Quick switching from CLI between LAN and WiFi
Usually, I work on my LAN connection, but to use a printer I need to jump to a Wi-Fi connection. This is needed because the printer is connected to the other network and I can't reach this network from my LAN. I prepared two simple bash scripts and saved it in the directory that included in the environment PATH variable, so I could call these two scripts from anywhere. This post is intended for saving these scripts.
The same actions can be called from the Network Manager, but it requires more steps, like find wifi connection, turning it on, finding a LAN connection, turn it off.
Anyway here are the scripts
Create 2wifi file
1 2 3 |
$ touch 2wifi && chmod +x 2wifi && nano 2wifi |
with the next content
1 2 3 4 5 6 7 8 9 10 11 |
#!/bin/bash INT_WIFI=`ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' | grep wlx | head -1` INT_ETH=`ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' | grep eno1 | head -1` nmcli dev disconnect $INT_ETH nmcli dev connect $INT_WIFI echo "\n" nmcli dev status | grep -E "(DEVICE|$INT_WIFI|$INT_ETH)" |
Create 2lan file
1 2 3 |
$ touch 2lan && chmod +x 2lan && nano 2lan |
with the next content
1 2 3 4 5 6 7 8 9 10 11 |
#!/bin/bash INT_WIFI=`ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' | grep wlx | head -1` INT_ETH=`ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' | grep eno1 | head -1` nmcli dev disconnect $INT_WIFI nmcli dev connect $INT_ETH echo "\n" nmcli dev status | grep -E "(DEVICE|$INT_WIFI|$INT_ETH)" |
If you are on wifi, just execute 2lan, eg
1 2 3 |
$ 2lan |
and vice versa - if you are on lan connection just execute 2wifi
1 2 3 |
$ 2wifi |
Notes
If something doesn't make sure that the interface is parsed correctly from your ifconfig output and align the next command accordingly
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
#!/bin/bash echo "Step 1 == WIFI" ifconfig -a echo "Step 2 == WIFI" ifconfig -a | sed 's/:[ \t].*//;/^$/d' echo "Step 3 == WIFI" ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' echo "Step 4 == WIFI" ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' | grep wlx echo "Step 5 == WIFI" ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' | grep wlx | head -1 echo "Step 1 == WIFI" ifconfig -a echo "Step 2 == ETH" ifconfig -a | sed 's/:[ \t].*//;/^$/d' echo "Step 3 == ETH" ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' echo "Step 4 == ETH" ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' | grep eno1 echo "Step 5 == ETH" ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' | grep eno1 | head -1 ## Make changes in the next lines ## INT_WIFI=`ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' | grep wlx | head -1` ## INT_ETH=`ifconfig -a | sed 's/:[ \t].*//;/^$/d' | sed -e 's/://' | grep eno1 | head -1` |
Author: | Tags: /
| Rating:
Leave a Reply