Using My PC as a Temporary Wifi Access Point

Last weekend there was an electrical storm which took out my wireless access point. My Ubuntu desktop PC is wired and also has a wireless card, so today I set my mind to a temporary wifi solution until I get a new AP.

The Basic Setup

In order to use my wireless card in master mode (that is, as an access point), I needed to use hostapd. In order to bridge the wireless interface to the LAN, I needed to install bridge-utils. Both of those things are in the Ubuntu repositories:

$ sudo apt-get install hostapd bridge-utils

My hostapd config file looks like this (with the SSID and passphrase not included):

interface=wlan0
driver=nl80211
ssid=[MySSID]
hw_mode=g
channel=11
wpa=1
wpa_passphrase=[MyPassphrase]
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
wpa_ptk_rekey=600
bridge=br0

For this to work though, the interface  br0  needs to be set up. You can set this up in /etc/network/interfaces, but since this is a short-term fix, I chose to just do it manually from a script.

# Add bridge interface and add eth0 to it.
brctl addbr br0
brctl addif br0 eth0

# Start the wireless gateway
hostapd hostapd.wlan0.conf

The Catch

The setup above made the wireless work fine for me, but it meant that my desktop couldn’t access the network itself. After much hunting around, I figured out that I had to remove the IP addresses and routes from  eth0  and add them to  br0  for this to work. This article that pointed me in the right direction.

My final script is:

#!/bin/bash

# Add bridge interface and add eth0 to it.
brctl addbr br0
brctl addif br0 eth0

# Remove IP address from eth0, add a static one to br0
ip addr flush dev eth0
ip addr add 192.168.1.188/19 dev br0

# Bring the interface up and set the gateway.
ifconfig br0 up
ip route add default via 192.168.0.254

# Start the wireless gateway
hostapd hostapd.wlan0.conf

Now as long as my desktop is switched on and running this script, I have WiFi access to my network.

 

This entry was posted in midlength and tagged , , , . Bookmark the permalink.

Comments are closed.