# How to do wifi conveniently from CLI?

## Punchcutter

Hi....  I've lately had very bad luck trying to find a convenient GUI tool to manage wifi connections (long story... closely related to KDE and its dumping of 3.5.x, but let's not go there....)  I need to take a business trip very soon, and use wifi on the road.  I'm quite sufficiently techie, however, and not afraid to use the command line to manage my wifi connections (using /etc/init.d/net.wlan0, ifconfig, wpa_supplicant command, etc). There are just a few things I don't know:

In a case where there may be multiple networks present, how can I ensure that the ESSID I want to use is the one chosen to attach to?

How can I easily check which ESSID I am connected to at any given time?

The tools I know about don't seem to offer this capability.  Is there another tool that deals at the ESSID level?  If not, this seems like an odd gap in functional coverage...

Thanks very much in advance for any help.  Any and all tips on best practices for managing wifi from CLI are most appreciated!

EDIT:

   Of course it's only as soon as you've posted something like this that you think to google and then find some useful info.  Googling reminded me of "iwconfig", which I had long forgotten about.  I see that you can "set" the essid with this.  But if I can get /etc/init.d/net.wlan0 to handle underlying details for me, including interfacing with wpa_supplicant, how would iwconfig fit into this scheme?  Or would I need to specify ESSIDs in /etc/conf.d/net? (don't know the syntax for that - if there's a man page for this file, I can't find it).

Too many questions.... and much info on the web is specific to non-Gentoo distros, so I suppose asking here will have been worthwhile in the long run.... thanks again.

----------

## mikegpitt

A well set up /etc/wpa_supplicant/wpa_supplicant.conf should handle most things for your automatically.  Others may recommend using wicd, but I don't have any experience with wicd.  I find the easiest way to configure wpa_supplicant is to use the wpa_gui tool.

As for controlling things through the command line, you can use iwconfig as you noted above.  You can also use wpa_cli.  The wpa_cli documentation is severely lacking, but I've been able to figure out the following:

```
# perform a scan and list the results

wpa_cli SCAN

wpa_cli SCAN_RESULTS

# disconnect from an ap

wpa_cli DISCONNECT

# connect to a new ap

wpa_cli SELECT_NETWORK myessid

wpa_cli REASSOCIATE

# get the status of your connection

wpa_cli STATUS
```

[/code]

----------

## DONAHUE

How can I easily check which ESSID I am connected to at any given time? -- iwconfig

what's available -- iwlist scan

In a case where there may be multiple networks present, how can I ensure that the ESSID I want to use is the one chosen to attach to? set ssid= in wpa-supplicant.conf

you don't have a wpa supplicant administration gui as a result of emerge wpa-supplicant?

----------

## poly_poly-man

if you want a gui back (or not - it's still, in the opinions of many networkmanager converts, a useful tool), use wicd.

----------

## Punchcutter

Thanks for all the great suggestions.  I had no idea that wpa_gui existed.  However I'm having some trouble.  The gui will show the successful connection if one was made elsewhere, but I can't get it to show anything on a scan, or to make a connection itself.  This is even when iwlist wlan0 scan will give scan output. I tried the wpa_cli commands above as well, but not with much success.  It often just comes back and tells me it can't connect to the supplicant (sorry don't have exact messages now!   :Embarassed:  )

One thing I've noticed is that the interface seems to go up and down by itself.  I had terrible trouble in the past when using my wired ethernet with wlan0 coming up and trying to make connections, stealing my DNS configuration, etc.  I thought it was networkmanager causing the trouble, so I unmerged it, but it didn't stop.  wlan0 was like some kind of demonic toy in a slasher movie... I had to keep crushing it down until it would finally leave me alone and let me use the wired port.  That was a while ago, but recently.

Now, as I say, I've got this weirdness where I can bring it up with ifconfig wlan0 up (or iwconfig wlan0 up?), and then try to scan and connect, but it just drops out from under me. I have no reason to think there's anything wrong with my kernel/drivers.  I have one network fully listed in wpa_supplicant.conf (at my workplace), and this one will connect up and stay up with no problem.

I realize this is all kinda fragmented and hard to make sense of.  For me too.  I'm hoping it'll ring bells for someone.  If not, I'll just have to keep trying over and over every trick in my book until I manage to make connections.  Leaving on my trip tomorrow....

(p.s. I have tried wicd, as a matter of fact, and it just didn't work for me.  Very unstable and more trouble than it was worth. I'll keep it in mind to try again in the future).

----------

## depontius

The button on the right on wpa_gui is "scan".  Press that and it'll pop up a new panel that shows you the networks it can find.  You can then pick one of those, click the "add" button and that network will get added to the main wpa_gui network pulldown.  (At this point you can close the scan panel, if you want.)  Meanwhile the main wpa_gui is cycling through its possible connections, and will eventually get to the one you added.  My wireless isn't active now, so I can't give you the whole works exactly, but from somewhere in these panels you can also configure the newly added network, in case you have a key or some such.

I normally keep networks set up in wpa_supplicant.conf for home, work, and Hilton hotels.  (My wife is quite fond of Hampton Inns, when we travel.)  Anything else, like an airport or other open wifi, I add ad-hoc through the gui.

----------

## mikegpitt

 *Punchcutter wrote:*   

> It often just comes back and tells me it can't connect to the supplicant (sorry don't have exact messages now!   )

 Is wpa_supplicant started?  You will need the following in your /etc/conf.d/net:

```
modules=( "wpa_supplicant" )

wpa_supplicant_wlan0="-Dwext"
```

...and then run the follow to start wpa_supplicant:

```
/etc/init.d/net.wlan0 restart
```

----------

## doctork

 *Punchcutter wrote:*   

> Thanks for all the great suggestions.  I had no idea that wpa_gui existed.  However I'm having some trouble.  The gui will show the successful connection if one was made elsewhere, but I can't get it to show anything on a scan, or to make a connection itself.  This is even when iwlist wlan0 scan will give scan output. I tried the wpa_cli commands above as well, but not with much success.  It often just comes back and tells me it can't connect 
> 
> o the supplicant (sorry don't have exact messages now!   )
> 
> .

 

wpa_cli and wpa_gui need to run as root or by a user in a group specified in wpa_supplicant.conf by a statement like:

```
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=wheel

```

As far as wireless stealing your wired connections, you can prevent that with a statement like this in /etc/conf.d/net:

```
dhcp_wlan0="nodns nontp nogateway nodomain"
```

--

doc

----------

