How to change Interface Metric permanently in CentOS

Veerendra asked:

My Config:

  1. Guest OS – CentOS7
  2. Host OS – Windows 7
  3. Interface – 3 (enp0s3, enp0s8, enp0s9)
  4. Installed in Virtual Box
  5. enp0s8 is Bridge to wlan0(For Internet)
  6. enp0s3 and enp0s9 are host-only

Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface UG 100 0 0 enp0s3 UG 101 0 0 enp0s9 UG 102 0 0 enp0s8 U 100 0 0 enp0s3 U 100 0 0 enp0s8 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 is failing. If I down the enp0s3, enp0s9, the ping is successful. Is there is way to do this?

My answer:

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.

View the full question and answer on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.