A Raspberry Pi with a wireless dongle that supports Access Point mode is a very versatile tool. As well as connecting to existing wireless networks, the Raspberry Pi can become an access point and have multiple devices connected to it. It can either have its own network or bridge onto an existing one and make it wireless. One potential application of this is to create a wireless access point for guests, with appropriate firewalling rules to make sure they can’t connect to anything on your LAN. Another is simply connecting to it over wireless rather than Ethernet, which can be useful if the Ethernet port is already in use. For example, a Raspberry Pi acting as a portable PXE server (used to boot a computer over the network) would have an Ethernet cable connected to the computer it’s booting, but you might need to log in and see what’s going on at the same time.
Latest Raspbian Image
A router or switch
A USB wireless dongle that supportsAaccess Point mode
A Wi-Fi device to test with
Step 01 Install the required software
Log into the Raspbian system with the username pi and the password raspberry. Get the latest package lists using the command:
$ sudo apt-get update
We’ll be using hostapd, which is a daemon that handles access point management and authentication. We’ll also need bridge utils, which will be used to bridge the Ethernet and wireless interfaces together. iw is used to get information about the wireless interface, and dnsmasq is used as a DHCP server. Install these with:
$ sudo apt-get install hostapd bridge-utils iw dnsmasq
Step 02 Check for AP mode
It’s crucial that you have a wireless dongle that supports Access Point (AP) mode. To verify that, connect the wireless dongle and type iw list. There will be a section titled ‘Supported interface modes’. Ensure that AP mode is in that list. Our expert’s output looked like this:
Supported interface modes:
* managed *AP
* mesh point
Step 03 Bridge interfaces
We’ll bridge the Ethernet interface and the wireless interface so they can share the same IP address and traffic can pass between them. To do this, edit /etc/network/interfaces (using sudo) and change it to look as follows:
auto lo br0 iface lo inet loopback allow-hotplug eth0 iface eth0 inet manual allow-hotplug wlan0 iface wlan0 inet manual iface br0 inet dhcp bridge_ports eth0 wlan0 bridge_waitport 0
At the moment, we’ll be bridging onto an existing network, but we will set up our own later on. Reboot using sudo reboot so that the changes take effect.
Step 04 Configure hostapd
We first need to edit /etc/default/hostapd to start the daemon on boot. Uncomment the ‘DAEMON_CONF’ option and replace it with:
We then need to create the hostapd config file at the path specified above. It should have the following contents:
interface=wlan0 bridge=br0 driver=nl80211 country_code=UK ssid=pinet hw_mode=g channel=1 wpa=2 wpa_passphrase=super_secret wpa_key_mgmt=WPA-PSK ieee80211n=1 wmm_enabled=1
Note that if you don’t have a wireless N capable device, or are having stability issues, you’ll want to leave out the last two lines. You may also need to change the wireless channel if you are having stability issues. Once you’ve done this, you can start the hostapd daemon with sudo /etc/init.d/hostapd start.
Step 05 Connect to the network
The SSID in the config file is the network name, and the WPA Passphrase is the password. When you connect to the network, the connection will be bridged to the existing wired network and you should receive an IP address from your existing router doing DHCP. Congratulations on creating an access point!
Step 06 Create an independent network
We’re now going to change the network configuration to be independent from your existing network. The first thing to do is to pick a private address range that you’d like to use. For this example, we’ll use 192.168.0.0/24. However, we recommend using a random address range in case you ever want to route to other networks. The first thing we’ll do is assign a static address to the bridge interface. Change the bridge section of /etc/network/interfaces to look as follows:
iface br0 inet static bridge_ports eth0 wlan0 bridge_waitport 0 address 192.168.0.1 network 192.168.0.0 netmask 255.255.255.0
Step 07 Configure a DHCP server
We installed dnsmasq in the first step. Configuring it is really simple. Start by taking a copy of the default config:
$ sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
Then edit /etc/dnsmasq.conf to contain the following lines:
Reboot for the changes to take effect. You’ll want to disconnect the Raspberry Pi from your existing network at this point, otherwise there will be two DHCP servers on the network.
Step 08 Try it out
Devices on the wireless interface will be able to talk to devices on the wired interface, and any device plugged into the Pi will get an IP address so that it can talk to the other devices.