Multiple SSIDs with hostapd

From Wiki
Jump to: navigation, search

I found the documentation for this rather confusing, but it's quite simple.

In essence, each SSID needs a BSSID. In a standard single-SSID configuration, the BSSID of your wireless card is the same hex value as the burned-in MAC address of the card. Every SSID requires its own BSSID, so hostapd needs to be told how these should be generated.

Not every wireless card will work with hostapd, and of those that will only a subset will support multiple SSIDs. Nicolas Calderon kindly let me know about the iw command which can be used to interrogate your wireless card in order to discover what capabilities are supported:

# iw list
  ...much output

valid interface combinations:
     * #{ managed, WDS, P2P-client } <= 2048, #{ IBSS, AP, mesh point, P2P-GO } <= 8, total <= 2048, #channels <= 1

Note: iw list is distinct from iwlist

Nicholas points out – and I agree with his interpretation – that within the 'valid interface combinations' section, the part containing the 'AP' mode must correspond to a number higher than 1, in the above case it looks like 8 SSIDs would be supported.

Assuming you get encouraging results from iw list, the first step is to change the MAC address of the wireless interface. This is necessary because the MAC must end in a 0, and we need to make sure that newly generated addresses don't conflict with other devices. So, find out the existing address:

# ifconfig wlan0 | grep -o "HWaddr ..:..:..:..:..:.."
HWaddr 09:ab:cd:ef:12:34

where wlan0 is your wireless interface. This MAC address will need to be changed like so:

09:ab:cd:ef:12:34<- Change to 30
Change to 02, which means 'locally administered'

So, hostapd will assign BSSIDs from 02:ab:cd:ef:12:30, 02:ab:cd:ef:12:31, 02:ab:cd:ef:12:32 and so on. To make this change, it should be as simple as:

# ifconfig wlan0 down
# ifconfig wlan0 hw ether 02:ab:cd:ef:12:30
# ifconfig wlan0 up

but that wouldn't work for me, since wlan0 refused to be taken down. Instead, I just did this:

# vi /etc/network/interfaces

auto wlan0
# Hotplug will watch for this device and bring it up when connected.
# Useful for USB devices
allow-hotplug wlan0
iface wlan0 inet static
 # Start hostapd if it is not running
 hostapd /etc/hostapd/hostapd.conf
 pre-up ifconfig wlan0 hw ether 02:ab:cd:ef:12:30

Now, additional SSIDs can be configured like so:

# vi /etc/hostapd/hostapd.conf

# Change wlan0 to your wireless device
# Tell hostapd what your new MAC address is




Restart hostapd

# service hostapd restart

and you'll have new interfaces like wlan0_0, wlan0_1 which correspond to each SSID. These can be assigned IP addresses and routed or masqueraded with iptables – whatever you wish. However, whatever I tried I couldn't get wlan0_0 to be brought up at boot with the right IP address. I had already added:

auto wlan0_0
iface wlan0_0 inet static

to /etc/network/interfaces, but still no go. In the end I lost patience and simply modified the init script like so:

# vi /etc/init.d/hostapd


	log_daemon_msg "Starting $DESC" "$NAME"
	start-stop-daemon --start --oknodo --quiet --exec "$DAEMON_SBIN" \
		--pidfile "$PIDFILE" -- $DAEMON_OPTS >/dev/null && sleep 5 ; ifup wlan0_0
	log_end_msg "$?"


Yep, it just waits five seconds for hostapd to start and then manually brings up wlan0_0, reading its config from /etc/network/interfaces. Ugly, but it works fine.

However, Jayen Ashar says:

"I was able to get udev to start the interface by changing auto wlan0_0 to allow-hotplug wlan0_0 in /etc/network/interfaces".

I will definitely try this the next time I do a PiFi build. Stocksy 09:13, 18 November 2013 (UTC)