Routing table changes on boot up

Issues related to configuring your network
Post Reply
northpoint
Posts: 76
Joined: 2016/05/23 11:57:12

Routing table changes on boot up

Post by northpoint » 2018/02/14 00:02:53

Hello,

I administer a centos7 server from remote as the drive is about 1.5 hours a way. The server has two network cards. One for Internet access and the other that services the local lan. I am using iptables for masqing the network ids of the workstations. Everything runs fine until a reboot. It seems that the system will default to the local lan as the default route. Here is some info:

Code: Select all

em1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.0.1  netmask 255.255.255.0  broadcast 192.168.0.255
        inet6 fe80::226:b9ff:fe48:6dde  prefixlen 64  scopeid 0x20<link>
        ether 00:26:b9:48:6d:de  txqueuelen 1000  (Ethernet)
        RX packets 6332198  bytes 1549672239 (1.4 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 8582199  bytes 8333396499 (7.7 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

em2: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 69.14.xxx.xxx  netmask 255.255.255.0  broadcast 69.14.211.255
        inet6 fe80::226:b9ff:fe48:6de0  prefixlen 64  scopeid 0x20<link>
        ether 00:26:b9:48:6d:e0  txqueuelen 1000  (Ethernet)
        RX packets 4843235  bytes 5703625181 (5.3 GiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 3001778  bytes 493540310 (470.6 MiB)
        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
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1  (Local Loopback)
        RX packets 10251  bytes 1095072 (1.0 MiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 10251  bytes 1095072 (1.0 MiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
Routing - This is the good routing table when everything works.

Code: Select all

Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
default         d14-69-1-211.tr 0.0.0.0         UG    100    0        0 em2
default         sd2.sd.local    0.0.0.0         UG    101    0        0 em1
69.14.211.0     0.0.0.0         255.255.255.0   U     100    0        0 em2
192.168.0.0     0.0.0.0         255.255.255.0   U     100    0        0 em1
192.168.122.0   0.0.0.0         255.255.255.0   U     0      0        0 virbr0
If the server has to reboot then the way I fix this is that its a onsite visit and I remove the network cable from the local lan side (/dev/em1) and bootup. Then after the Internet network card comes up I can plugin the local lan.

I took a look at /etc/sysconfig/network and it does not list anything. I can see that NetworkManager is handling all the connections. What I would like is that on reboot /dev/em2 connects to modem and sets the default route for Internet traffic. Then of course the local lan sets up as it normally does.

I am not sure how to get the system to perform as I need unless I configure NetworkManager to not bring the local lan up on bootup just the Internet network card. This of course is not idea either.

Any help would be greatly appreciated. It would save me those 1.5 hour trips :)

Thanx,
Ryzen x1800 * Asus x370 Pro * CentOS 7.4 64bit / Icewarp /

User avatar
TrevorH
Forum Moderator
Posts: 23876
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: Routing table changes on boot up

Post by TrevorH » 2018/02/14 10:23:13

Check the /etc/sysconfig/network-scripts/ifcfg-* files and make sure that only the interface file that should have the default route has a GATEWAY= line in it.
CentOS 5 died in March 2017 - migrate NOW!
Full time Geek, part time moderator. Use the FAQ Luke

northpoint
Posts: 76
Joined: 2016/05/23 11:57:12

Re: Routing table changes on boot up

Post by northpoint » 2018/02/14 22:41:49

TrevorH wrote:Check the /etc/sysconfig/network-scripts/ifcfg-* files and make sure that only the interface file that should have the default route has a GATEWAY= line in it.
Thank you, I appreciate the reply. I will be off to check that.

I will update this when I figure it all out.

Northpoint
Ryzen x1800 * Asus x370 Pro * CentOS 7.4 64bit / Icewarp /

northpoint
Posts: 76
Joined: 2016/05/23 11:57:12

Re: Routing table changes on boot up

Post by northpoint » 2018/05/28 17:18:57

Excuse me for being so late to update this thread.

I assume the DEFROUTE setting should be taken out from em1 as it will no longer be the default route? It only handles the internal network.

Here is the /etc/sysconfig/network-scripts/ifcfg-em2 which is the 2nd nic that connects to the modem.

Code: Select all

TYPE=Ethernet
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
NAME=em2
UUID=da54a54e-fcf9-4690-9c42-b1c1e5bf1e31
DEVICE=em2
ONBOOT=yes
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=dhcp
GATEWAY=xx.xx.xx.232
ZONE=external
Ryzen x1800 * Asus x370 Pro * CentOS 7.4 64bit / Icewarp /

User avatar
jlehtone
Posts: 2018
Joined: 2007/12/11 08:17:33
Location: Finland

Re: Routing table changes on boot up

Post by jlehtone » 2018/05/29 08:04:11

If you were using network.service and not NetworkManager.service, then this part of ifup-scripts would apply:

Code: Select all

# Set a default route.
if [ "${DEFROUTE}" != "no" ] && [ -z "${GATEWAYDEV}" -o "${GATEWAYDEV}" = "${REALDEVICE}" ]
then
  # set up default gateway. replace if one already exists
  if [ -n "${GATEWAY}" ] && [ "$(ipcalc --network ${GATEWAY} ${netmask[0]} 2>/dev/null)" = "NETWORK=${NETWORK}" ]
  then
    ip route replace default ...
  elif [ "${GATEWAYDEV}" = "${DEVICE}" ]
  then
    ip route replace default ...
  fi
fi
The important point is that DEFROUTE has to be 'no' or GATEWAYDEV has to be set (to another device), if you don't want this device to be even considered to be the link to default route.
Failing those, having GATEWAY not in the subnet of this device is the final saving grace.


If you were using ...
but you wrote that you do use NetworkManager. There we look at the configuration in different ways:

Code: Select all

# Overall status
nmcli
# Show devices
nmcli d s
# Show connections
nmcli c s
# Show details of one connection
nmcli c s <conn-name>
# Show just ipv4 config
nmcli -f ipv4 c s <conn-name>
The last one could show something like:

Code: Select all

ipv4.method:                            manual
ipv4.dns:                               --
ipv4.dns-search:                        --
ipv4.dns-options:                       ""
ipv4.dns-priority:                      0
ipv4.addresses:                         1.3.6.9/24
ipv4.gateway:                           --
ipv4.routes:                            --
ipv4.route-metric:                      -1
ipv4.route-table:                       0 (unspec)
ipv4.ignore-auto-routes:                no
ipv4.ignore-auto-dns:                   no
ipv4.dhcp-client-id:                    --
ipv4.dhcp-timeout:                      0 (default)
ipv4.dhcp-send-hostname:                yes
ipv4.dhcp-hostname:                     --
ipv4.dhcp-fqdn:                         --
ipv4.never-default:                     yes
ipv4.may-fail:                          yes
ipv4.dad-timeout:                       -1 (default)
Of these I have definitely set the

Code: Select all

ipv4.method:                            manual
ipv4.addresses:                         1.3.6.9/24
ipv4.never-default:                     yes
for the default config has:

Code: Select all

ipv4.method:                            auto
ipv4.addresses:                         --
ipv4.never-default:                     no
Of the never-default the man nm-settings writes:
If TRUE, this connection will never be the default connection for this IP type, meaning it will never be assigned the default route by NetworkManager.
Thus, to tell NetworkManager that internal net has no route out:

Code: Select all

nmcli c mod em1 ipv4.never-default yes
(I bet that "em1" is not the connection's correct name. Check with nmcli c s.)

northpoint
Posts: 76
Joined: 2016/05/23 11:57:12

Re: Routing table changes on boot up

Post by northpoint » 2018/05/29 19:40:21

I want to thank you very much for your help.

What had me a bit confused is NetworkManager (GUI on desktop) and nmtui which I didnt know existed. I was able to correct the issues with networking surviving a reboot and was able to setup the new internet connection easily! Used nmtui to setup networking and get it right :)

Thank you once again,

northpoint
Ryzen x1800 * Asus x370 Pro * CentOS 7.4 64bit / Icewarp /

Post Reply