hostapd: Ubuntu server as a wireless access point

The first thing to do is find out whether your hardware is capable of running in master mode. The easiest way to check this is like so:

user@computer:$ sudo apt-get install iw
user@computer:$ iw list

Look through the output to find the Supported Interface Modes section:

...
Supported interface modes:
         * IBSS
         * managed
         * AP
         * AP/VLAN
         * monitor
         * mesh point
...

If, as in the example above, AP mode is listed, then congratulations you have everything you need! If not, all is not lost. Check out this guide to see how to test older hardware for master mode.

HostAPD

We’re going to use the hostapd service to manage our access point, the first thing to do is install, then configure it.

user@computer:$ sudo apt-get install hostapd
user@computer:$ sudo nano /etc/default/hostapd

This will install hostapd and present you with the default service configuration. We need to modify this file to start hostapd at boot and tell it where we’ll store the config file. Do this by editing the DAEMON_CONF line like so:

DAEMON_CONF="/etc/hostapd/hostapd.conf"

Now we need to create a config file at the location above:

user@computer:$ sudo nano /etc/hostapd/hostapd.conf

Paste the following into it:

ctrl_interface=/var/run/hostapd
###############################
# Basic Config
###############################
macaddr_acl=0
auth_algs=1
# Most modern wireless drivers in the kernel need driver=nl80211
driver=nl80211
##########################
# Local configuration...
##########################
interface=wlan0
bridge=br0
hw_mode=g
channel=1
ssid=danlan
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=3
wpa_passphrase=DONOTFORGETTOCHANGEME
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Most of the options above are fairly self-explantory, however, there are a few things to note. Firstly, “hw_mode=g” should be set as “g” even if you want an 802.11n access point. Furthermore, you need to set a WPA passphrase where indicated.

Bridging the Connections

Your AP is now configured and clients will be able to connect, however, they will not be assigned an IP and they will not be able to access the network on eth0. That’s where bridging comes in. This example assumes that your server has an eth0 connection to the network and wlan0 which is being used as the wireless AP.

First we need to install the bridge utilities:

user@computer:$ sudo apt-get install bridge-utils

Edit your /etc/network/interfaces file like so:

# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
 
# The loopback network interface
auto lo
iface lo inet loopback
 
# The primary network interface
#auto eth0
#iface eth0 inet static
#       address 192.168.0.2
#       netmask 255.255.255.0
#       network 192.168.0.0
#       broadcast 192.168.0.255
#       gateway 192.168.0.1
 
auto br0
iface br0 inet static
        address 192.168.0.2
        netmask 255.255.255.0
        network 192.168.0.0
        broadcast 192.168.0.255
        gateway 192.168.0.1
        bridge-ports eth0 wlan0

Note that the new br0 interface effectively replaces your existing eth0 interface. If you’ve followed the Ubuntu SBS guide to configure DHCP then you’re done! Your new AP should be up and running after a simple reboot. If not, follow the DHCP Server section of the SBS guide on this site.

Connect with:

13 Comments

on “hostapd: Ubuntu server as a wireless access point
13 Comments on “hostapd: Ubuntu server as a wireless access point
  1. Hi Dan,

    I see you can also start hostapd under your network/interfaces by adding the lines below.
    What i like about it is that it allows you configure other settings on you wifi interface if needed.

    iface wlan0 inet static
    hostapd /etc/hostapd/hostapd.conf
    address 192.168.168.1
    netmask 255.255.255.0

  2. i’ve tried this on xubuntu, it works, but only for the people connecting to the access point.. on the host computer i don’t have internet the internet symbol in the bar also has a red cross.

  3. Can you bridge two wireless adapters? I’m deployed overseas and the only internet I have is wireless. The signal is very weak. I have a high gain wireless usb adapter (from TP Link) attached to my laptop to get a good signal. I would like to set up a wireless access point using the built in wifi card for my laptop and share the connection I get from the usb wireless adapter. How would I go about doing that?

  4. Pingback: voyage, bluetooth & android

  5. Pingback: problemi bluetooth con bluez - Pagina 5

  6. Pingback: How to host an AP or a hotspot? | Ubuntu InfoUbuntu Info

  7. Pingback: WiFi-Access Point mit dem Raspberry (bridged auf eth0) » pi3g Blog

  8. Pingback: Linux als WLAN-Hotspot nutzen - Nerd-Supreme

  9. Hi,

    I got this working on my Raspberry Pi, but actually I don’t want to access the internet, but only set up a local WiFi and access the webserver on my RasPi over a smartphone. So I tried pulling the ethernet cable, leaving the bridge part out, and some other changes, but it doesn’t work.
    I can see the network, but no IP is assigned.
    Can you give me a hint?
    Thank you in advance!

    Best regards
    Zap

Leave a Reply