Метрика сетевого интерфейса linux

How to change Interface Metric permanently in CentOS

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?

3 Answers 3

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.

Ok, I did just you said, but still I’m not able to ping 8.8.8.8 . Now I cant even ping gateway of enp0s8 ‘s

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.

Читайте также:  Ati sbx00 azalia linux

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

Источник

Разбираемся с приоритетом -999: как изменить порядок подключения в Linux

Изменение порядка подключения сетевых интерфейсов в Linux может быть необходимо для различных задач, таких как настройка балансировки нагрузки или настройка безопасности. Однако, при этом могут возникнуть проблемы с приоритетом подключения, которые могут привести к тому, что передача данных не будет осуществляться через нужный интерфейс. В данной статье мы рассмотрим, как изменить приоритет подключения сетевых интерфейсов в Linux.

Определение приоритета подключения

Приоритет подключения в Linux определяется с помощью метрики. Метрика — это числовое значение, которое определяет приоритет интерфейса. Чем меньше значение метрики, тем выше приоритет интерфейса.

В Linux по умолчанию, метрика устанавливается автоматически при подключении интерфейса. Однако, при необходимости, можно изменить приоритет подключения с помощью установки своих значений метрики.

Изменение приоритета подключения

Для изменения приоритета подключения можно использовать утилиту iproute2. Для этого необходимо выполнить следующие шаги:

Эта команда выведет список всех сетевых интерфейсов с их текущими значениями метрики.

sudo ip route delete default sudo ip route add default via dev metric

Здесь — адрес шлюза, — имя интерфейса, — новое значение метрики.

Эта команда покажет обновленный список сетевых интерфейсов с новыми значениями метрики.

Заключение

Изменение приоритета подключения в Linux может быть необходимость для различных задач. Для изменения приоритета необходимо использовать утилиту iproute2 и настроить метрики для сетевых интерфейсов на нужные значения. Рекомендуется использовать новые значения метрики, отличные от -999, поскольку это значение может использоваться интерфейсами по умолчанию.

Читайте также:  Нет доступа изменить папки linux

Источник

How can I make changes to the network routing metric permanently

When I reboot though, the metric for enp0s3 reverts to 101. How can I make this change permanent or have it set automatically at boot time?

6 Answers 6

If you are using NetworkManager, the proper way to change the metric for the default route is to modify the connection associated with interface enp0s3 in this way:

nmcli connection modify ipv4.route-metric 1 

and then re-activate the connection:

You can find the value for in the output of nmcli connection .

This is permanent and IMHO answer the question. Be aware, still, that this solution is attached to a connection, not an interface. If you happen to use several connections (typical case: roaming device connecting to various places) on the same interface (the machine’s wifi or Ethernet), the operation has to be done for the each of the connections that need metric adjustment. This may or may not be what you want. I feel this is good because you can e.g. say «this specific Wifi costs me money by the byte so put a higher metric», «this Ethernet connection is high-performance, use it in priority».

Unfortunately, it doesn’t change the metric of the default gateway immediately, I posted a question here : unix.stackexchange.com/questions/625126/…

The correct way to do this, in Debian and derivatives, is to write a file in /etc/NetworkManager/dispatcher.d (call it whatever you like), with the following content:

#!/bin/sh # Change the metric of the default route only on interface enp0s3 IF=$1 STATUS=$2 MY_METRIC=1 if [ "$IF" = "enp0s3" ] then case "$STATUS" in up) ip route del default dev $IF ip route add default via $DHCP4_ROUTERS dev $IF metric $MY_METRIC ;; *) ;; esac fi 

This way, your customization will not be overwritten upon each update. In order to check this, stop the Network Manager, kill the dhclient and flush the IP address of the interface, then restart network manager.

Читайте также:  Word to pdf python linux

You can find documentation here.

systemctl stop network-manager pkill dhclient ip addr flush dev eth0 systemctl start network-manager 

if the interface in question is eth0, otherwise change accordingly.

Источник

Оцените статью
Adblock
detector