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:

shogun1234 12-04-2009 02:42 AM

I try this setting but the result of executing `ifup wlan0' shows
Code:

No DHCPOFFERS received.
No working leases in persistent database - sleeping.

The wirelss configuration in /etc/network/interfaces is

Code:

allow-hotplug wlan0
ifcae wlan- inet dhcp
wirelss_essid TEST
wirelss_key s:password

Is this the correct setting parameters for WEP? I `man wirelss', it seems this is the correct format for setting wirelss.

I am sure the network works well because I can use other pc (windows) to surf the internet.

Also, previously my laptop works well in another wireless which configures using wpa and it worked well without a problem.

What is the correct setting for WEP? Or where can I obtain the working sample for WEP setting?

Thanks for help.


Quote:

Originally Posted by evo2 (Post 3745121)
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.


evo2 12-04-2009 03:12 AM

Quote:

Originally Posted by shogun1234 (Post 3779368)
I try this setting but the result of executing `ifup wlan0' shows
Code:

No DHCPOFFERS received.
No working leases in persistent database - sleeping.


That is extremly strange. I should output much more than that, even if it does fail.

Quote:

The wirelss configuration in /etc/network/interfaces is

Code:

allow-hotplug wlan0
ifcae wlan- inet dhcp
wirelss_essid TEST
wirelss_key s:password

Is this the correct setting parameters for WEP? I `man wirelss', it seems this is the correct format for setting wirelss.
It depends if the typos above are only in your post and not in your interfaces file. If what is really in your interfaces file is as below, then it should work for wep.
Code:

allow-hotplug wlan0
iface wlan0 inet dhcp
wireless_essid TEST
wireless_key s:password

Quote:

Also, previously my laptop works well in another wireless which configures using wpa and it worked well without a problem.

What is the correct setting for WEP? Or where can I obtain the working sample for WEP setting?
I'm pretty sure that what I posted is correct. There must be some other problem.

From your original post it seems that you are able to use some gui tool to get your wireless working. If so can you please post the output of the following for two cases
Code:

sudo iwconfig
1. When the wireless is working: after bring it up with the gui
2. When it is not working: just after failing to bring it up on the command line.


Cheers,

Evo2.

JML 12-04-2009 03:13 AM

I'm not sure if you typed or copy/pasted your network configuration, but in almost every case of "wireless" you're missing an 'e'. Start by correcting that if you did just copy it.

Since this thread has already been resurrected, cnetworkmanager is another option for users who are already using Network Manager on their systems. It's a command line interface to network manager of course, and fairly simple to use. Ex. cnetworkmanager -C my_ssid --wpa-pass=mypass

imagine_me2 12-04-2009 08:13 AM

To: tredegar

<Quote>nm-applet is rubbish</Quote>

There are people who wrote nm-applet, and with a honest motive of helping the Linux users. I think they deserve a better comment than the above.

We may not like a thing but we can be gentle with our criticism. I said this not because i think you are wrong, but beacause of the way you said it.

Regards.

onebuck 12-04-2009 10:53 AM

Hi,

Quote:

Originally Posted by imagine_me2 (Post 3779686)
To: tredegar

<Quote>nm-applet is rubbish</Quote>

There are people who wrote nm-applet, and with a honest motive of helping the Linux users. I think they deserve a better comment than the above.

We may not like a thing but we can be gentle with our criticism. I said this not because i think you are wrong, but beacause of the way you said it.

Regards.

From your perspective!

'PC' is 'BS'!

If something is a piece of crap it deserves noted as such. You can rub or spin any way you want but if the feelings or skin of the software programmer is that thin then I suggest they get out.

When the kettle is Black, it can be hot too. Touching it will make you aware of one but not the other. :)

shogun1234 12-05-2009 05:52 PM

env: kernel 2.6.31/ gcc 4.3.4/ make 3.81/ debian unstable

I double check the related setting again. It looks correct to me, but I think there should have something missing and I am not aware of it. They are follow:

Firmware located at /lib/firmware contains
Code:

iwlwifi-4965-2.ucode
The result of lsmod | grep iwlagn
Code:

iwlagn 73340 0
iwlcore 95716 1 iwlagn
mac80211 124608 2 iwlagn, iwlcore
cfg80211 76636 3 iwlagn, iwlcore, mac80211
led_class 3868 3 iwlcore, hp_accel, sdhci

I can not find any kernel module with `lsmod | grep 4965`, which is the module detected in the past. I also read on the internet saying that iwl4965 is iwlagn in fact, as follow:
Code:

http://ubuntuforums.org/showthread.php?t=902652&page=2
http://article.gmane.org/gmane.linux.drivers.ipw3945.devel/3398

The syslog shows
Code:

iwlagn: Intel(R) Wireless Wifi Link AGN driver for Linux, 1.3.27ks
iwlagn: Copyright(c) 2003-2009 Intel Corporation
iwlagn: 0000:10:00.0: PCI INT A -> GSI 17 (level, low) -> IRQ 17
iwlagn: 0000:10:00.0: setting latency timer to 64
iwlagn: 0000:10:00.0: Detected Intel Wireless WiFi Link 4965AGN REV=0x4
...
iwlagn 0000:10:00.0: firmware: requesting iwlwifi-4965-2.ucode
iwlagn 0000:10:00.0: loaded firmware version 228.57.2.21
Registered led device: iwl-phy0::radio
Registered led device: iwl-phy0::assoc
Registered led device: iwl-phy0::RX
Registered led device: iwl-phy0::TX
ADDRCONF(NETDEV_UP): wlan0: link is not ready

It looks like the firmware is loaded, but I do not know why the link is not ready.

The iwconfig reault
Code:

wlan0 IEEEE 802.11abgn ESSID:"TEST"
      Mode:Managed Frequency:2.412 GHz Access Point: Not-Associated
      Tx-Power=15 dBm
      Retry long limit: 7 RTS thr:off Fragment thr:off
      Encryption key:off
      Power Management: off
      Link Quality:0 Signal level: 0 Noise level:0
      Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
      Tx execessive retries:0 Invalid misc: 0 Missed beacon:0

The interfaces configuration
Code:

allow-hotplug wlan0
iface wlan0 inet dhcp
wireless_essid TEST
wireless_key s:password

auto wlan0

Does these look correct?

Thanks for the help.

I appreciate it.


Quote:

Originally Posted by evo2 (Post 3779384)
That is extremly strange. I should output much more than that, even if it does fail.


It depends if the typos above are only in your post and not in your interfaces file. If what is really in your interfaces file is as below, then it should work for wep.
Code:

allow-hotplug wlan0
iface wlan0 inet dhcp
wireless_essid TEST
wireless_key s:password


I'm pretty sure that what I posted is correct. There must be some other problem.

From your original post it seems that you are able to use some gui tool to get your wireless working. If so can you please post the output of the following for two cases
Code:

sudo iwconfig
1. When the wireless is working: after bring it up with the gui
2. When it is not working: just after failing to bring it up on the command line.


Cheers,

Evo2.


evo2 12-06-2009 01:35 AM

To help you I need you to follow instructions.
From my last post:

Quote:

From your original post it seems that you are able to use some gui tool to get your wireless working. If so can you please post the output of the following for two cases
Code:

Code:

sudo iwconfig
1. When the wireless is working: after bring it up with the gui
2. When it is not working: just after failing to bring it up on the command line.
It seems you did one of the above, but not both. I need to compare the output in the two situations. It is also important that you run the command as root otherwise I will not be able to see it the key was set properly.

Quote:

The interfaces configuration
Code:
Code:

allow-hotplug wlan0
iface wlan0 inet dhcp
wireless_essid TEST
wireless_key s:password

auto wlan0


Please remove the line with "auto wlan0"

Evo2.


All times are GMT -5. The time now is 11:57 AM.