Setting up WiFi on Ubuntu 14.04 Server from the Terminal
Dec 27, 2014 · CommentsComputersLinux
I was setting up a server today and I didn’t have a wired ethernet drop available for it but I did have WiFi. So I decided to just setup WiFi for today and get it plugged into the network on Monday. I mean how hard could it be to set up wifi right?
I started with this article on the Ubuntu community help portal:
https://help.ubuntu.com/community/NetworkConfigurationCommandLine/Automatic#WPA_supplicant
I have to admit this got me most of the way, but for my machine there was a crucial piece of configuration missing. It turns out there are two driver options available for wifi cards, wext and nl80211. It took me far too many minutes hours of googling to discover this. Here was the page that explained it for me:
http://unix.stackexchange.com/questions/97828/driver-d-option-under-wpa-supplicant
After updating the driver, here is what my wpa.sh file looks like:
#!/bin/bash
### BEGIN INIT INFO
# Provides: wpa
# Required-Start: $network $syslog $local_fs
# Required-Stop: $network $syslog $local_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start/stop script for wpa supplicant
# Description: Custom start/stop script for wpa_supplicant.
### END INIT INFO
SELF=`basename $0`
WPA=wpa_supplicant
PROGRAM=/sbin/${WPA}
CONF=/etc/${WPA}.conf
INTERFACE=wlan0
DRIVER=nl80211
DAEMONMODE="-B"
LOGFILE=/var/log/$WPA.log
function start() {
# TODO: Support multiple interfaces and drivers
OPTIONS="-c $CONF -i $INTERFACE -D $DRIVER $DAEMONMODE"
## You can remove this if you are running 8.10 and up.
# Ubuntu 8.10 and up doesn't need the -w anymore..
# And the logfile option is not valid on 8.04 and lower
local ver=$(lsb_release -sr | sed -e 's/\.//g');
[ $ver -lt 810 ] && OPTIONS="$OPTIONS -w" && LOGFILE=""
##
# Log to a file
[ -n "$LOGFILE" ] && OPTIONS="$OPTIONS -f $LOGFILE"
echo " * Starting wpa supplicant"
eval $PROGRAM $OPTIONS
}
function stop() {
echo " * Stopping wpa supplicant"
pkill $PROGRAM
}
function debug() {
stop
DAEMONMODE="-ddd"
start
}
function restart() {
stop
start
}
function status() {
pgrep -lf $PROGRAM
}
function usage() {
echo "Usage: $SELF <start|stop|status|debug>"
return 2
}
case $1 in
start|stop|debug|status) $1 ;;
*) usage ;;
esac
That’s it. At least it was a Saturday so no one saw…