How to Change Your Default Gateway



How to Change Your Default Gateway

Your server needs to have a single default gateway. DHCP servers automatically assign a default gateway to DHCP-configured NICs, but NICs with configured, static IP addresses will need to have a manually configured default gateway. This can be done with a simple command. This example uses a newly installed wireless interface called wlan0; most PCs would be using the standard Ethernet interface eth0:

     [root@bigboy tmp]# route add default gw 192.168.1.1 wlan0

In this case, make sure that the router/firewall with IP address 192.168.1.1 is connected to the same network as interface wlan0!

When this is done, you need to update your /etc/sysconfig/network file to reflect the change. This file is used to configure your default gateway each time Linux boots:

     NETWORKING=yes
     HOSTNAME=bigboy
     GATEWAY=192.168.1.1

Some people don't bother with this step and just place the route add command in the script file /etc/rc.d/rc.local which is run at the end of every reboot.

It is possible to define default gateways in the NIC configuration file in the /etc/sysconfig/network-scripts directory, but you run the risk of inadvertently assigning more than one default gateway when you have more than one NIC. This will cause packets to be sent to alternating gateways and could cause connectivity problems. If one of the default gateways has no route to the intended destination, every other packet will become lost. Firewalls that are designed to block packets with irregular sequence numbers and unexpected origins could also obstruct your data flow.