LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 03-01-2020, 08:25 PM   #1
Xiloba
LQ Newbie
 
Registered: Feb 2020
Location: Brazil
Distribution: Slackware
Posts: 12

Rep: Reputation: Disabled
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?

Last edited by Xiloba; 03-01-2020 at 08:27 PM.
 
Old 03-01-2020, 08:40 PM   #2
upnort
Senior Member
 
Registered: Oct 2014
Distribution: Slackware
Posts: 1,893

Rep: Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162Reputation: 1162
Are you looking for the nmcli command?

Code:
nmcli c up name_of_connection
 
2 members found this post helpful.
Old 03-01-2020, 09:04 PM   #3
Xiloba
LQ Newbie
 
Registered: Feb 2020
Location: Brazil
Distribution: Slackware
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by upnort View Post
Are you looking for the nmcli command?

Code:
nmcli c up name_of_connection
Thanks, Bro.

Im not looking for any networkmanager command.

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 >> ?

Last edited by Xiloba; 03-01-2020 at 09:05 PM.
 
Old 03-01-2020, 09:19 PM   #4
bassmadrigal
LQ Guru
 
Registered: Nov 2003
Location: West Jordan, UT, USA
Distribution: Slackware
Posts: 8,792

Rep: Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656Reputation: 6656
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.

Code:
wpa_supplicant -Dnl80211 -iwlan0 -B -c/etc/wpa_supplicant-1.conf
dhcpcd wlan0
# or
wpa_supplicant -Dnl80211 -iwlan0 -B -c/etc/wpa_supplicant-2.conf
dhcpcd wlan0
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.

Code:
iwconfig wlan0 essid $SSID_NAME
wpa_supplicant -Dnl80211 -iwlan0 -B -c/etc/wpa_supplicant.conf
dhcpcd wlan0
 
1 members found this post helpful.
Old 03-01-2020, 09:27 PM   #5
Xiloba
LQ Newbie
 
Registered: Feb 2020
Location: Brazil
Distribution: Slackware
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by bassmadrigal View Post
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.

Code:
wpa_supplicant -Dnl80211 -iwlan0 -B -c/etc/wpa_supplicant-1.conf
dhcpcd wlan0
# or
wpa_supplicant -Dnl80211 -iwlan0 -B -c/etc/wpa_supplicant-2.conf
dhcpcd wlan0
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.

Code:
iwconfig wlan0 essid $SSID_NAME
wpa_supplicant -Dnl80211 -iwlan0 -B -c/etc/wpa_supplicant.conf
dhcpcd wlan0
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
 
Old 03-01-2020, 10:15 PM   #6
Zexuo
Member
 
Registered: Mar 2015
Location: Florida
Distribution: Slackware
Posts: 64

Rep: Reputation: Disabled
Show networks configured in wpa_supplicant.conf:
Code:
wpa_cli -i $IFNAME list_networks
Select a network by its number in the output from the previous command:
Code:
wpa_cli -i $IFNAME select_network $NETWORK_NUMBER
 
4 members found this post helpful.
Old 03-02-2020, 03:15 AM   #7
Xiloba
LQ Newbie
 
Registered: Feb 2020
Location: Brazil
Distribution: Slackware
Posts: 12

Original Poster
Rep: Reputation: Disabled
Thanks, Zexuo.
I will try it.
 
Old 03-02-2020, 04:32 AM   #8
RedBlueYellow12
LQ Newbie
 
Registered: Aug 2019
Location: Melbourne, Australia
Distribution: Slackware
Posts: 27

Rep: Reputation: Disabled
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.
 
2 members found this post helpful.
Old 03-02-2020, 06:12 AM   #9
kikinovak
MLED Founder
 
Registered: Jun 2011
Location: Montpezat (South France)
Distribution: CentOS, OpenSUSE
Posts: 3,453

Rep: Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154Reputation: 2154
Quote:
Originally Posted by Xiloba View Post
Thanks, Bro.

Im not looking for any networkmanager command.

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.

Cheers,

Niki
 
2 members found this post helpful.
Old 03-02-2020, 06:43 AM   #10
Zexuo
Member
 
Registered: Mar 2015
Location: Florida
Distribution: Slackware
Posts: 64

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 03-02-2020, 08:19 AM   #11
BW-userx
LQ Guru
 
Registered: Sep 2013
Location: Somewhere in my head.
Distribution: Slackware (15 current), Slack15, Ubuntu studio, MX Linux, FreeBSD 13.1, WIn10
Posts: 10,342

Rep: Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242Reputation: 2242
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.
 
Old 03-02-2020, 09:59 AM   #12
Zexuo
Member
 
Registered: Mar 2015
Location: Florida
Distribution: Slackware
Posts: 64

Rep: Reputation: Disabled
Quote:
Originally Posted by BW-userx View Post
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.
 
2 members found this post helpful.
Old 03-02-2020, 02:42 PM   #13
Xiloba
LQ Newbie
 
Registered: Feb 2020
Location: Brazil
Distribution: Slackware
Posts: 12

Original Poster
Rep: Reputation: Disabled
I followed the steps below:


1- # chmod -x /etc/rc.d/rc.networkmanager
2-# wpa_passphrase my first ssid mypassword > /etc/wpa_supplicant.conf
3 # wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf -B -D nl80211
4 # dhclient wlan0

After,

5- wpa_passphrase my second ssid mypassword >> /etc/wpa_supplicant.conf


and type priority level in /etc/wpa_supplicant

network={
ssid="PACIFIC3"
psk=57971f5bdc8cda883b36e5be727e7c16b34551c794d0faefa7b661e2c01d841a
priority=5
}
network={
ssid="HOUSE"
psk=e04d199d71bb240e91afd82e799abfcab0c2c08e2198c6ddfa3c5f3db07dc8b6
priority=4
}

Last edited by Xiloba; 03-02-2020 at 03:14 PM.
 
1 members found this post helpful.
Old 03-02-2020, 02:43 PM   #14
Xiloba
LQ Newbie
 
Registered: Feb 2020
Location: Brazil
Distribution: Slackware
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by RedBlueYellow12 View Post
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.
Thanks, RedBlueYellow12.
 
Old 03-02-2020, 02:46 PM   #15
Xiloba
LQ Newbie
 
Registered: Feb 2020
Location: Brazil
Distribution: Slackware
Posts: 12

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by Zexuo View Post
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.
Thanks, for your advise, Zexuo.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] text manipulating ... the more efficient way to grab a string socalheel Programming 21 11-02-2013 02:31 PM
[SOLVED] C++ more efficient way. Int to Char array? Thesniperofdeath Programming 5 03-27-2011 01:56 PM
More efficient way to obtain process-related information: ps or /proc ? Black_Light Programming 5 12-06-2009 03:22 PM
PHP: more efficient (if else vs switch) Zeno McDohl Programming 12 12-17-2008 05:18 PM
Efficient way to read only 1st line from number of files anurade Other *NIX 2 03-31-2008 10:55 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 08:07 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration