All commands that should be used to connect to wifi in command line
Solution 1
I recommend using wpa_supplicant for all connection and AP association procedures. Though the name suggests usage with WPA, it actually is a universal tool for configuring any type of wireless connection.
Here's a complete procedure of connecting to a wireless network, using wpa_supplicant
(I assume wlan0
is the name of your wireless device) :
Bring the device up:
ifconfig wlan0 up
.List the wireless networks with
iwlist wlan0 scan | less
and find the network you want to connect to.-
Use
wpa_supplicant
to associate and connect with the network.a) Create a config file for
wpa_supplicant
, containing encryption information about the network. Seeman wpa_supplicant.conf
for examples. Try with simplest entries first.b) Run
wpa_supplicant -Dwext -iwlan0 -c/etc/wpa_supplicant.conf
(as root; assuming/etc/wpa_supplicant.conf
is the name of the config file). If it works, run it in the background and redirect the output somewhere (I just dump it to/dev/null
.) Use
dhclient wlan0
ordhcpcd wlan0
to obtain IP.PROFIT!
Solution 2
Looks like maybe you're not setting the channel and "mode". I use a simple script that does these shell commands:
ifconfig wlan0 down
iwconfig wlan0 mode managed
ifconfig wlan0 up
iwconfig wlan0 channel 3
iwconfig wlan0 key xxxxxxxxxx
iwconfig wlan0 key restricted
iwconfig wlan0 essid "Blah Blah Foo Bar"
iwconfig wlan0 ap xx:yy:zz:aa:bb:cc
sleep 5
dhcpcd -d wlan0
You have to put in your key, and access point MAC address. This is under Slackware 13.1, and I'm using a WRT54GL running DD-WRT. Much to my shame, I'm using WEP encryption. I had to do some experimenting about when to "ifconfig" and wlen to "iwconfig" and in what order to set ESSID and AP.
Solution 3
Would you please tell us which kind of encryption you use on your router?
You can also try wicd, it's a great connectivity tool and it can work with ncurses interface or gtk (not gnome) frontend. You only run it once, establish a connection, tell wicd to remember it and add wicd daemon to your startup scripts. After that you can just forget about your connection and not run a frontend for months - it will just work. I used it with different distributions and different desktop environments (or standalone WMs) and I'm very happy with it.
Solution 4
To get better clues, before you run dhclient
, run iwconfig
with no arguments. That will display the current wireless status, showing whether you are properly associated with the access point.
If you see Xephyr made a difference, see whether iwconfig
reveals that difference. And if still stuck, post your iwconfig results, which should look like http://en.wikipedia.org/wiki/Wireless_tools_for_Linux#iwconfig
Related videos on Youtube
MARTIN Damien
Updated on September 17, 2022Comments
-
MARTIN Damien over 1 year
I would like to switch from gnome to awesome and I would like to connect my wifi network in command line (instead of using gnome tools).
So, I searched on the internet and found approximatively the same methods :
ifconfig wlan0 up iwconfig wlan0 essid "MyNetwork" key THEHEXAKEY dhclient wlan0
When I run awesome alone and execute those commands, I'm tucked at the 3rd one. It looks like DHCP cannot be resolve (the command continue running endlessly).
But when I run awesome in Xephyr and execute the same commands,
dhclient wlan0
works well.So I suppose Gnome do something that I don"t but I can't find what.
Could someone help me ?
-
Eli Heady about 13 yearsAre you sure that you have successfully authenticated and associated with the AP after your iwconfig invocation? You might try manually setting an IP and route to verify that you can send/recieve on wlan0
-
Gilles 'SO- stop being evil' about 13 yearsYou can keep using Network Manager, even if you don't use Gnome. You can run
nm-applet
in any number of panels. I'm normally a command-line, do-it-myself person, but for networking on a laptop I gave up on doing things manually because Network Manager Just Works on most wifi networks. -
MARTIN Damien about 13 years@Gilles nm-applet is a pretty good solution for the moment. I will wait to configure completly awesome (I saw there is network indicator applets to). Thank you very much.
-
Eli Heady about 13 yearsYou can also use wpa_supplicant, rather than using iwconfig directy - very handy for encrypted networks. If you do continue to use a manual method of any sort, be sure to stop Network Manager services to save yourself some grief.
-
-
MARTIN Damien about 13 yearsIs
iwconfig wlan0 ap xx:yy:zz:aa:bb:cc
The content of 'Cell 01 - Address: 00:19:70:4A:64:ED' when I doiwlist scan
? -
Eli Heady about 13 yearsYes, the address listed in the block that also lists your ESSID is your AP's MAC address. This isn't required, but it is good practice if you have only one AP.
-
MARTIN Damien almost 13 yearsYour proposition sounds great, I'll try it. Thank you very much.