View previous topic :: View next topic |
Author |
Message |
thegrind n00b
Joined: 22 Sep 2024 Posts: 26
|
Posted: Wed Nov 06, 2024 5:12 am Post subject: Giving wlan0 priority over eth0 |
|
|
I have installed Gentoo on my RPi5. The Pi has a connection for the ethernet cable and wifi. I have them both connected and they both have different local ips so for example eth0 has 192.168.1.10 and wlan0 has 192.168.1.11. My wifi connection is faster so I would like to use this is as the default interface but every time I boot it defaults to eth0. Does anyone know how I can set this up. I did it before with NetworkManager by using nmcli and setting a priority so I'd like to see if I could do something similar with iwd instead of having to switch to NM. |
|
Back to top |
|
|
pingtoo Veteran
Joined: 10 Sep 2021 Posts: 1339 Location: Richmond Hill, Canada
|
Posted: Wed Nov 06, 2024 7:19 am Post subject: |
|
|
Have you tried with nmcli?
I don't use wifi for my rpi5, but nmcli does show Code: | rpi5 ~ # nmcli
end0: connected to Wired connection 1
"end0"
ethernet (macb), 2C:xx:xx:xx:xx:xx, hw, mtu 1500
ip4 default
inet4 192.168.xx.xx/24
route4 192.168.xx.0/24 metric 100
route4 default via 192.168.xx.xx metric 100
docker0: connected (externally) to docker0
"docker0"
bridge, 02:42:C0:5D:C6:4F, sw, mtu 1500
inet4 172.17.0.1/16
route4 172.17.0.0/16 metric 0
inet6 fe80::42:c0ff:fe5d:c64f/64
route6 fe80::/64 metric 256
lo: connected (externally) to lo
"lo"
loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536
inet4 127.0.0.1/8
inet6 ::1/128
wlan0: unavailable
"Broadcom Wi-Fi"
wifi (brcmfmac), xx:xx:xx:xx:xx:xx, sw disabled, hw, mtu 1500
DNS configuration:
servers: 192.168.xx.xx
domains: home
interface: end0
Use "nmcli device show" to get complete information about known devices and
"nmcli connection show" to get an overview on active connection profiles.
Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.
rpi5 ~ # |
And networkcli show Code: | rpi5 ~ # networkctl
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback - unmanaged
2 end0 ether - unmanaged
3 wlan0 wlan - unmanaged
4 docker0 bridge - unmanaged
4 links listed. |
|
|
Back to top |
|
|
szatox Advocate
Joined: 27 Aug 2013 Posts: 3477
|
Posted: Wed Nov 06, 2024 9:01 am Post subject: |
|
|
1) Why not just unplug the wire if you don't want to use it anyway?
2) What do you use to manage wired connection? I though iwd handles wireless part and is a replacement for wpa_supplicant rather than networkmanager, am I wrong about it? _________________ Make Computing Fun Again |
|
Back to top |
|
|
thegrind n00b
Joined: 22 Sep 2024 Posts: 26
|
Posted: Thu Nov 07, 2024 1:56 am Post subject: |
|
|
pingtoo wrote: | Have you tried with nmcli?
I don't use wifi for my rpi5, but nmcli does show Code: | rpi5 ~ # nmcli
end0: connected to Wired connection 1
"end0"
ethernet (macb), 2C:xx:xx:xx:xx:xx, hw, mtu 1500
ip4 default
inet4 192.168.xx.xx/24
route4 192.168.xx.0/24 metric 100
route4 default via 192.168.xx.xx metric 100
docker0: connected (externally) to docker0
"docker0"
bridge, 02:42:C0:5D:C6:4F, sw, mtu 1500
inet4 172.17.0.1/16
route4 172.17.0.0/16 metric 0
inet6 fe80::42:c0ff:fe5d:c64f/64
route6 fe80::/64 metric 256
lo: connected (externally) to lo
"lo"
loopback (unknown), 00:00:00:00:00:00, sw, mtu 65536
inet4 127.0.0.1/8
inet6 ::1/128
wlan0: unavailable
"Broadcom Wi-Fi"
wifi (brcmfmac), xx:xx:xx:xx:xx:xx, sw disabled, hw, mtu 1500
DNS configuration:
servers: 192.168.xx.xx
domains: home
interface: end0
Use "nmcli device show" to get complete information about known devices and
"nmcli connection show" to get an overview on active connection profiles.
Consult nmcli(1) and nmcli-examples(7) manual pages for complete usage details.
rpi5 ~ # |
And networkcli show Code: | rpi5 ~ # networkctl
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback - unmanaged
2 end0 ether - unmanaged
3 wlan0 wlan - unmanaged
4 docker0 bridge - unmanaged
4 links listed. |
|
I didn't install NetworkManager on this install thus I don't have nmcli as I am just using iwd. I had it working on my previous microsd with NM as it was fairly easy. The problem I've been having with the PI5 on both Arch (using wpa_supplicant) and Getntoo (NM) is the network interfaces freezing up randomly. Sometimes after a half day sometimes after a couple of days. I would like to try to make it work with iwd but I'm not sure if this is doable. |
|
Back to top |
|
|
thegrind n00b
Joined: 22 Sep 2024 Posts: 26
|
Posted: Thu Nov 07, 2024 2:01 am Post subject: |
|
|
szatox wrote: | 1) Why not just unplug the wire if you don't want to use it anyway?
2) What do you use to manage wired connection? I though iwd handles wireless part and is a replacement for wpa_supplicant rather than networkmanager, am I wrong about it? |
1. It seems any large emerge doesn't do well with wifi so I like to keep plugged in and then I can just up or down the network interface I don't want to use.
2. I'm not sure what manages eth0. Naturally the wifi is managed by iwd. This is probably why I can't set a priority since they are two different managers. I'll just try to work off wifi and see how it goes or buy a new wall outlet ethernet connection with a high speed one as my current one is 100MB/sec |
|
Back to top |
|
|
flexibeast Guru
Joined: 04 Apr 2022 Posts: 473 Location: Naarm/Melbourne, Australia
|
|
Back to top |
|
|
szatox Advocate
Joined: 27 Aug 2013 Posts: 3477
|
Posted: Thu Nov 07, 2024 8:51 am Post subject: |
|
|
Well, the rules for selecting the outgoing interface go like this:
1 Find all interfaces with routing rules containing the destination
2 Order them by mask (longer mask = higher priority)
3 Break ties with metrics (lower cost/number = higher priority)
Wifi's default metric is like 600, and ethernet's default metric depends on interface speed, but will always be lower. And here comes trick from OpenVPN:
add 2 routes to your wifi, to 0.0.0.0/1 and 128.0.0.0/1
Those will override the default gateway ( 0/0 ) regardless of metrics. And you can do the same with ipv6 address space. It is a bit of a hack, but other things are unlikely to mess this setup up even if they try.
Quote: | I'm not sure what manages eth0 | Ah, I'm not sure what. Yes, this one is known to cause problems.
Quote: | It seems any large emerge doesn't do well with wifi |
That's weird. Can you explain that part more? This also looks like the actual problem you should be solving instead of doing workarounds on your network. What's going wrong there?
One thing that comes to my mind is that maybe your power supply is not strong enough to radiate power while spinning all cores at full throttle. _________________ Make Computing Fun Again |
|
Back to top |
|
|
thegrind n00b
Joined: 22 Sep 2024 Posts: 26
|
Posted: Fri Nov 08, 2024 5:18 am Post subject: |
|
|
flexibeast wrote: | Since you use `networkctl` i presume you're on a systemd-based setup. i'm not a systemd user myself, so i can't help with specifics, but what i can say is that you need to specify a routing metric for each interface so that the wired interface has a higher priority. (On an OpenRC+netifrc system, like i have, one specifies these metrics in the /etc/conf.d/net configuration file.) |
Thanks for the help. I am not using systemd as I am using openrc. I tried the adding the priority to the /etc/conf.d/net but this didn't change. I assume that Netifrc can't control wlan0 at least I didn't see it in the Wiki. I don't have networkctl as a command. |
|
Back to top |
|
|
thegrind n00b
Joined: 22 Sep 2024 Posts: 26
|
Posted: Fri Nov 08, 2024 5:25 am Post subject: |
|
|
szatox wrote: | Well, the rules for selecting the outgoing interface go like this:
1 Find all interfaces with routing rules containing the destination
2 Order them by mask (longer mask = higher priority)
3 Break ties with metrics (lower cost/number = higher priority)
Wifi's default metric is like 600, and ethernet's default metric depends on interface speed, but will always be lower. And here comes trick from OpenVPN:
add 2 routes to your wifi, to 0.0.0.0/1 and 128.0.0.0/1
Those will override the default gateway ( 0/0 ) regardless of metrics. And you can do the same with ipv6 address space. It is a bit of a hack, but other things are unlikely to mess this setup up even if they try.
Quote: | I'm not sure what manages eth0 | Ah, I'm not sure what. Yes, this one is known to cause problems.
Quote: | It seems any large emerge doesn't do well with wifi |
That's weird. Can you explain that part more? This also looks like the actual problem you should be solving instead of doing workarounds on your network. What's going wrong there?
One thing that comes to my mind is that maybe your power supply is not strong enough to radiate power while spinning all cores at full throttle. |
I'm not sure what the problem is. I had the same issue when trying to do a git pull as it would stall and give me a timeout error. I was trying to dl the kernel so I could compile. I dl the kernel sources by hooking up my Pi directly to the router. I ended up cross compiling in the end as I have a hdd on my Manjaro PC amd64. I am using the same power supply I had with my 3+ I think it is 4W and I think the Pi 5 wants 5W. I figured I wasn't connecting any disks to it so I thought would be okay.
I figured from reading that it would chose the wlan0 as it is twice as fast as my eth0 but it still defaults to eth0.
How do you do the OpenVPN trick? That's ultimately what I would like to do. |
|
Back to top |
|
|
flexibeast Guru
Joined: 04 Apr 2022 Posts: 473 Location: Naarm/Melbourne, Australia
|
Posted: Fri Nov 08, 2024 5:51 am Post subject: |
|
|
thegrind wrote: | [I am not using systemd as I am using openrc. |
Oh, sorry, i read your command `networkcli` as `networkctl`. :-/ i definitely need new glasses!
thegrind wrote: | I tried the adding the priority to the /etc/conf.d/net but this didn't change. I assume that Netifrc can't control wlan0 at least I didn't see it in the Wiki. |
It definitely can; i do so on my own system (well, the interface is actually called `wlp2s0`, but without persistent names, it's `wlan0`, and i've used netifrc to configure both). But for this to happen, you need to have configured your system appropriately, including creating a symlink for each interface you want netifrc to manage, configuring which program you want to use for a given interface (e.g `wpa_supplicant` or `iwd`), and starting an OpenRC service for each interface via those symlinks. i recommend reading the netifrc wiki page in full to understand what needs to be done.
i currently configure netifrc to use wpa_supplicant for the wifi interface; i haven't got it working with iwd yet. _________________ https://wiki.gentoo.org/wiki/User:Flexibeast |
|
Back to top |
|
|
szatox Advocate
Joined: 27 Aug 2013 Posts: 3477
|
Posted: Fri Nov 08, 2024 10:39 am Post subject: |
|
|
You can check routing table with
ip route
Add and remove rules manually with ip route add/del <rule> respectively.
Doing it automatically requires you to know what manages your network, so you can configure that thing to do your bidding correctly.
I still think you're over-engineering it though. If you want to use wifi because it's faster, but disable it for updates, you might just as well use wifi and enable eth for updates.
Also, depending on your actual use patterns, that speed difference between eth and wifi might not even matter, making the cable a better choice overall. _________________ Make Computing Fun Again |
|
Back to top |
|
|
thegrind n00b
Joined: 22 Sep 2024 Posts: 26
|
Posted: Tue Nov 19, 2024 6:06 pm Post subject: |
|
|
Code: | k@localhost ~ $ rc-update -v show
NetworkManager |
agetty |
atd | default
binfmt | boot
bluetooth | default
bootlogd |
bootmisc | boot
cgroups | sysinit
chronyd | default
consolefont |
dbus |
dcron | default
devfs | sysinit
dhcpcd | default
dmesg | sysinit
fsck | boot
git-daemon |
hostname | boot
hwclock | boot
ip6tables |
iptables |
iwd | boot
keymaps | boot
killprocs | shutdown
kmod-static-nodes | sysinit
kodi | default
local | default nonetwork
localmount | boot
loopback | boot
metalog |
mit-krb5kadmind |
mit-krb5kdc |
mit-krb5kpropd |
modemmanager |
modules | boot
mount-ro | shutdown
mtab | boot
net-online |
net.eth0 |
net.lo |
net.wlan0 |
netmount | default
nullmailer |
numlock |
openvpn |
osclock |
procfs | boot
pydoc-3.12 |
pydoc-3.13 |
root | boot
rsyncd |
runsvdir |
s6-svscan |
samba | default
save-keymaps | boot
save-termencoding | boot
savecache | shutdown
seedrng | boot
sshd | default
swap | boot
swclock |
sysctl | boot
sysfs | sysinit
systemd-tmpfiles-setup | boot
systemd-tmpfiles-setup-dev | sysinit
termencoding | boot
udev | sysinit
udev-settle |
udev-trigger | sysinit
wpa_supplicant |
|
I am looking to bond wlan0 (started with iwd) and eth0 but I cannot tell what is starting my ethernet connection as it's [/code]not started by net.lo. |
|
Back to top |
|
|
Ralphred l33t
Joined: 31 Dec 2013 Posts: 668
|
Posted: Tue Nov 19, 2024 6:28 pm Post subject: |
|
|
thegrind wrote: | but I cannot tell what is starting my ethernet connection | It doesn't matter if you bond them, you can delete both the net.eth0 and net.wlan0 symlinks from /etc/init.d/ in favour of net.bond0 |
|
Back to top |
|
|
pingtoo Veteran
Joined: 10 Sep 2021 Posts: 1339 Location: Richmond Hill, Canada
|
Posted: Tue Nov 19, 2024 6:29 pm Post subject: |
|
|
I think it is dhcpcd start it.
Check dmesg for dhcpcd messages. |
|
Back to top |
|
|
thegrind n00b
Joined: 22 Sep 2024 Posts: 26
|
Posted: Wed Nov 20, 2024 4:40 am Post subject: |
|
|
It was dhcpcd that was starting eth0. I removed it from the run level and then did net.eth0 and net.wlan0 and both of these worked. I then tried to bond them together following the Gentoo wiki. I was able to get bond0 to work with eth0 but I can't get it to work with wlan0 on it's own as I don't get any internet. I also noticed that it blanked out my /etc/resolv.conf file or if put down eth0 and wlan0 as slaves it doesn't use wlan0 as I unplug the ethernet and I lose internet. I am using iwd for wlan0 but I removed it from the runlevel.
Here is my net file.
Code: | config_eth0="null"
config_wlan0="null"
slaves_bond0="eth0 wlan0"
config_bond0="192.168.0.193/24"
# Pick a correct mode and additional configuration options which suit your needs
#modules_bond0="iwd"
mode_bond0="active-backup"
config_bond0="dhcpcd" |
I am not sure if I need the module_bond0='iwd'
cat /proc/net/bonding/bond0 says both eth0 and wlan0 are up. Also, ifconfig shows a bond address and wlan0 and eth0 are listed but no ip. When I try wlano on it's on I get a strange ip not the typical 192.168.0.193 type something like 162.109.56.176
What am I missing. |
|
Back to top |
|
|
Ralphred l33t
Joined: 31 Dec 2013 Posts: 668
|
Posted: Wed Nov 20, 2024 1:12 pm Post subject: |
|
|
Even with a working bond, the slaves will not show ip addresses, from a working bond on a Pi4: Code: | $ ip add
~snip~
2: eth0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc mq master bond0 state UP group default qlen 1000
link/ether dc:a6:32:b6:43:d0 brd ff:ff:ff:ff:ff:ff
3: wlan0: <BROADCAST,MULTICAST,SLAVE,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master bond0 state UP group default qlen 1000
link/ether dc:a6:32:b6:43:d0 brd ff:ff:ff:ff:ff:ff
4: bond0: <BROADCAST,MULTICAST,MASTER,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether dc:a6:32:b6:43:d0 brd ff:ff:ff:ff:ff:ff
inet 10.0.0.15/24 brd 10.0.0.255 scope global dynamic noprefixroute bond0
~snip~ |
/etc/conf.d/net: | config_eth0="null"
config_wlan0="null"
slaves_bond0="eth0 wlan0"
config_bond0="dhcp"
mode_bond0=0 #"balance-alb" |
I don't know how iwd works, I use wpa_supplicant here - it's effectively the equivalent of "plugging in the ethernet cable", it's in the same runlevels as net.bond0 and starts before it.
This is the same config that was working on the Pi5 before it got "sent on a mission".
Is this the chosen solution to making wlan0 have higher priority than eth0? Because setting /etc/conf.d/net snippet: | metric_eth0="101"
metric_wlan0="100" | seems a simpler option IMHO, plus you can switch eth0 to 99 (and back) on the fly when you want to run updates. |
|
Back to top |
|
|
thegrind n00b
Joined: 22 Sep 2024 Posts: 26
|
Posted: Thu Nov 21, 2024 12:16 am Post subject: |
|
|
After I removed dhcpcd from the run level and I added net.eth0 and net.wlan0 and made the metric changes, I am able to get wlan0 as the highest priority. Thanks for pointing me in the right direction.
I assumed with bonding that net.bond0 started the necessary services like wpa supplicant so that the wlan0 connects. Is this not the case. Do you have wpa _supplicant added to a run level with bonding and to a wpa_supplicant.conf file that has your SSDI and password?
The other day my wifi connection went bad and I got dropped to 7MB/s versus the usual 210MB/s. In bonding can you set it up, at least with wlan0 and eth0, to combine the two bandwidths together so if that situation happens again I will still be at 60MB/s (what eth0 puts out). Of course I can reboot just trying to see what I can make work. |
|
Back to top |
|
|
Ralphred l33t
Joined: 31 Dec 2013 Posts: 668
|
Posted: Thu Nov 21, 2024 12:09 pm Post subject: |
|
|
thegrind wrote: | Do you have wpa _supplicant added to a run level with bonding and to a wpa_supplicant.conf file that has your SSDI and password? | Yes I do. You could probably make netifrc do this for you, but I have "different things" happening in other runlevels so prefer to do it myself. I never read up much on the different bonding modes/options but the docs are here. |
|
Back to top |
|
|
thegrind n00b
Joined: 22 Sep 2024 Posts: 26
|
Posted: Sat Nov 23, 2024 3:19 am Post subject: |
|
|
Thanks for the help. My problem was that I wasn't starting wpa_supplicant. bond0 gets assigned an ip say 192.168.0.140. I use my Rpi to stream so if I unplug the ethernet cable while streaming it's like nothing happened. The only problem I have is I can no longer access 192.168.0.140 most of the time. I am using broadcast mode. I have also tried round robin. One time it worked to where I didn't lose my putty session on my windows pc but the other 5 or so times I have tested I lose my putty session and I can't ping 192.168.0.140. Ifconfig shows the ip of bond0 as 192.168.0.140 even with the cable unplugged. When I plug the cable in I can access 192.168.0.140 again. Do you know how I can fix this as I can't use my kodi remote when this happens. |
|
Back to top |
|
|
thegrind n00b
Joined: 22 Sep 2024 Posts: 26
|
Posted: Sat Nov 23, 2024 5:26 am Post subject: |
|
|
Okay, I figured it out. I had to set a static IP to bond0 and define a route to the router as the system was confused due to previous leases and bond0 wasn't being assigned a mac address. |
|
Back to top |
|
|
Ralphred l33t
Joined: 31 Dec 2013 Posts: 668
|
Posted: Sat Nov 23, 2024 12:03 pm Post subject: |
|
|
thegrind wrote: | Okay, I figured it out. I had to set a static IP to bond0 and define a route to the router as the system was confused due to previous leases and bond0 wasn't being assigned a mac address. | If bond0's mac keeps changing you can "fix" it - I had to because of the mac filtering on the AP (mac_bond0="aa:bb:cc:dd:ee:ff")
It's also worth noting the the 802.[*] based bond modes won't work with "wireless" in one of your links. I originally set this up on a laptop, so I could "unplug" it and work on it directly, then plug it back in to the network and power later without losing any ssh sessions, "balance-alb" was the best working mode, but "0" is my default for debugging. It's the "standard" config I deploy on Pis unless they are running a "local admin AP" on wlan0. |
|
Back to top |
|
|
|