7 Replies Latest reply: Feb 6, 2013 11:08 PM by 140295 RSS

    Change Default gateway

    140295
      Hi..I have to change default gateway in my linux machine. Its OS is RHEL6.
      I followed following steps.
      1.run command ip route to check current default gateway
      2.delete that gateway with command
      route del default gw x.x.x.x eth2
      3.Add new gatewy with command below
      route add default gateway x.x.x.x eth0
      4.Also ensure /etc/sysconfig/network has new gateway entry with eth name in it.
      NETWORKING=yes
      HOSTNAME=N1
      GATEWAY=x.x.x.x
      GATEWAYDEV=eth0

      But when we restart network service it moves back to old gateway.

      Kindly let me know how to make it permanent.

      Thanks !!
        • 1. Re: Change Default gateway
          Paul M.
          Did you try using system-config-network command ?
          • 2. Re: Change Default gateway
            140295
            Hi..i tried running this from command prompt but it shows command not found.
            • 3. Re: Change Default gateway
              bigdelboy
              iam_dushyant wrote:
              Hi..I have to change default gateway in my linux machine. Its OS is RHEL6.
              I followed following steps.
              1.run command ip route to check current default gateway
              2.delete that gateway with command
              route del default gw x.x.x.x eth2
              3.Add new gatewy with command below
              route add default gateway x.x.x.x eth0
              4.Also ensure /etc/sysconfig/network has new gateway entry with eth name in it.
              NETWORKING=yes
              HOSTNAME=N1
              GATEWAY=x.x.x.x
              GATEWAYDEV=eth0

              But when we restart network service it moves back to old gateway.

              Kindly let me know how to make it permanent.

              Thanks !!
              My thoughts are, and having a quick look at an OL 6.3 system here ... is that:

              GATEWAY=x.x.x.x
              DEFROUTE=yes

              is in the ifcfg-ethX file.

              And that:

              GATEWAY=x.x.x.x
              GATEWAYDEV=eth0

              are no longer in the /etc/sysconfig/network file.

              ...

              Also keep out a lookout at any /etc/default-routes files ( possibly consider renaming it should it exist).

              ...

              Looking at your latest post you may need to install system-config-network to get that utility ...
              • 4. Re: Change Default gateway
                Catch-22
                As far as I know, entries in /etc/sysconfig/network, e.g. GATEWAY= are only used only if there there is no corresponding entry in the ifcfg-ethX interface specific config file, which takes precedence.
                • 5. Re: Change Default gateway
                  140295
                  Hi..my data center is in location x and person accessing it on Y over wan.Server has linux RHEL 6.2 OS and has 4 nic card with their different ip(Ip1,Ip2,Ip3 & Ip4),netmask and gateway (gw1 to gw4). Person from Y is able to ping gateway gw1 to gw4. When he tried to ping ip , he is able to ping Ip1.

                  Do i need to define default gateway for all ip? How shall i configure default gateway for rest of IP's?


                  INTERFACE     IP     Gateway     Subnet     Remarks
                  ce0     192.12.80.1     192.12.80.254     255.255.255.0     
                  ce0:1     192.12.80.2     192.12.80.254     255.255.255.0     It is virtual IP
                  ce1     192.12.81.5     192.12.80.126     255.255.255.128     
                  ce2     192.12.83.4     192.12.80.254     255..255.255.192     
                  ce3     192.168.176.1     192.168.176.254     255.255.255.0     

                  Pls find below details as required.


                  [root@nth1 ~]# ifconfig -a
                  eth0 Link encap:Ethernet HWaddr 00:1A:64:D3:FD:54
                  inet addr:192.12.80.1 Bcast:10.2.180.255 Mask:255.255.255.0
                  inet6 addr: fe80::21a:64ff:fed3:fd54/64 Scope:Link
                  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
                  RX packets:10955 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:4868 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000
                  RX bytes:3273759 (3.1 MiB) TX bytes:1554244 (1.4 MiB)
                  Interrupt:16 Memory:ce000000-ce012800

                  eth1 Link encap:Ethernet HWaddr 00:1A:64:D3:FD:56
                  inet addr:192.12.81.5 Bcast:10.2.181.127 Mask:255.255.255.128
                  inet6 addr: fe80::21a:64ff:fed3:fd56/64 Scope:Link
                  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
                  RX packets:6760 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:5464 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000
                  RX bytes:7758932 (7.3 MiB) TX bytes:522470 (510.2 KiB)
                  Interrupt:17 Memory:ca000000-ca012800

                  eth2 Link encap:Ethernet HWaddr 00:15:17:78:5F:9E
                  inet addr:192.12.83.4 Bcast:10.2.181.191 Mask:255.255.255.192
                  inet6 addr: fe80::215:17ff:fe78:5f9e/64 Scope:Link
                  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
                  RX packets:4458 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:3930 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000
                  RX bytes:4428694 (4.2 MiB) TX bytes:365910 (357.3 KiB)
                  Interrupt:16 Memory:c7ee0000-c7f00000

                  eth3 Link encap:Ethernet HWaddr 00:15:17:78:5F:9F
                  inet addr:192.168.176.1 Bcast:192.168.176.255 Mask:255.255.255.0
                  inet6 addr: fe80::215:17ff:fe78:5f9f/64 Scope:Link
                  UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
                  RX packets:3634 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:3558 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000
                  RX bytes:896806 (875.7 KiB) TX bytes:896716 (875.6 KiB)
                  Interrupt:17 Memory:c7ea0000-c7ec0000

                  eth4 Link encap:Ethernet HWaddr 00:15:17:78:61:94
                  UP BROADCAST MULTICAST MTU:1500 Metric:1
                  RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000
                  RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
                  Interrupt:17 Memory:c5fe0000-c6000000

                  eth5 Link encap:Ethernet HWaddr 00:15:17:78:61:95
                  UP BROADCAST MULTICAST MTU:1500 Metric:1
                  RX packets:0 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:1000
                  RX bytes:0 (0.0 b) TX bytes:0 (0.0 b)
                  Interrupt:18 Memory:c5fa0000-c5fc0000

                  lo Link encap:Local Loopback
                  inet addr:127.0.0.1 Mask:255.0.0.0
                  inet6 addr: ::1/128 Scope:Host
                  UP LOOPBACK RUNNING MTU:16436 Metric:1
                  RX packets:3755 errors:0 dropped:0 overruns:0 frame:0
                  TX packets:3755 errors:0 dropped:0 overruns:0 carrier:0
                  collisions:0 txqueuelen:0
                  RX bytes:1096013 (1.0 MiB) TX bytes:1096013 (1.0 MiB)

                  [root@nth1 ~]# route -n
                  Kernel IP routing table
                  Destination Gateway Genmask Flags Metric Ref Use Iface
                  10.2.181.128 0.0.0.0 255.255.255.192 U 0 0 0 eth2
                  10.2.181.0 0.0.0.0 255.255.255.128 U 0 0 0 eth1
                  192.168.176.0 0.0.0.0 255.255.255.0 U 0 0 0 eth3
                  10.2.180.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
                  169.254.0.0 0.0.0.0 255.255.0.0 U 1002 0 0 eth0
                  169.254.0.0 0.0.0.0 255.255.0.0 U 1003 0 0 eth1
                  169.254.0.0 0.0.0.0 255.255.0.0 U 1004 0 0 eth2
                  169.254.0.0 0.0.0.0 255.255.0.0 U 1005 0 0 eth3
                  0.0.0.0 192.12.80.254 0.0.0.0 UG 0 0 0 eth0
                  [root@nth1 ~]#
                  [root@nth1 ~]# netstat -nr
                  Kernel IP routing table
                  Destination Gateway Genmask Flags MSS Window irtt Iface
                  10.2.181.128 0.0.0.0 255.255.255.192 U 0 0 0 eth2
                  10.2.181.0 0.0.0.0 255.255.255.128 U 0 0 0 eth1
                  192.168.176.0 0.0.0.0 255.255.255.0 U 0 0 0 eth3
                  10.2.180.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
                  169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth0
                  169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth1
                  169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth2
                  169.254.0.0 0.0.0.0 255.255.0.0 U 0 0 0 eth3
                  0.0.0.0 192.12.80.254 0.0.0.0 UG 0 0 0 eth0

                  Thanks !!

                  Edited by: iam_dushyant on Feb 6, 2013 3:21 AM
                  • 6. Re: Change Default gateway
                    bigdelboy
                    Not my best area, but as far as I know in static routing you may have one default gateway that is used for a all address not on a local subnet for which a specific static route is not available.

                    If I am not mistaken looking at:
                    INTERFACE IP Gateway Subnet Remarks
                    ce0 192.12.80.1 192.12.80.254 255.255.255.0
                    ce0:1 192.12.80.2 192.12.80.254 255.255.255.0 It is virtual IP
                    ce1 192.12.81.5 192.12.80.126 255.255.255.128
                    ce2 192.12.83.4 192.12.80.254 255..255.255.192
                    ce3 192.168.176.1 192.168.176.254 255.255.255.0 
                    Taking interface ce1 the gateway (192.12.80.126) does not appear to be on the subnet of the IP {192.12.81.5 netmask 255.255.255.128}

                    Should the gateway be 192.12.81.126 this would make more sense. My guess would be GATEWAY=192.12.80.126 with DEFROUTE=no in the ifcfg-eth1 file would achieve this.

                    ....

                    I also note the line "inet addr:192.12.81.5 Bcast:10.2.181.127 Mask:255.255.255.128" and again the broadcast address does not look right for the subnet. I suggest checking the configuration carefully.
                    • 7. Re: Change Default gateway
                      140295
                      Thanks ..its type error..My apology.

                      INTERFACE IP Gateway Subnet Remarks
                      ce0 192.12.80.1 192.12.80.254 255.255.255.0
                      ce0:1 192.12.80.2 192.12.80.254 255.255.255.0 It is virtual IP
                      ce1 192.12.81.5 192.12.81.126 255.255.255.128
                      ce2 192.12.83.4 192.12.83.254 255..255.255.192
                      ce3 192.168.176.1 192.168.176.254 255.255.255.0

                      In eth1,defroute is no.

                      Thanks