How to change Interface Metric permanently in CentOS
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 the ifcfg-enp0s3
and ifcfg-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