WiFi Configuration On Ubuntu Workstation/Server

802.11g Wireless Networking

A recent change of office required some wireless networking, involving installation of TP-Link TL-WN321G USB dongles on an Ubuntu Linux 9.10 workstation, 8.04 server and a couple of Windows XP workstations. This article summarises getting the device to work on an Ubuntu Linux system.

I broadly followed the (out-of-date) Ubuntu Community Documentation Wifi How To, with a few tips from elsewhere, and a recollection that it’s sometimes better to be without Gnome’s Network Manager.

Kernel Driver Support

After plugging in the dongle, `lsusb` gave the following (snipped)

$ lsusb
 Bus 002 Device 001: ID 1d6b:0001 Linux Foundation 1.1 root hub
 Bus 001 Device 002: ID 148f:2573 Ralink Technology, Corp. RT2501USB Wireless Adapter

The second line of output gives the vendor (148f) and product (2573)
identifiers for the device. Checking a Linux wireless adapter chipset directory showed that supporting kernel drivers exist for this device’s chipset.

Listing the currently loaded kernel drivers showed that both the rt73usb and rt2500usb drivers had been automatically loaded:

$ lsmod
 Module Size Used by
 rt73usb 26336 0
 rt2500usb xxxxx 0

Seeing that two drivers had been loaded I chose to blacklist one of them – the rt2500usb. For that I created a new, custom blacklist file in the /etc/modprobe/ directory, avoiding editing any existing blacklist file that my distribution had created. I chose to create the file /etc/modprobe/blacklist-custom.conf:

$ cat /etc/modprobe.d/blacklist-custom.conf
 blacklist rt2500usb

The rt2500usb driver may work, though I haven’t tested it.

Gnome Network Manager Problems

The Ubuntu workstation default setup makes use of Gnome Network Manager to manage wired and wireless network connectivity. Inspecting the kernel message log showed that although the wireless interface was being activated, it was then very quickly deactivating:

$ dmesg
 [ xxxx.xxxxxx] rt73usb 1-2:1.0: firmware: requesting rt73.bin
 [ xxxx.xxxxxx] ADDRCONF(NETDEV_UP): wlan2: link is not ready
 [ xxxx.xxxxxx] wlan2: authenticate with AP xx:xx:xx:xx:xx:xx
 [ xxxx.xxxxxx] wlan2: authenticated
 [ xxxx.xxxxxx] wlan2: deauthenticating by local choice (reason=3)

Suspecting that Network Manager may be trying to maintain a wired-only connection and knowing the workstation doesn’t move anywhere, I decided to dispense with the network-manager package altogether:

$ sudo apt-get remove network-manager

Network Interface Configuration

In order to test the connection with my WAP I first disabled authentication and encryption on the WAP through its configuration interface. Here’s the simple configuration details for the USB dongle in the workstation’s /etc/network/interfaces file:

auto lo
    iface lo inet loopback

auto wlan2
    iface wlan2 inet static
    # Wireless config
    wireless-essid myssid
    wireless-channel 1
    wireless-mode managed

Using iwconfig I could see that the USB dongle was connecting to the WAP.

Now that we know that we can connect to the wireless access point, we can protect our communication. I’m using WPA2 to connect to and encrypt the communication channel to my WAP. Here’s the snipped /etc/network/interfaces:

auto lo
iface lo inet loopback

auto wlan2
iface wlan2 inet static
    # WPA2 config
    wpa-psk secretpasskey
    wpa-driver wext
    wpa-key-mgmt WPA-PSK
    wpa-proto WPA2
    wpa-ssid myssid
    pre-up sleep 5

WPA2 details can go straight into the interfaces file, though you may wish to externalise the WPA2 supplicant information into a separate file that is read-protected from anything but the root user and group.

A check of the network interfaces shows a working wlan network interface:

$ ifconfig
lo Link encap:Local Loopback
    inet addr: Mask:
    inet6 addr: ::1/128 Scope:Host
    UP LOOPBACK RUNNING MTU:16436 Metric:1
    RX packets:33 errors:0 dropped:0 overruns:0 frame:0
    TX packets:33 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:0
    RX bytes:1831 (1.8 KB) TX bytes:1831 (1.8 KB)


wlan2 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx
    inet addr: Bcast: Mask:
    inet6 addr: fe80::227:19ff:feb7:668a/64 Scope:Link
    RX packets:468550 errors:0 dropped:0 overruns:0 frame:0
    TX packets:398811 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:1000
    RX bytes:406451098 (406.4 MB) TX bytes:184734469 (184.7 MB)

Checking wireless connection information with iwconfig shows the wlan interface is connected:

$ iwconfig
lo no wireless extensions.


wmaster0 no wireless extensions.

wlan2 IEEE 802.11bg ESSID:"myssid"
    Mode:Managed Frequency:2.462 GHz Access Point: xx:xx:xx:xx:xx:xx
    Bit Rate=54 Mb/s Tx-Power=9 dBm
    Retry long limit:7 RTS thr:off Fragment thr:off
    Power Management:on
    Link Quality=38/70 Signal level=-72 dBm
    Rx invalid nwid:0 Rx invalid crypt:0 Rx invalid frag:0
    Tx excessive retries:0 Invalid misc:0 Missed beacon:0
Tags: ,

PHP Output to Syslog on Ubuntu

There are just a few things you need to know in order to output trace or error information to syslog on an Ubuntu system from PHP (the following is probably true for other Debian-based distributions, too).

  • Set error logging to syslog in php.ini (the system-wide php.ini can be found at /etc/php5/php.ini):
error_log = syslog
  • Restart Apache:
$ sudo /etc/init.d/apache2 restart

Use the error_log() function to output your error messages.

  • View the output of error messages:
$ tail -f /var/log/syslog

The -f flag causes new messages to be appended to the output of tail.

Tags: ,