[Solved] Preventing automatic metric reset

[Solved] Preventing automatic metric reset

Postby pmr » Sep 29th, '21, 11:48

I use Ethernet and Wifi connections in parallel. Both are connected to the same IP network. I would like to prefer Ethernet one whenever it is connected, but use also WiFi, when not. I achieve the goal temporarily by setting different metrics to interfaces. The problem is, however, that after some time the metrics reset automatically to 0. How to prevent such an automatic metric reset?

After manual set:

Code: Select all
[root@pmrnote etc]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.18.0.1      0.0.0.0         UG    66     0        0 enp2s0
172.18.0.0      0.0.0.0         255.255.255.192 U     66     0        0 enp2s0
172.18.0.0      0.0.0.0         255.255.255.192 U     666    0        0 wlp1s0


After some time:

Code: Select all
[root@pmrnote etc]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.18.0.1      0.0.0.0         UG    0      0        0 enp2s0
172.18.0.0      0.0.0.0         255.255.255.192 U     0      0        0 enp2s0
172.18.0.0      0.0.0.0         255.255.255.192 U     0      0        0 wlp1s0
Last edited by pmr on Feb 10th, '22, 23:25, edited 1 time in total.
pmr
 
Posts: 10
Joined: Sep 29th, '21, 11:41

Re: Preventing automatic metric reset

Postby doktor5000 » Sep 29th, '21, 15:49

Hi there, how do you set the metric initially in particular? And after what time or after which event (standby, hibernate, ...) do the metrics reset?
Also, what controls your network interfaces, the default net_applet, networkmanager or maybe something else?

Please show the configuration files of your interfaces, that would be pretty helpful.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17659
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Preventing automatic metric reset

Postby pmr » Sep 29th, '21, 20:45

doktor5000 wrote:how do you set the metric initially in particular?

I set the metrics by hand, using small aliases:

Code: Select all
alias ifm='ifmetric wlp1s0 666 ; ifmetric enp2s0 66 ; route -vn'
alias neth='ifdown wlp1s0 ; dhclient enp2s0 ; ifup wlp1s0 ; ifm'


I use the "neth" if I want to force the preference of the Ethernet after I connect it and "ifm" if I just want to restore the metrics, after their unwanted reset.

doktor5000 wrote:what time or after which event (standby, hibernate, ...) do the metrics reset?


I am not sure at which timepoint exactly metrics reset; I suppose that it is related to events of loosing connectivity on interfaces, in particular on the wireless, which happen from time to time. These metrics resets happen even without sleeping events occuring - just during a normal continuous work.

doktor5000 wrote:what controls your network interfaces, the default net_applet, networkmanager or maybe something else?


The net_applet:

Code: Select all
[root@pmrnote Temp]# ps -e | grep "NetworkManager\|net_applet"
  16356 ?        00:32:29 net_applet


In fact, I rather configure the interfaces rather via CLI then via GUI.

doktor5000 wrote:Please show the configuration files of your interfaces, that would be pretty helpful.

[/quote]

Code: Select all
[root@pmrnote Temp]# cat /etc/sysconfig/network-scripts/ifcfg-enp2s0
DEVICE=enp2s0
BOOTPROTO=dhcp
IPADDR=10.0.0.66
NETMASK=255.255.255.0
ONBOOT=yes
METRIC=66
IPV4_ROUTE_METRIC=77
DEFROUTE=yes
MII_NOT_SUPPORTED=no
USERCTL=yes
RESOLV_MODS=yes
NOZEROCONF=yes
LINK_DETECTION_DELAY=6
IPV6INIT=no
IPV6TO4INIT=no
#IPV6ADDR=2001:db8:acad:666::6/64
#IPV6ADDR_SECONDARIES="2001:db8:cafe:666::6/64 2001:db8:feed:666::6/64"
# IPV6_DEFAULTGW=2001:db8:acad:666::1
IPV6_AUTOCONF=yes
DHCPV6C=no
ACCOUNTING=no
NM_CONTROLLED=yes
DHCP_CLIENT=dhclient
NEEDHOSTNAME=no
PEERDNS=yes
PEERYP=yes
PEERNTPD=no
[root@pmrnote Temp]# cat /etc/sysconfig/network-scripts/ifcfg-wlp1s0
DEVICE=wlp1s0
BOOTPROTO=dhcp
ONBOOT=yes
METRIC=666
MII_NOT_SUPPORTED=no
USERCTL=yes
RESOLV_MODS=no
WIRELESS_MODE=Managed
WIRELESS_ESSID=**********
WIRELESS_ENC_KEY=s:****************
WIRELESS_WPA_DRIVER=wext
WIRELESS_WPA_REASSOCIATE=no
KEY_MGMT=WPA-PSK
WPA_PSK=*********
IPV6INIT=no
IPV6TO4INIT=no
ACCOUNTING=no
NM_CONTROLLED=yes
UUID=*************
NAME="System PMR (wlp1s0)"
DHCP_CLIENT=dhclient
NEEDHOSTNAME=no
PEERDNS=yes
PEERYP=yes
PEERNTPD=no


The "METRIC" entries seem to be not effecive :-/
pmr
 
Posts: 10
Joined: Sep 29th, '21, 11:41

Re: Preventing automatic metric reset

Postby doktor5000 » Sep 29th, '21, 22:20

Well, it's logical that each time an interface is re-initialised that your dynamic changes are overridden.
How did you set the METRIC entries, manually by editing the config files ?

There has been a bug on that, which is quite old, maybe it has resurfaced: https://bugs.mageia.org/show_bug.cgi?id=2080

As an alternative, you could try switching to networkmanager. Check viewtopic.php?f=25&t=5782
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17659
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Preventing automatic metric reset

Postby pmr » Sep 30th, '21, 02:48

doktor5000 wrote:Well, it's logical that each time an interface is re-initialised that your dynamic changes are overridden.
How did you set the METRIC entries, manually by editing the config files ?


I set the METRIC values manually, by editing the config files.
I have checked that they appear in proper editboxes in interface properies dialogs, therefore I assume that they are syntactically correct. But nevertheless - not effective :-/
I assumed that these values can be considered as the initial ones and applied during interfaces (re)initializations, but are not.

doktor5000 wrote:As an alternative, you could try switching to networkmanager. Check viewtopic.php?f=25&t=5782


I'm afraid a little bit, to be honest ;-)
I switch between different wireless networks quite often, sometimes use an external USB WiFi transceiver and Wireshark monitor mode, and have settled the configuration that behaves quite stably, with the exception of this unfortunate resetting metrics. I would like not to destabilize it.
I was using NetworkManager several years ago (I use Mageia since the first version, earlier Mandriva, earlier - Mandrake, before that - RedHat and Slackware) and had some bad experiences - do not remember details now, but they distracted me from the NetworkManager. Do you think it is worth reconsideration now?
Last edited by doktor5000 on Sep 30th, '21, 12:02, edited 1 time in total.
Reason: fixed quote tags
pmr
 
Posts: 10
Joined: Sep 29th, '21, 11:41

Re: Preventing automatic metric reset

Postby doktor5000 » Sep 30th, '21, 12:05

Well, if the metric is not applied, then you should probably file a bugreport about that: https://wiki.mageia.org/en/How_to_report_a_bug_properly

Regarding networkmanager, at least it's worth a try, and it's not really invasive but it could help with this issue - but it's just a workaround to the issue at hand.
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 17659
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: Preventing automatic metric reset

Postby pmr » Sep 30th, '21, 17:15

doktor5000 wrote:if the metric is not applied, then you should probably file a bugreport about that


THX. I have indeed started a bug report:
https://bugs.mageia.org/show_bug.cgi?id=29505
pmr
 
Posts: 10
Joined: Sep 29th, '21, 11:41

Re: Preventing automatic metric reset

Postby pmr » Oct 19th, '21, 15:00

It seems that setting the metric is related to the address allocation mode of the interface (static/DHCP).
My Ethernet interface was configured as DHCP client.
I temporarily changed the type to a static mode and metric started to be assigned after interface restart:

Code: Select all
[root@pmrnote network-scripts]# cat ifcfg-enp2s0
[...]
DEVICE=enp2s0
BOOTPROTO=static
IPADDR=10.0.0.66
NETMASK=255.255.255.0
GATEWAY=10.0.0.1
ONBOOT=yes
METRIC=55
IPV4_ROUTE_METRIC=77
DEFROUTE=yes
[...]
[root@pmrnote network-scripts]# ifdown enp2s0 ; ifup enp2s0
[...]
[root@pmrnote network-scripts]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         10.0.0.1        0.0.0.0         UG    55     0        0 enp2s0
10.0.0.0        0.0.0.0         255.255.255.0   U     0      0        0 enp2s0
192.168.60.0    0.0.0.0         255.255.252.0   U     666    0        0 wlp1s0
[root@pmrnote network-scripts]#


But anyway - only for the default route and not for the route for the local, directly connected network.
pmr
 
Posts: 10
Joined: Sep 29th, '21, 11:41

Re: Preventing automatic metric reset

Postby jiml8 » Nov 20th, '21, 16:54

Your answer lies in /sbin/dhclient-script.

Mageia uses the isc dhcp suite, and isc dhclient handles all its system dependent things using dhclient-script. This will include setting up the route for the newly configured interface. If you grep that script, you will find lots of references to metric, in connection with how the routes are set.

Study and play with that script, and you will solve your problem. Once you have solved your problem, be careful to backup your changes because the script is in /sbin and an update might very well wipe it out.

You are teetering on the edge of my world, where your particular needs cause you to vary a considerable distance from what Mageia expects. This has implications, particularly with upgrades. I suggest you document carefully what you have done and are doing; you will need to revisit it from time to time.

Sorry I did not see this thread sooner; I have been very busy. As it happens, I have been very busy with a product that explicitly supports the configuration of N wired and M wireless connections, and handles dynamic reconfiguration among those interfaces, including setting appropriate metrics for the various connections.
jiml8
 
Posts: 1253
Joined: Jul 7th, '13, 18:09

Re: Preventing automatic metric reset

Postby pmr » Feb 10th, '22, 21:18

THX

FYI I created a small workaround that works as I expect:

Code: Select all
[root@pmrnote Temp]# cat /etc/dhclient-enter-hooks.d/routes-enter
if [[ "$interface" == "enp2s0" ]]; then
   IF_METRIC=66
fi

if [[ "$interface" == "wlp1s0" ]]; then
   IF_METRIC=666
fi

[root@pmrnote Temp]# cat /etc/dhclient-exit-hooks.d/routes-exit
ifmetric enp2s0  66
ifmetric wlp1s0 666

[root@pmrnote Temp]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         172.18.0.1      0.0.0.0         UG    66     0        0 enp2s0
0.0.0.0         172.18.0.1      0.0.0.0         UG    666    0        0 wlp1s0
172.18.0.0      0.0.0.0         255.255.255.0   U     66     0        0 enp2s0
172.18.0.0      0.0.0.0         255.255.255.0   U     666    0        0 wlp1s0
[root@pmrnote Temp]#
pmr
 
Posts: 10
Joined: Sep 29th, '21, 11:41


Return to Networking

Who is online

Users browsing this forum: No registered users and 1 guest