david@connol.ly

Raspberry Pi Wifi Access Point (L2 Bridge Mode)

A recent guide to using the Raspberry Pi as a Wifi Access Point focused on providing a routed network from the Pi itself. In most home network settings, this introduces a Double-NAT which is highly undesirable.

However, a WiFi access point is usually a layer 2 bridge. Thankfully, the built-in drivers for the RaLink RT5370 usb dongle supports bridging with the following command:

iw phy phy0 interface add moni0 type managed 4addr on

After running this command, all normal brctl commands work with the wlan0 device, and a Pi can be configured as a real layer 2 bridging access point!

The following is an example configuration suitable for Rasbian. HostAP should be configured as per the eLinux guide. No DHCP or Firewall configuration is required.

Pre-requisites:
apt-get install bridge-utils hostapd

/etc/network/interfaces
auto lo
iface lo inet loopback
auto eth0
iface eth0 inet manual 
pre-up ifconfig $IFACE up
post-down ifconfig $IFACE down
auto br0 
iface br0 inet dhcp
bridge_ports eth0 
auto wlan0
iface wlan0 inet manual
    pre-up ifconfig $IFACE up && iw phy phy0 interface add moni0 type managed 4addr on
    post-up (sleep 60 && brctl addif br0 wlan0) &

Note, the command highlighted in red is delaying adding wlan0 to the bridge until it is ready.

/etc/hostapd/hostapd.conf
interface=wlan0
driver=nl80211
country_code=IE
ieee80211d=1
ssid=PiAP
hw_mode=n
channel=6
wme_enabled=1
ieee80211n=1
ht_capab=[SMPS-STATIC][RX-STBC1]
macaddr_acl=0
auth_algs=1
wpa=2
wpa_passphrase=PiAP2013
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP CCMP
rsn_pairwise=TKIP CCMP

Add to /etc/sysctl.conf
net.ipv4.ip_forward=1
net.ipv6.conf.all.forwarding=1

* Updated to enable 802.11n mode.

Comments:

TheCompander -

how did you choose the ht_capab values for the rt5370?

I find that my uplink performance is halved when using mode n and your ht_capab values.

David Connolly -

Hi,

Thanks for the cool tip.

I used the values autodetected by openwrt on another router with the same usb device.

Both those HT_CAPAB options depend on 802.11n. I’d say the power saving option [SMPS-STATIC] is killing throughput.

I’m mainly using this with a Nexus 4 and an iPad so battery life is the priority!

Unknown -

Hi, I had some problem getting this to work. Is the script supposed to bring up hostapd automatically? Where is that done? I had to start it manally for some reason. Anyway cool post!