You are not logged in.

#1 2021-10-04 22:50:37

hwallace
Member
Registered: 2021-08-30
Posts: 110

[SOLVED] routing systemd-networkd with two interfaces

I have a wired and wireless connection. I want them active concurrently (the wireless is for a VM)  and I want the host machine to prefer the ethernet.

With this systemd-networkd configuration

:> cat 100-eno1.network 
[Match]
Name=eno1

[Network]
Address=10.0.0.170/24
Gateway=10.0.0.1
Metric=1000



:> cat 200-wlan0.network 
[Match]
Name=wlan0

[Network]
Address=10.0.0.172/24
Gateway=10.0.0.1
Metric=5000

I am booting to

:> ip r
default via 10.0.0.1 dev wlan0 proto static 
default via 10.0.0.1 dev eno1 proto static 
10.0.0.0/24 dev wlan0 proto kernel scope link src 10.0.0.172 
10.0.0.0/24 dev eno1 proto kernel scope link src 10.0.0.170 

If I reset wlan0  I get the routing table I'm expecting.

:> ip r
default via 10.0.0.1 dev eno1 proto static 
default via 10.0.0.1 dev wlan0 proto static 
10.0.0.0/24 dev eno1 proto kernel scope link src 10.0.0.170 
10.0.0.0/24 dev wlan0 proto kernel scope link src 10.0.0.172 

https://wiki.archlinux.org/title/system … me_machine says

Note: The Metric option is for static routes while the RouteMetric option is for setups not using static routes.

The article shows examples only for the DHCP option, placing the RouteMetric statement in the DHCP section. 

[Match]
Name=enp1s0

[Network]
DHCP=yes

[DHCP]
RouteMetric=10

I expect to boot to eno1 as the default but I'm getting wlan0.  So I'm missing some point here.

Last edited by hwallace (2021-10-06 12:40:40)

Offline

#2 2021-10-05 17:16:30

pm3840
Member
Registered: 2013-12-16
Posts: 67

Re: [SOLVED] routing systemd-networkd with two interfaces

Change [DHCP] to [DHCPv4]. Man page only shows DHCPv4 and DHCPv6 sections there's no DHCP section.

Offline

#3 2021-10-05 17:26:03

hwallace
Member
Registered: 2021-08-30
Posts: 110

Re: [SOLVED] routing systemd-networkd with two interfaces

pm3840 wrote:

Change [DHCP] to [DHCPv4]. Man page only shows DHCPv4 and DHCPv6 sections there's no DHCP section.

I don't have a DHCP section. These are static IPs. The last example configuration file is from the Arch wiki.

Last edited by hwallace (2021-10-05 17:27:42)

Offline

#4 2021-10-05 17:56:43

pm3840
Member
Registered: 2013-12-16
Posts: 67

Re: [SOLVED] routing systemd-networkd with two interfaces

Use this for static IP:

[Match]
Name=link1

[Address]
Address=192.168.1.253/24
RouteMetric=100

[Route]
Gateway=192.168.1.1
Metric=100

[Match]
Name=link2

[Address]
Address=192.168.1.254/24
RouteMetric=200

[Route]
Gateway=192.168.1.1
Metric=200

Offline

#5 2021-10-06 12:40:15

hwallace
Member
Registered: 2021-08-30
Posts: 110

Re: [SOLVED] routing systemd-networkd with two interfaces

Thank you. That works and has been stable now through a few reboots and overnight so I will mark this as SOLVED

But I want to point back to this :

https://wiki.archlinux.org/title/system … me_machine says

Note: The Metric option is for static routes while the RouteMetric option is for setups not using static routes.

This suggests to my reading that RouteMetric is not applied for static routes. My assumption here, perhaps incorrect, is that I am using a static route. Am I not? 

Anyway thanks for the tips. Here are the changes you suggest, from the man page.

Note: AddPrefixRoute is false by default.

[ADDRESS]
        RouteMetric=
           The metric of the prefix route, which is pointing to the subnet of
           the configured IP address, taking the configured prefix length into
           account. Takes an unsigned integer in the range 0...4294967295.
           When unset or set to 0, the kernel's default value is used. This
           setting will be ignored when AddPrefixRoute= is false.
           
           
[ROUTE]
        Metric=
           The metric of the route. Takes an unsigned integer in the range
           0...4294967295. Defaults to unset, and the kernel's default will be
           used.
         

Last edited by hwallace (2021-10-06 12:43:28)

Offline

#6 2021-10-06 13:45:39

pm3840
Member
Registered: 2013-12-16
Posts: 67

Re: [SOLVED] routing systemd-networkd with two interfaces

Default route is static route. With that said, here's a summary:

Address->RouteMetric applies to connected route
Route->Metric deals with static route
DHCPxx->RouteMetric applies to routes learned from DHCP

Offline

Board footer

Powered by FluxBB