You are not logged in.

#1 2022-03-21 13:30:10

kflak
Member
Registered: 2017-09-23
Posts: 52

How to make systemd-networkd prioritize iwd over ethernet connection?

I have a situation where I run a local network between two computers over an ethernet router. The ethernet router is not connected to the internet, but the wireless network is. I would like to be able to stay online, even when I am connected to the local, ethernet network... Is there a way to tell systemd-networkd/iwd/systemd-resolved to prioritize wifi over ethernet for internet, while maintaining the ethernet connection? I use iwd, systemd-networkd and systemd-resolved for my network needs. I tried setting RouteMetric to different values (I assume a lower value has a higher priority) but this didn't seem to work.

My config:

/etc/systemd/network/20-wired.network
---
[Match]
Name=enp0s31f6

[Network]
DHCP=yes

[DHCPv4]
RouteMetric=20
/etc/systemd/network/25-wireless.network
---
[Match]
Name=wlan0

[Network]
DHCP=yes 

[DHCPv4]
RouteMetric=10

Offline

#2 2022-03-21 17:23:48

Tarqi
Member
From: Ixtlan
Registered: 2012-11-27
Posts: 180
Website

Re: How to make systemd-networkd prioritize iwd over ethernet connection?

Make sure that only one default route exists: the internet one.


Knowing others is wisdom, knowing yourself is enlightenment. ~Lao Tse

Offline

#3 2022-03-21 17:35:38

progandy
Member
Registered: 2012-05-17
Posts: 5,319

Re: How to make systemd-networkd prioritize iwd over ethernet connection?

Tarqi wrote:

Make sure that only one default route exists: the internet one.

That is the easiest solution, just set set DefaultRouteOnDevice=false in the [Network] section I think.

If you want to use the ethernet as a fallback connection, you can set up both computers as a gateway for the ethernet and then choose a different metric for the default routes.

The RouteMetric option cannot set the metric for the default route, only the prefix routes. A custom route section should work, though. A lower metric will have a higher priority. Maybe you have to use DefaultRouteOnDevice=false as well.

[Route]
Destination=0.0.0.0/0
Metric=10 #or 11 or 20

The same can be done for ipv6 with ::/0

Last edited by progandy (2022-03-21 17:44:43)


| alias CUTF='LANG=en_XX.UTF-8@POSIX ' | alias ENGLISH='LANG=C.UTF-8 ' |

Offline

Board footer

Powered by FluxBB