LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-04-2009, 10:39 AM   #1
Daravon
Member
 
Registered: Mar 2006
Posts: 170

Rep: Reputation: 15
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.
 
Old 11-04-2009, 11:27 AM   #2
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
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.
 
Old 11-04-2009, 01:59 PM   #3
Myiagros
Member
 
Registered: Mar 2009
Distribution: Ubuntu, CentOS 5.3
Posts: 75

Rep: Reputation: 18
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.
 
Old 11-04-2009, 02:26 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,051

Rep: Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852Reputation: 852
you would want wireless-tools

iwconfig
iwlist wlan0 scan
iwconfig wlan0 essid <my-router>
dhclient
 
Old 11-04-2009, 02:41 PM   #5
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,603
Blog Entries: 25

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


Last edited by onebuck; 11-05-2009 at 09:14 PM. Reason: correct syntax error
 
Old 11-04-2009, 09:50 PM   #6
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
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.
 
Old 11-04-2009, 10:39 PM   #7
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

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

Last edited by exvor; 11-04-2009 at 10:40 PM. Reason: puctuation
 
Old 11-04-2009, 10:47 PM   #8
evo2
LQ Guru
 
Registered: Jan 2009
Location: Japan
Distribution: Mostly Debian and Scientific Linux
Posts: 5,753

Rep: Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288Reputation: 1288
Quote:
Originally Posted by exvor View Post
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.
 
Old 11-05-2009, 08:12 AM   #9
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,603
Blog Entries: 25

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Hi,

Quote:
Originally Posted by exvor View Post
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
 
Old 11-05-2009, 11:57 AM   #10
Daravon
Member
 
Registered: Mar 2006
Posts: 170

Original Poster
Rep: Reputation: 15
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?
 
Old 11-05-2009, 12:08 PM   #11
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
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.
 
Old 11-05-2009, 12:13 PM   #12
speel
Member
 
Registered: Apr 2004
Location: queens , nyc
Distribution: Ubuntu MATE
Posts: 352

Rep: Reputation: 30
Quote:
Originally Posted by onebuck View Post
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.

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
 
Old 11-05-2009, 12:16 PM   #13
tredegar
LQ 5k Club
 
Registered: May 2003
Location: London, UK
Distribution: Debian "Jessie"
Posts: 6,085

Rep: Reputation: 398Reputation: 398Reputation: 398Reputation: 398
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
 
Old 11-05-2009, 01:09 PM   #14
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 416Reputation: 416Reputation: 416Reputation: 416Reputation: 416
I would like to point out that wicd now has a console based client, wicd-curses. Works great.
 
Old 11-05-2009, 09:26 PM   #15
onebuck
Moderator
 
Registered: Jan 2005
Location: Midwest USA, Central Illinois
Distribution: SlackwareŽ
Posts: 12,603
Blog Entries: 25

Rep: Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981Reputation: 1981
Hi,

Quote:
Originally Posted by Hangdog42 View Post
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.

 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Connecting PC to Wireless Network cochetopa Linux - Newbie 3 12-28-2008 11:37 AM
connecting to wireless network gibney Linux - Newbie 1 06-18-2007 05:00 AM
Connecting to Wireless Network Zephryos Linux - Software 3 01-28-2006 06:45 PM
Connecting via the command line jawq Linux - Newbie 2 06-16-2005 10:44 AM
Connecting to a wireless network death_au Linux - Newbie 3 03-06-2005 07:38 AM


All times are GMT -5. The time now is 08:30 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration