I'm struggling to get the networking working working on a linux VM. As is after the setup, I have this ifconfig
:
# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.19.190.144 netmask 255.255.0.0 broadcast 172.19.255.255
inet6 fe80::215:5dff:febe:6707 prefixlen 64 scopeid 0x20<link>
ether 00:15:5d:be:67:07 txqueuelen 1000 (Ethernet)
RX packets 30629 bytes 3428768 (3.2 MiB)
RX errors 0 dropped 409 overruns 0 frame 0
TX packets 351 bytes 53232 (51.9 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
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 78 bytes 6600 (6.4 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 78 bytes 6600 (6.4 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
And this routing table:
# ip route
default via 172.19.190.1 dev eth0 proto static metric 100
172.19.0.0/16 dev eth0 proto kernel scope link src 172.19.190.144 metric 100
With this setup, I can ping the gateway and external internet hosts, but I cannot ping hosts on 172.19.180.x subnet, getting "host unreachable".
When I then manually do
# ip route add 172.19.0.0/16 via 172.19.190.1 dev eth0
Then everything works as expected. I now add this line into /etc/sysconfig/network-scripts/route-eth0
:
172.19.0.0/16 via 172.19.190.1
After the reboot, my routing table looks like this:
# ip route
default via 172.19.190.1 dev eth0 proto static metric 100
172.19.0.0/16 dev eth0 proto kernel scope link src 172.19.190.144 metric 100
172.19.0.0/16 via 172.19.190.1 dev eth0 proto static metric 100
And I again cannot get to 172.19.180.x subnet. The difference between this and the manual addition with ip route add
is that the last line has proto static metric 100
at the end, whereas with the manual way it doesn't.
What do I need to do to get everything working on a reboot?
UPDATE: here's my ifcfg-eth0
file:
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=no
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
UUID=.... (masked)
DEVICE=eth0
ONBOOT=yes
IPADDR=172.19.190.144
PREFIX=16
GATEWAY=172.19.190.1
DNS1=172.19.190.240
DNS2=172.19.190.242
UPDATE2:
If I remove the second route (... src 172.19.190.144...
) and only leave one default, then everything work correctly. Then the question becomes: where does the second route come from and how do I get rid of it?
The problem is that your have two routes to
172.19/16
. Since they have the same netmask length (16 bits) the second one overrides the third one.The third route:
was added by the
/etc/sysconfig/network-scripts/route-eth0
. The second one:has a
proto kernel
, so it was added by the script that configured the IP address of your interface.In the following I am guessing that your are using Fedora. The netmask/network prefix that your used to configure you IP address is too wide. You need to add to the file
/etc/sysconfig/network-scripts/ifcfg-eth0
a line like:Answer to update 2: When you add an IP address, say 1.2.3.4, to an interface, a couple of routes are added too. The exact routes depend on the tool:
ip addr
will force you to specify the network prefix (size of the netmask) of 1.2.3.4 or complain vehemently. If you execute:ip addr add dev eth0 1.2.3.4/24
, you' get a1.2.3.4/24 dev eth0
route as bonus (+ 2 routes you don't see, because they are in thelocal
routing table, cf.ip route show table local
).ifconfig
will assume your network has a prefix of 24 if you do not specify a netmask and add a1.2.3.4/24 dev eth0
route.So a direct answer to your question is: the
PREFIX=16
line in/etc/sysconfig/network-scripts/ifcfg-eth0
caused the second route to appear.