I'm setting up a headless server, but I don't have ethernet access where I want to put it, so I need it to automatically connect to my WiFi network when it boots up (it has a wireless card). I can connect to an ethernet connection to set it up, but I need it to automatically connect to my access point from then on.
How can I configure this?
Best Answer
After doing a lot of research I've gotten it working. Since I have an Intel wireless card I didn't have to install any extra drivers, but you might have to, depending on the card you have.
First you need to figure out what interface your wireless card is using. We use the
iwconfig
command for this:In my case my wireless card is the
wlan0
interface, so I will be using that. Now we need to scan for wireless networks:This should give lots of output, showing the details of the various wireless networks in your area. It's usually easier to filter by ESSID.
grep
helps us out here:This will list the names of all the wireless networks in your area. Now it's time to connect to your network.
Unsecure and WEP networks
If your network is unsecured or is secured by the older WEP (time to upgrade your security or router!) connecting is relatively simple. If your network is unsecured you should be able to connect with this:
If your network is WEP protected just add the
key
argument followed by your password, like this:You might have to run
To get your router to assign you an IP address.
WPA/WPA2
WPA/WPA2 is a bit more complicated. You will need to use
wpa_supplicant
. First create the config file in/etc
:Now we need to connect:
For example:
-B
runswpa_supplicant
in the background. Thewext
driver should work in most cases. To see other drivers run:For more information on getting connected see How to connect and disconnect to a network manually in terminal?
Get connected on startup
Now we need to edit
/etc/network/interfaces
. Open it in your favorite editor (vim
,nano
, etc); you'll need to usesudo
.Remove everything except:
(the loopback device). Now add:
Where
wlan0
is your wireless interface and<COMMAND>
is the command you use to connect to your network (see above). For example if you're network is unsecured you would add:If your network is secured with WPA/2 you would add something like this:
If you're using
wpa_supplicant
you should also add:Save the file, restart, unplug your ethernet and try running:
If the command completes successfully congratulations! You're online! If the command does not complete successfully please add a comment below.
Examples and Explanations
If your network is unsecured or secured with WEP your
/etc/network/interfaces
should look similar to this now:If your network is WPA/2 secured your
/etc/network/interfaces
should look similar to this:Now an explanation.
auto wlan0
: Starts thewlan0
interface automatically.iface wlan0 inet dhcp
: Gets us an IP address through DHCPpre-up
: Specifies the command(s) to get the connection going.post-down
: Specifies the command(s) to be used to clean up after ourselves (if necessary).Sources:
http://www.squaregoldfish.co.uk/2010/03/11/a-wireless-headless-linux-box/
How to connect and disconnect to a network manually in terminal?
Personal experience and lots of tinkering.