My Config:
- Guest OS - CentOS7
- Host OS - Windows 7
- Interface - 3 (
enp0s3
,enp0s8
,enp0s9
) - Installed in Virtual Box
enp0s8
is Bridge towlan0
(For Internet)enp0s3
andenp0s9
are host-only
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
0.0.0.0 10.10.10.1 0.0.0.0 UG 100 0 0 enp0s3
0.0.0.0 192.168.3.1 0.0.0.0 UG 101 0 0 enp0s9
0.0.0.0 192.168.0.1 0.0.0.0 UG 102 0 0 enp0s8
10.10.10.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s3
192.168.0.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s8
192.168.3.0 0.0.0.0 255.255.255.0 U 100 0 0 enp0s9
I added METRIC=10
in /etc/sysconfig/network-scripts/ifcfg-enp0s8
and then restarted. But in route -n
still it is showing Metric
as 101
(As you see in above output). I tried sudo ifconfig enp0s8 metric 10
, but no use. The ping 8.8.8.8
is failing. If I down
the enp0s3
, enp0s9
, the ping is successful. Is there is way to do this?
Don't set default gateways for interfaces which don't connect to the Internet.
Remove the default gateways that are defined for those interfaces. That is, delete the
GATEWAY=
line from theifcfg-enp0s3
andifcfg-enp0s9
files.You do not need to worry about the route metric at all.
add METRIC=10 in /etc/sysconfig/network-scripts/ifcfg-enp0s8
For centos 7, this setting is permanently
NetworkManager ifcfg-rh plugin is used on the Fedora and Red Hat Enterprise Linux distributions (and CentOS) to read/write configuration from/to the traditional /etc/sysconfig/network-scripts/ifcfg-* files.
ifcfg-rh plugin variable IPV4_ROUTE_METRIC is NetworkManager specific extension not understood by traditional initscripts. For this purpose NetworkManager have to be active which is the default behaviour in CentOS7.
Add IPV4_ROUTE_METRIC=10 to /etc/sysconfig/network-scripts/ifcfg-enp0s8. The lower number the higher priority. If you add this parameter for one interface you should add IPV4_ROUTE_METRIC with different priority numbers also to all remaining interfaces to keep control over routing priority.
Restart all interfaces:
ifdown ifcfg-enp0s3;ifdown ifcfg-enp0s8;ifdown ifcfg-enp0s9;ifup ifcfg-enp0s3;ifup ifcfg-enp0s8;ifup ifcfg-enp0s9
Other way to inform NetworkManager about config changes:
nmcli con reload
Check routing priority with command:
ip route show