[SOLVED] Is there a more efficient way to switch networks using command line?
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Is there a more efficient way to switch networks using command line?
Hi, everybody .
How to switch between two networks available at the same company, using the command line?
I set priority = 5 in one and priority = 4 in another.
Is there another way to switch between networks without having to change the priority level in the wpa_supplicant file?
I am looking for easiest way to switch between networks, without to use networkmanager.
Some command that removed the configuration of the second network.
To add second essid i type: wpa_passphrase myessid password >> /etc/wpa_supplicant.conf
This">>" adds my second essid in wpa_supplicant.
Is there possible to undo >> command and to erase or to comment generated lines by >> ?
I'm not too familiar with this, but from reading, it looks like there's two options.
The first is to just have two different wpa_supplicant.conf files. Each one containing a specific network and passphrase. Then you'd just change your wpa_supplicant command to use a specific conf file based on what network you want to connect to.
The second is more of a guess based on some reading online, but if you have both networks in your wpa_supplicant.conf, if you connect to one of them using iwconfig before running wpa_supplicant, it should try and send the passphrase afterwards.
I'm not too familiar with this, but from reading, it looks like there's two options.
The first is to just have two different wpa_supplicant.conf files. Each one containing a specific network and passphrase. Then you'd just change your wpa_supplicant command to use a specific conf file based on what network you want to connect to.
The second is more of a guess based on some reading online, but if you have both networks in your wpa_supplicant.conf, if you connect to one of them using iwconfig before running wpa_supplicant, it should try and send the passphrase afterwards.
Thanks, Friend.
I am using the second way: Two essids in my only wpa_supplicant.
I seted the commands you said in /etc/rc.d/rc.local to run automatically:
#!/bin/sh
#
# /etc/rc.d/rc.local: Local system initialization script.
#
# Put any local startup commands in here. Also, if you have
# anything that needs to be run at shutdown time you can
# make an /etc/rc.d/rc.local_shutdown script and put those
# commands in there.
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf -B -Dnl80211
dhclient
ntpdate pool.ntp.org
You're in luck brother
I made a script just for this purpose, very simple, all it does is find the proper keywords in the config files and replace them with whatever string you want.
Code:
#!/bin/bash
# WiFi easy config script (more features coming soon)
# USE AS ROOT - SUDO WILL NOT DO
until [ "$ssidyesno" = "yes" ]
do
echo SSID:
read SSID
echo yes/no
read ssidyesno
done
until [ "$passwordyesno" = "yes" ]
do
echo Password:
read password
echo yes/no
read passwordyesno
done
#wpa_supplicant
sed -i 's/^psk=.*$/psk="$password"/' /etc/wpa_supplicant.conf
sed -i 's/^ssid=.*$/ssid="$SSID"/' /etc/wpa_supplicant.conf
#rc.inet1.conf
sed -i 's/^WLAN_ESSID[4]=.*$/WLAN_ESSID[4]="$SSID"/' /etc/rc.d/rc.inet1.conf
sed -i 's/^WPAPSK=.*$/WPAPSK=$password"/' /etc/rc.d/rc.inet1.conf
killall wpa_supplicant
killall dhcpcd
wpa_supplicant
dhcpcd
.
Not exactly sure if the proper command syntax and such is correct, haven't really tested it out properly yet. Poke around in your files first to see if it actually replaces the correct text.
Last edited by RedBlueYellow12; 03-02-2020 at 04:34 AM.
I am looking for easiest way to switch between networks ?
So you want to use NetworkManager without using NetworkManager.
You can make your life easy by using nmcli (NetworkManager's command line tool). Or jump through burning loops and reinvent the wheel by using something else.
I would advise against editing wpa_supplicant.conf just to switch networks. If you use wpa_supplicant to connect to Wi-Fi routers then use wpa_cli or wpa_gui to manage connections.
without a network manager, how are you going to manage your network switching between one to the other connection?
the person being the first and foremost, then software to elevate some of what a person has to do to change connections.
without a network manager, how are you going to manage your network switching between one to the other connection?
the person being the first and foremost, then software to elevate some of what a person has to do to change connections.
wpa_cli's select_network option switches to the selected network and disables the others in the configuration file.
You're in luck brother
I made a script just for this purpose, very simple, all it does is find the proper keywords in the config files and replace them with whatever string you want.
Code:
#!/bin/bash
# WiFi easy config script (more features coming soon)
# USE AS ROOT - SUDO WILL NOT DO
until [ "$ssidyesno" = "yes" ]
do
echo SSID:
read SSID
echo yes/no
read ssidyesno
done
until [ "$passwordyesno" = "yes" ]
do
echo Password:
read password
echo yes/no
read passwordyesno
done
#wpa_supplicant
sed -i 's/^psk=.*$/psk="$password"/' /etc/wpa_supplicant.conf
sed -i 's/^ssid=.*$/ssid="$SSID"/' /etc/wpa_supplicant.conf
#rc.inet1.conf
sed -i 's/^WLAN_ESSID[4]=.*$/WLAN_ESSID[4]="$SSID"/' /etc/rc.d/rc.inet1.conf
sed -i 's/^WPAPSK=.*$/WPAPSK=$password"/' /etc/rc.d/rc.inet1.conf
killall wpa_supplicant
killall dhcpcd
wpa_supplicant
dhcpcd
.
Not exactly sure if the proper command syntax and such is correct, haven't really tested it out properly yet. Poke around in your files first to see if it actually replaces the correct text.
I would advise against editing wpa_supplicant.conf just to switch networks. If you use wpa_supplicant to connect to Wi-Fi routers then use wpa_cli or wpa_gui to manage connections.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.