4

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 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?

Veerendra K
  • 273
  • 3
  • 4
  • 10

3 Answers3

2

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.

Michael Hampton
  • 237,123
  • 42
  • 477
  • 940
1

add METRIC=10 in /etc/sysconfig/network-scripts/ifcfg-enp0s8

For centos 7, this setting is permanently

Frankie
  • 11
  • 1
1

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

gizi
  • 11
  • 3