2

I want to switch between the Wifi and ethernet in Linux (Ubuntu 10.04) . I have searched many ways and I found it can be done using firestarter — autoswitch between wired and wireless networks .

For this I need to install the firestarter package in Ubuntu.

Is this the correct way for switching between eth0 and wifi ? I wanted to implement it using command line without installing any new packages.

Please help. Thanks in advance

1

I created the script for connection and disconnection from wifi and ethernet

Disconnect the wifi

killall wpa_supplicant
wirelessname=`ls /sys/class/net | grep wlan* | head -1`
ifconfig $wirelessname down

Connect the wifi

wirelessname=`ls /sys/class/net | grep wlan* | head -1`
ifconfig $wirelessname up > /dev/null 2>&1 &
killall wpa_supplicant > /dev/null 2>&1 &
iwconfig $wirelessname power off > /dev/null 2>&1 &
wpa_passphrase $1 $2 > /root/wps.conf
wpa_supplicant -Dwext -i$wirelessname -c/root/wps.conf > /dev/null 2>&1 &
sleep 5
dhclient -r > /dev/null 2>&1 &
dhclient $wirelessname > /dev/null 2>&1 &

Connect Ethernet

ifconfig $(ip link show | grep eth | grep state | awk '{printf $2}'| sed -e 's/:$//') up
ifconfig $(ifconfig | grep eth | awk '{print $1}'| head -1 ) $(ifconfig  | grep Bcast | awk '{printf $2}' | cut  -c6-) up

Disconnect ethernet

ifconfig $(ifconfig | grep eth | awk '{print $1}' | head -1 )  down 
1

Connman(1) can be used to prioritize your connections to prefer wired networks and auto-connect to wireles when the wired connection is unavailable. It is supported by Intel, so it can be hostile to non-intel networking hardware: I can't use Connman(1) since my wifi driver won't set flags Intel expects to enable the adapter. I get "no carrier" error and no wifi connection. However, it seems to connect quickly when I plug in the wired connection.

You need to configure /etc/connman/main.conf/main.conf with something like:

  BackgroundScanning = false
  DefaultAutoConnectTechnologies = ethernet,wifi 
  PreferredTechnologies = ethernet,wifi
  SingleConnectedTechnology = true

to ensure only wifi or ethernet is connected. Then, use an interactive connmanctl(1) session as indicated by the man page to connect to wifi the first time or edit the settings file for your interface found in /var/lib/connman (this seems easier to me, but restart required.) See connman-service.config(5)

If you have ifupdown or its variants installed, you might remove those to avoid collisions before installing connman(1)

  • Welcome to Ask Ubuntu! :-) Great first answer! Upvoted! – Fabby Jul 17 '18 at 21:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.