Operating System - Linux
1753516 Members
5299 Online
108795 Solutions
New Discussion юеВ

Re: Need to change gateway in Linux

 
SOLVED
Go to solution
Sreer
Valued Contributor

Need to change gateway in Linux

Hi Gurus,

I need to change the gate way in my linux box.

root @up-p03:~# uname -a
Linux up-p03 2.6.18-164.el5 #1 SMP Tue Aug 18 15:51:48 EDT 2009 x86_64 x86_64 x86_64 GNU/Linux
root @up-p03:~# more /etc/redhat-release
Red Hat Enterprise Linux Server release 5.4 (Tikanga)
root @up-p03:~#

Pls guide me the procedure to o it in a production Box.

Do reboot needed?
what are the files needed to modify?
any services needed to restarted?

many thanks for your help.

Rgds
Sree
2 REPLIES 2
Matti_Kurkela
Honored Contributor
Solution

Re: Need to change gateway in Linux

The default gateway is normally configured in either the global network configuration file /etc/sysconfig/network or in one of the interface-specific configuration files, named like /etc/sysconfig/ifconfig-*.

If your gateway is 11.22.33.44, you'll find a setting:

GATEWAY=11.22.33.44

in one of the above-mentioned files.

If you only change the GATEWAY= line in the file, the change would take effect only after you reboot the system or run ifdown & ifup on the appropriate network interface.

To make the change immediately, you must also use the "route" command to change the current gateway. For example, to change the gateway immediately from 11.22.33.44 to 22.33.44.55:

route del default gw 11.22.33.44
route add default gw 22.33.44.55

If you only use the "route" command, the gateway will be changed, but your change will be lost the next time the system is rebooted. So you must *both* use the route command to make the actual change, *and* edit the configuration file so that the change will be permanent.

If only the gateway is changed (and the host IP address and netmask will stay as-is), the change can be made without restarting any services.

You should not make this change over a regular SSH/telnet/rlogin etc. connection, as deleting the old default gateway may break your session. A remote console system like iLO uses a separate network interface at the hardware level, so it would be safe to use.

A reboot is not strictly _necessary_, but very much recommended: it ensures any connections that are interrupted by the gateway change are cleaned up, and it confirms the new gateway is correctly configured.

MK
MK
Abushad
Advisor

Re: Need to change gateway in Linux

Hi Sree,

Please follow the instructions as mentioned by matti for adding a default gateway.

if you want to add route for a particular network then use the command
#iproute add via

to make this permanent edit the config file
/etc/sysconfig/network-scripts/route-ethX

network address/mask via gateway

Regards
Abushad