Disable WLan if Wired/Cable Network is available
Hire the world's top talent on demand or became one of them at Toptal: https://topt.al/25cXVn
and get $2,000 discount on your first invoice
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Thinking It Over
--
Chapters
00:00 Disable Wlan If Wired/Cable Network Is Available
00:29 Answer 1 Score 3
00:41 Answer 2 Score 2
01:59 Accepted Answer Score 75
02:40 Answer 4 Score 4
04:15 Thank you
--
Full question
https://superuser.com/questions/233448/d...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#linux #networking #wirelessnetworking #ubuntu1004
#avk47
ACCEPTED ANSWER
Score 75
You can drop this script to /etc/NetworkManager/dispatcher.d/99-wlan
:
#!/bin/bash
wired_interfaces="en.*|eth.*"
if [[ "$1" =~ $wired_interfaces ]]; then
case "$2" in
up)
nmcli radio wifi off
;;
down)
nmcli radio wifi on
;;
esac
fi
Don't forget afterwards:
chmod +x /etc/NetworkManager/dispatcher.d/99-wlan
This catches the legacy eth*
names and the new kernel "predictable named interfaces" that start with en
and then use either the bus path or the MAC address so that the name of each interface is the same on every boot. This worked with the USB-C (passthrough) and USB ethernet adapter I tried with and I'm confident it will work with built-in adapters as well.
ANSWER 2
Score 4
Quite simply for the gnome GUI approach...
Right click on the network system indicator in the gnome panel up by your clock. (The indicator will be one of two icons; either the up/down arrows (LAN) or the traditional WiFi Funnel. Note that the up/down icon will appear when both LAN & WiFi or only LAN are connected and the WiFi funnel appears when connected via WiFi ONLY. (LAN Disconnected)) -- [LAN trumps WiFi automatically.*]
Select 'Edit Connections...'
- Select the 'Wireless' tab.
- Double click the first connection in your list and Uncheck the 'Connect automatically' box.
- Click the 'Apply...' button.
- Repeat for each connection in the list.
This will leave the Wireless network operational for on-the-fly manual connections and disconnections available by left clicking the network icon, without the NM trying to Automatically connect you all the time.
Naturally you could also disable/enable Wireless by right clicking the network icon and then left clicking on the "Enable Wireless' selection, effectively bringing down or up the Wireless interface as indicated by the presence or absence of the check mark.
- LAN trumps WiFi automatically, there is no need to disable WiFi. Simply unplugging your Ethernet cable will seamlessly transfer the connection to WiFi and you can pick up and move about without any fuss. Likewise, with reconnecting the LAN.
- While LAN does trump WiFi the NM (Network Manager) will find what you seek should you be on different networks simultaneously and are working both online (WiFi) and with a local host (LAN) or V/V for example.
ANSWER 3
Score 3
Just a guess but i assume ifplugd could help. You could make it shut down wifi when cable is used.
ANSWER 4
Score 2
Create two simple 'scripts', the name of the script is not important (I simply use wlan) and I assume there is only one cabled network interface, and is thus called 'eth0'... Check this with 'ifconfig' if you're not sure. Note that this disabled wireless entirely, not just wlan0. (Only an issue if you have multiple wlan interfaces and only want to disable specific ones)
These scripts could easily be adapted - by boolean logic - to a situation in which you have two or more cabled network interfaces.
Make sure these scripts are executable with 'chmod +x'
/etc/network/ip-up.d/wlan
#!/bin/sh
# If eth0 goes up, disable wireless
if [ "$IFACE" = "eth0" ]; then
dbus-send --system --type=method_call --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.DBus.Properties.Set string:org.freedesktop.NetworkManager string:WirelessEnabled variant:boolean:false
fi
/etc/network/if-down.d/wlan
#!/bin/sh
# If eth0 goes down, enable wireless
if [ "$IFACE" = "eth0" ]; then
dbus-send --system --type=method_call --dest=org.freedesktop.NetworkManager /org/freedesktop/NetworkManager org.freedesktop.DBus.Properties.Set string:org.freedesktop.NetworkManager string:WirelessEnabled variant:boolean:true
fi
This enables/disables wireless in the NetworkManager that can usually be found as an system indicator in the Gnome panel.
You could also use 'ifconfig wlan0 down' or 'ifconfig wlan0 up' instead of the dbus-send line, but this should be more user-friendly and interfere less with Ubuntu's system utilities.
Tested with Ubuntu Desktop 10.10, and should work with earlier versions or other distributions using NetworkManager and dbus.