LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Connecting to a wireless network from command-line (https://www.linuxquestions.org/questions/linux-newbie-8/connecting-to-a-wireless-network-from-command-line-766819/)

Daravon 11-04-2009 09:39 AM

Connecting to a wireless network from command-line
 
I run Ubuntu, and it has a nice GUI widget thing that connects me to my home wireless network when I boot. I don't have a problem with that. But suppose I don't start X, and boot to a recovery console for some reason, like I did recently when my graphics were broken after installing Karmic. In that case, my computer won't be connected to the wireless network until I log into X normally. So I can't apt-get anything or anything. It's very annoying. And I don't know how to connect to my wireless network.

I know my wireless network SSID, and I know my WEP key or WPA passphrase. How can I log onto the network with commandline tools? Is there some basic program that I can just run "networkmanager <myssid> <mywepkey>"? I looked at the iwconfig man page and I honestly couldn't figure out how to simply connect to my network.

Once I figure out how to connect to the network with command-line tools, where can I put an "autoconnect" script so that it will connect during startup, like it should anyway?

What I don't understand is, why the Ubuntu network manager nm-applet, doesn't just work as a front-end for more basic networking stuff. I don't see any reason why it should require you to start X before working; it could be a daemon that runs at startup, and there could be a config-file somewhere, but it doesn't even start running until I log onto gnome.

tredegar 11-04-2009 10:27 AM

nm-applet is rubbish (the last time I looked) try uninstalling it and using wicd instead.

Otherwise, it is just a matter of editing your /etc/network/interfaces file to bring up the interface(s) you want at boot time. There are lots of HOWTOs on the net.

My wireless / wired just comes up at boot, and is ready to use as soon as I am logged on. I only use wicd if I am "roaming".

Come back with details of your interfaces file if you get stuck.

Myiagros 11-04-2009 12:59 PM

When I first switched to Ubuntu I was using the wireless manager that came with it which didn't really do a good job. Switched to wicd though and now it works great, no issues at all with it.

schneidz 11-04-2009 01:26 PM

you would want wireless-tools

iwconfig
iwlist wlan0 scan
iwconfig wlan0 essid <my-router>
dhclient

onebuck 11-04-2009 01:41 PM

Hi,

I setup a script for just that;

Code:

cat wlan.sh
#!/bin/bash
#
#10-26-09 13:30 gws
#setup the wlan0 device
#
/sbin/ifconfig wlan0 192.168.1.18
/sbin/route add default gw 192.168.1.1
/sbin/iwconfig wlan0 essid "Your_wireless_ap" <<-- AP essid
/sbin/iwconfig wlan0 key "Your_key_here"      <<-Your Key
/sbin/iwconfig wlan0 ap 00:00:00:00:00:00    <<-Your ap

You can just copy the above an save into 'wlan.sh'. Be sure to setup the 'essid', 'key' & 'ap'. Then do a 'chmod +x wlan.sh'. Once you have it saved and proper permissions then just do;

Code:

~#./wlan.sh'
Handy whenever you need to control the device for times like your experiencing.

:hattip:

evo2 11-04-2009 08:50 PM

Simple example of /etc/network/interaces for wireless device called wlan0 and access point using WEP encryption.

Code:

auto lo
iface lo inet loopback

auto wlan0
iface wlan0 inet dhcp
      #wireless_key s:asciikey  # Start with the "s:" if the key is ascii
      wireless_key D05C0B1234  #
      wireless_essid Foobar
      wireless_mode managed

The line "auto wlan0" will ensure mean that the interace will come up automatically at boot.
You can manually bring it down with

Code:

ifup wlan0
and down with
Code:

ifdown wlan0
NB. This is the way it's done in Debian, and therefore I assume Ubuntu.

HTH,

Evo2.

exvor 11-04-2009 09:39 PM

Code:

/sbin/iwconfig wlan0 ap 00:00:00:00:00:00    <<-Your ap
You know I have never had to do this. I have always just put in channel, key, and essid stuff. I wonder if its needed when your in a multi AP environment?

evo2 11-04-2009 09:47 PM

Quote:

Originally Posted by exvor (Post 3745155)
Code:

/sbin/iwconfig wlan0 ap 00:00:00:00:00:00    <<-Your ap
You know I have never had to do this. I have always just put in channel, key, and essid stuff. I wonder if its needed when your in a multi AP environment?

I've used this before when working in an office where a number or people were running their own wireless routers. However, in my case I put it in my /etc/network/interfaces in the form of:

Code:

wireless_ap 00:00:00:00:00:00
Cheers,

Evo2.

onebuck 11-05-2009 07:12 AM

Hi,

Quote:

Originally Posted by exvor (Post 3745155)
Code:

/sbin/iwconfig wlan0 ap 00:00:00:00:00:00    <<-Your ap
You know I have never had to do this. I have always just put in channel, key, and essid stuff. I wonder if its needed when your in a multi AP environment?

If your environment has multiple access points and signal quality variants then the above is the way to dictate the 'ap' to be used;

Quote:

excerpt from 'man iwconfig';

ap Force the card to register to the Access Point given by the address, if it is possible.
This address is the cell identity of the Access Point, as reported by wireless scanning,
which may be different from its network MAC address. If the wireless link is point to
point, set the address of the other end of the link. If the link is ad-hoc, set the cell
identity of the ad-hoc network.
When the quality of the connection goes too low, the driver may revert back to automatic
mode (the card selects the best Access Point in range).
You may also use off to re-enable automatic mode without changing the current Access
Point, or you may use any or auto to force the card to reassociate with the currently best
Access Point.
Example :
iwconfig eth0 ap 00:60:1D:01:23:45
iwconfig eth0 ap any
iwconfig eth0 ap off

:hattip:

Daravon 11-05-2009 10:57 AM

Thanks for all the advice. I'm not sure I understand every command but I will try to setup a file. What I don't understand is why the network manager applet doesn't just create this file for you. There are many gui tools that simply edit config files or run simple bash scripts.


Quote:

~#/wlan.sh'
I don't understand this syntax. What is ~/# and what is the ' after it?

tredegar 11-05-2009 11:08 AM

Quote:

I don't understand is why the network manager applet doesn't just create this file for you. There are many gui tools that simply edit config files or run simple bash scripts.
MN is one of theose GUI tools that edits the config files. But it does it really really badly.

wicd however, "just works", (so long as MN hasn't completely messed up the interfaces file) :)

As does editing your interfaces file yourself (my preferred method). 90 seconds (and I type slowly compared to many) and the problem is solved.

speel 11-05-2009 11:13 AM

Quote:

Originally Posted by onebuck (Post 3744634)
Hi,

I setup a script for just that;

Code:

cat wlan.sh
#!/bin/bash
#
#10-26-09 13:30 gws
#setup the wlan0 device
#
/sbin/ifconfig wlan0 192.168.1.18
/sbin/route add default gw 192.168.1.1
/sbin/iwconfig wlan0 essid "Your_wireless_ap" <<-- AP essid
/sbin/iwconfig wlan0 key "Your_key_here"      <<-Your Key
/sbin/iwconfig wlan0 ap 00:00:00:00:00:00    <<-Your ap

You can just copy the above an save into 'wlan.sh'. Be sure to setup the 'essid', 'key' & 'ap'. Then do a 'chmod +x wlan.sh'. Once you have it saved and proper permissions then just do;

Code:

~#/wlan.sh'
Handy whenever you need to control the device for times like your experiencing.

:hattip:

made it a little more user friendly

#!/bin/bash
#
#10-26-09 13:30 gws
#setup the wlan0 device
#

read -p "Wireless SSID:" ssid
read -p "Wepkey:" wep_key
read -p "AP( 00:00:00:00:00:00 ):" ap

/sbin/ifconfig wlan0 192.168.1.18
/sbin/route add default gw 192.168.1.1
/sbin/iwconfig wlan0 essid $ssid
/sbin/iwconfig wlan0 key $wep_key
/sbin/iwconfig wlan0 ap $ap

tredegar 11-05-2009 11:16 AM

Oops, missed this bit:
Quote:

I don't understand this syntax. What is ~/# and what is the ' after it?
~ means "home" in this case root's home which is the directory /root

What he means is "as root ...

(a root shell has a prompt of "#" - try it now, open terminal sudo -i give your password when prompted, you are root, check the bash prompt has changed. exit or close terminal)

... give the command ./wlan.sh

The ./ means the file is in the current directory and wlan.sh is the script to be run.

HTH

Hangdog42 11-05-2009 12:09 PM

I would like to point out that wicd now has a console based client, wicd-curses. Works great.

onebuck 11-05-2009 08:26 PM

Hi,

Quote:

Originally Posted by Hangdog42 (Post 3745943)
I would like to point out that wicd now has a console based client, wicd-curses. Works great.

In the past few weeks I've had a few problems with 'wicd 1.6.2.2'. I exclusively used the 'wicd-curses', one day I could not get a known (recognized) ap or any for that matter. I jumped through hoops to get it going. I had to removepkg then installpkg again. I even removed the stale files left behind from the previous install. It worked for a while but then lost everything again. I removed it for now. I don't move this machine and don't need the hassle. I can manually setup without a problem. I think the 'wicd-curses' was available for 1.6.2.1.

:hattip:


All times are GMT -5. The time now is 06:21 PM.