Based on the other answer, I came up with this (tested on Kubuntu 20.04).
It auto-disconnects wifi on wired connection, except for connection names ending with -hotspot (like the default names Kubuntu uses for created access point connections). It allows sharing wireless hotspot from cable. So, instead of disabling radio for all WiFi, it just disconnects the network you're using. When the cable is unplugged, it reconnects the wireless device wlo1, which makes it reconnect the last used WiFi network.
Note that if you turn off the computer without cable and plug it before turning it on, it may start with both wifi and wired connections. Similarly, I presume, if you remove the cable while computer is off, it won't auto-connect at startup, I think.
sudo nano /etc/NetworkManager/dispatcher.d/99-disable-wireless-when-wired
sudo chmod 0744 /etc/NetworkManager/dispatcher.d/99-disable-wireless-when-wired
#!/bin/sh
myname=${0##*/}
log() { logger -p user.info -t "${myname}[$$]" "$*"; }
IFACE=$1
ACTION=$2
case ${IFACE} in
eth*|usb*|en*)
case ${ACTION} in
up) # when plugging ethernet cable
log "disconnecting wifi when wired"
# list active connections
nmcli -f uuid,type,name connection show --active |
# filter wifi except names ending with -hotspot, return UUID
awk '/\S\s+wifi\y/ && !/-hotspot\s*$/ {print $1;}' |
# disconnect these UUIDs
xargs -r nmcli connection down
;;
down) # when unplugging ethernet cable
log "reconnecting wifi when not wired"
# auto-choose wifi to reconnect
nmcli device connect wlo1
;;
esac
;;
esac
rfkill unblock wifiafter you've connectedeth0and you want to share, thenrfkill block wifiwhen you're done? – waltinator Mar 15 '12 at 01:40CONNECTION_UUIDto the identifier for that connection. I was thinking that the script could do something like only disable WiFi for the connection that I have declared the "standard" wired connection but leave it enabled ifeth0is activated by a different connection. I haven't tried it so I don't know if it works. But your point about just controlling it manually is a good one. – Richard Hansen Mar 15 '12 at 03:57eth0|usb0)to also disable/enable WiFi when USB tethering is activated/deactivated. – krlmlr Nov 25 '13 at 12:32nmcli nm wifi offandnmcli nm wifi on. But I don't have any particular reason for believing that the nmcli commands are better. I just wanted to do everything the NetworkManager way. – Jesse Hallett Jan 23 '14 at 01:35nmcli nm wifi offis correct—when I runnmcli r wifi offI getError: Object 'r' is unknown, try 'nmcli help'.– Richard Hansen Dec 27 '14 at 00:42Summary: If you are on Ubuntu "nm" works; if you are not use "r" (short for radio).
– doublehelix Dec 27 '14 at 08:03Zestyso should still be supported. – shadowbq Sep 07 '17 at 13:55nmcli radio wifi offdisables WiFi completely, so I cant create a hotspot. It fails with error: "Connection 'me-hotspot' is not available on device wlo1 because device is not available". – geekley Mar 01 '21 at 16:04