kemaru
kemaru

Reputation: 81

The default gateway set in /etc/sysconfig/network on a CentOS 7.2 server is "ignored"

I have a CentOS 7.2 server with two NICs. I set the default gateway to 192.168.0.1 in /etc/sysconfig/network. However, after rebooting the server, that setting does not take effect and my guess is DHCP used by eth1 overwrites it.

Is there a way to fix this issue? I have tried to add "DEFROUTE=yes" to /etc/sysconfig/network-scripts/ifcfg-eth0 but no luck.

I am also willing to run "sudo ip route replace default via 192.168.0.1 dev eth0", but where is the best place to put it?

The basic information of the server is provided below. Please let me know if you need any more information.

Many Thanks in advance!

[user@server ~]$ cat /etc/*release*
CentOS Linux release 7.2.1511 (Core) 

[user@server ~]$ sudo ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.5  netmask 255.255.255.0  broadcast 192.168.0.255
        ether fa:16:3e:1c:6c:0b  txqueuelen 1000  (Ethernet)
        RX packets 129799  bytes 9477014 (9.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 15  bytes 1830 (1.7 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

eth1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.241.11.94  netmask 255.255.254.0  broadcast 10.241.11.255
        ether fa:16:3e:cb:11:59  txqueuelen 1000  (Ethernet)
        RX packets 206571  bytes 13205742 (12.5 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 2850  bytes 225994 (220.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        loop  txqueuelen 0  (Local Loopback)
        RX packets 16  bytes 1936 (1.8 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 16  bytes 1936 (1.8 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

[user@server ~]$ sudo ip route
default via 10.241.10.1 dev eth1  proto static 
10.0.0.0/8 via 10.241.11.66 dev eth1 
10.241.10.0/23 dev eth1  proto kernel  scope link  src 10.241.11.94 
169.254.169.254 via 10.241.11.66 dev eth1  proto static 
192.168.0.0/24 dev eth0  proto kernel  scope link  src 192.168.0.5 

[user@server ~]$ cat /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=localhost.localdomain
NOZEROCONF=yes
GATEWAY=192.168.0.1

[user@server ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth0
NAME=eth0
DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet

[user@server ~]$ cat /etc/sysconfig/network-scripts/ifcfg-eth1
NAME=eth1
DEVICE=eth1
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet

Upvotes: 2

Views: 3847

Answers (1)

Brian
Brian

Reputation: 21

In the current implementation of Red Hat, the /etc/sysconfig/network file is deprecated. You can specify which connection to user as default with the DEFROUTE variable in the interface-specific config file. Set DEFROUTE=yes in ifcfg-eth0.

https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/sec-Using_the_Command_Line_Interface.html#sec-Static-Routes_and_the_Default_Gateway

Upvotes: 2

Related Questions