Configure WiFi on an Ubuntu Server

Ok, I know you’re wondering why I would ever want to setup WiFi on a server. Well, this was a small server to do some light work and I had a mini pc that had a builtin WiFi card that I used and since it had the option I figured I’d use the convenience rather than having to run another cable.

Note:
* You must be hard wired into your network to get this done; however, if you know the settings you will use off hand, or if you can grab the info off another machine, you can do it directly in the server shell.
* This should work in other Linux systems as well but I have not tested. If you use it on another system and it works, please leave a comment and let us know where it works.
* The items in orange are what you will need to gather for this setup.
* If your adapter is not configured, please do so before proceeding; that is a process too involved for this post so please look that up for your Distro.

First you have to make sure that that card is showing up (if not you will have to configure it) by running ifconfig -a, you should get output like this

wlan0     Link encap:Ethernet  HWaddr E3:E3:E3:E3:E3:E3
          inet6 addr: 0E1F::0E1F:0E1F:0E1F:0E1F/64 Scope:Link
          UP BROADCAST RUNNING NOARP  MTU:1500  Metric:1
          RX packets:25 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3100 (3.0 KiB)  TX bytes:3796 (3.7 KiB)

Note:
The name of the WiFi adapter (wlan0) may be different for you.

To get your gateway run route -n, which should output:

Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
0.0.0.0         192.168.1.1     0.0.0.0         UG    0      0        0 eth0
192.168.1.0     0.0.0.0         255.255.255.0   U     0      0        0 eth0

Configure the interface

Open /etc/network/interfaces and change your WiFi setting to mimic this, using the info from above of course:

For Static

auto wlan0
iface wlan0 inet static
address 192.168.1.38
netmask 255.255.255.0
gateway 192.168.1.1
wpa-ssid accesspoint_name
wpa-psk wpa_key

For DHCP

auto wlan0
iface wlan0 inet dhcp
wpa-ssid accesspoint_name
wpa-psk wpa_key

Getting it all set

Once you have the configs set, run the following command:

sudo ifdown wlan0 && sudo ifup -v wlan0

If it works you should see output like this:

Killed old client process
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/E3:E3:E3:E3:E3:E3
Sending on   LPF/wlan0/E3:E3:E3:E3:E3:E3
Sending on   Socket/fallback
DHCPRELEASE on wlan0 to 192.168.1.1 port 67 (xid=0x425cbf89)
Configuring interface wlan0=wlan0 (inet)
run-parts --exit-on-error --verbose /etc/network/if-pre-up.d
run-parts: executing /etc/network/if-pre-up.d/ethtool
run-parts: executing /etc/network/if-pre-up.d/wireless-tools
run-parts: executing /etc/network/if-pre-up.d/wpasupplicant
wpa_supplicant: wpa-driver nl80211,wext (default)
wpa_supplicant: /sbin/wpa_supplicant -s -B -P /run/wpa_supplicant.wlan0.pid -i wlan0 -D nl80211,wext -C /run/wpa_supplicant
Starting /sbin/wpa_supplicant...
wpa_supplicant: creating sendsigs omission pidfile: /run/sendsigs.omit.d/wpasupplicant.wpa_supplicant.wlan0.pid
wpa_supplicant: ctrl_interface socket located at /run/wpa_supplicant/wlan0
wpa_supplicant: configuring network block -- 0
wpa_supplicant: wpa-ssid "[accesspoint_name]" -- OK
wpa_supplicant: wpa-psk ***** -- OK
wpa_supplicant: enabling network block 0 -- OK

dhclient -1 -v -pf /run/dhclient.wlan0.pid -lf /var/lib/dhcp/dhclient.wlan0.leases wlan0    
Internet Systems Consortium DHCP Client 4.3.1
Copyright 2004-2014 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/wlan0/E3:E3:E3:E3:E3:E3
Sending on   LPF/wlan0/E3:E3:E3:E3:E3:E3
Sending on   Socket/fallback
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 3 (xid=0x3c29562d)
DHCPDISCOVER on wlan0 to 255.255.255.255 port 67 interval 8 (xid=0x3c29562d)
DHCPREQUEST of 192.168.1.38 on wlan0 to 255.255.255.255 port 67 (xid=0x5daeeb47)
DHCPOFFER of 192.168.1.38 from 192.168.1.1
DHCPACK of 192.168.1.38 from 192.168.1.1
bound to 192.168.1.38 -- renewal in 32551 seconds.
run-parts --exit-on-error --verbose /etc/network/if-up.d
run-parts: executing /etc/network/if-up.d/000resolvconf
run-parts: executing /etc/network/if-up.d/ethtool
run-parts: executing /etc/network/if-up.d/ntpdate
run-parts: executing /etc/network/if-up.d/openssh-server
run-parts: executing /etc/network/if-up.d/upstart
run-parts: executing /etc/network/if-up.d/wpasupplicant

Checking the outcome

Once all is done you will want to make sure you are getting an IP, to do that run the following command:

 ifconfig -a

You should see the following output for the WiFi connection:

wlan0     Link encap:Ethernet  HWaddr E3:E3:E3:E3:E3:E3  
          inet addr:192.168.1.38  Bcast:10.224.24.255  Mask:255.255.255.0
          inet6 addr: 0E1F::0E1F:0E1F:0E1F:0E1F/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:764 errors:0 dropped:0 overruns:0 frame:0
          TX packets:39 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:148460 (148.4 KB)  TX bytes:5416 (5.4 KB)

Note:
Don’t worry if you don’t have inet6 addr lines. Those are IPv6 related and you may or may not have those.
Advertisements

2 thoughts on “Configure WiFi on an Ubuntu Server”

Share your thoughts

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s