Aug 102012
 

QuickLinks
Part 1 – How to create a Wireless Network On Your RPi
Part 3 – How to make your RPi into a Router

In this part, we will turn the Raspberry Pi into a Wireless Access point.
All it will do is forward packets from the WiFi adapter to ethernet and vice versa. It will allow you to access your network via WiFi without needing a WiFi router.

To do this, we need to bridge the ethernet and wifi connections, and tell hostapd that we are now using a bridge connection.
In /etc/hostapd/hostapd.conf, we need to add the following line.

bridge=br0

Add the following lines into /etc/network/interfaces to define the bridge connection.

#auto br0
iface br0 inet dhcp
bridge_ports eth0 wlan0
pre-up ifconfig eth0 0.0.0.0 up
pre-up ifconfig wlan0 0.0.0.0 up
pre-up brctl addbr br0
pre-up brctl addif br0 eth0
post-down ifconfig wlan0 0.0.0.0 down
post-down ifconfig eth0 0.0.0.0 down
post-down brctl delif br0 eth0
post-down brctl delbr br0

Notice the “auto br0” is commented out. This is so the bridge does not come up automatically, as once the bridge is up, you will not be able to remotely access the Raspberry Pi until the bridge is brought down or until the bridge gets an IP address.

Once the lines are in /etc/network/interfaces, you can type in ifup br0 as root to bring up the bridge. If you are ssh’ed into the Pi, this will drop your connection.
Once it’s up, the Raspberry Pi will forward anything from the WiFi to ethernet and vice versa.

This let’s the Raspberry Pi act as a Wireless Access Point without any sort of routing. On a WiFi device, you will be able to connect to RaspAP, and it will act is if it was on the network, i.e. it will get an IP address from your normal router.


If you have found this post useful, please consider donating by pressing on the button below. Donating will help keep this site up and running ๐Ÿ™‚




Share

  36 Responses to “How To : Use The Raspberry Pi As A Wireless Access Point/Router Part 2”

  1. Hi I would like to create a network bridge between the ethernet port and the wireless usb adapter on my raspberry pi for my xbox. Are the instructions above all I need to do to set that up? I’m not interested in an access point, I just want to connect to the internet through my raspberry pi’s wireless connection via the ethernet port. It’s simple to do in windows but not so easy in linux.

    • So you want to connect the XBox to the Ethernet port on the Pi, and then use the Wifi to connect to a wireless network ?
      Easier way is to make the Pi into a wireless router/bridge.
      Same way as the Router post (Part 3), except swap wlan0 and eth0
      Harder way, is to make it into a bridge. I haven’t actually tried making it into a bridge, but it’s something along the lines of –
      install wpasupplicant
      connect the wifi
      setup a bridge
      use ebtables to change the mac address of any packets going out to the mac address of your xbox.

      I’ll do a writeup of it as soon as I can get my Pi working again.

      • Thank you for great tutorial.

        I was trying to do the same stuff as dave does with wireless bridge way. But I did not succeeded ๐Ÿ™ And I do not have local screen/keybord on the RasPi (I am using VNC as I do not have HDMI screen at home). So, what I know is – that when I make br0 interface from wlan0 and eth0, I’m able to ssh into the box only when I do connect ethernet to the switch directly, but what I wanted was, to have wifi connected to the AP and use ethernet interface as an LAN plug (without cable); I do need the same network for my endpoint, I do not like to be NATting the trafic (it would be 4th NAT on the route ๐Ÿ˜‰

        So, I’m a bit hoping that this thread will be continued ๐Ÿ™‚

        thx.

  2. Okay thanks I will check out the 3rd tutorial. Do I need to do any of the steps mentioned in the other tutorials or just start from the 3rd and go from there?

  3. Hey, got part 1 working fine but as soon as I add bridge=br0 too hostapd.conf i stop getting any kind of ip address.

    I am using archlinux so I am not entierly sure on how to do the part that should be added to interfaces, but I tried manually and it seems I have a bridge at least.

    #brctl show br0
    bridge name bridge id STP enabled interfaces
    br0 8000.000f53b02c49 no eth0
    wlan0

    • Yep when the bridge goes up, wlan0 and eth0 will lose their ip address and br0 should get one. If it doesnt, may need to run dhclient br0

      • Hello!

        Thanks for your reply, and sorry I wasn’t clear.
        I get an ip to br0, but dnsmasq does not seem to give ips to the clients that connect.

        I also wrote a question at the Arch Forum that has more detail
        https://bbs.archlinux.org/viewtopic.php?pid=1165886

        You said somewhere that you used the ralink 5370, what driver did you use? rt2800usb or rt5370sta?

        • Ah I see.
          If you have a bridge, you don’t need dnsmasq. The bridge will pass packets from the ethernet out to the WiFi network-connected computers.
          You only need dnsmasq if you are using the Pi as a standalone access point, or as a router.

          I don’t remember what driver i used and unfortunately I can’t check as my Pi is buggered at the moment. The SD Card socket broke and I haven’t had time to fix it yet.

  4. Awesome write-up, I am working on getting my Raspberry Pi to serve American Netflix to my home in Canada (through a SSH tunnel to my hosting provider in the states). The basic setup of my network is a pi running dnmasq and serving as a caching name server for my internal LAN and routing to my ISP provided modem (gateway). The second part of my project is to use a wifi dongle as an AP on the pi, set up dnsmasq to dish out IP’s on that interface on a different subnet, then route all traffic on that subnet through the tunnel the the states.. the apple-tv connecting to that WiFi network instead of my other WiFi network used for regular run of the mill Canadian content. Anways, I got everything configured before I realized that hostapd doesn’t work with r8712u based chipsets (8191SU on the D-link DWA-130 I’m using). I’ll let you know how it goes once I get a different dongle.

    Thanks for the write-up! ๐Ÿ™‚

  5. Fantastic write-up, many thanks.
    A note for others who may have encountered errors with hostapd failing to start – after some hunting around I found the “-d” parameter you can pass to hostapd to help get details on any issues.
    My issue was that the hostapd.conf file had a passphrase of 6 characters only and it was complaining that a minimum of 8 chars were needed for the passphrase.
    Changed that and all is working now so happy days.

  6. Hi,

    Great work! I am currently implementing it in a pandaboard with ubuntu 12.04. When I try to do the ifup br0, I am getting br0 already exist. Though, ifconfig doesnยดt show any br0. Checking forums,
    I tried ifconfig br0 up. and add a ip static ( I am not using dnsmasq so far).

    In another pc (windows). I connect to the wireless network, I made a ping to the device ip and it connects. But, when I tried the other hand, ping from the device to the pc. it doesnยดt connect. However, I can access a web service in the device by broswer using the ip static which I assigned.

    I guess the bridge functionality is not working. The reason for not using dnsmasq is that I am getting an error: failed to bind DCHP.

    have you encountered a similar problem?

    Thanks,
    Dustin

    • If it thinks br0 already exists then you can check by running brctl show

      That should show you whether the bridge exists, and also what interfaces are part of the bridge.

      Also you don’t need dnsmasq on the pandaboard if you’re just using the board as a bridge.

      • Thanks for the quick reply. I managed to create the bridge. Both client and bridge can see each other using ping. however, I canยดt used ssh to connect to bridge from client. I get a network refused. similar, the bridge canยดt connect to client using ssh.

        any ideas?

        Thanks
        Dustin

      • It is working now. I guess I was doing something wrong.

        Thanks,
        Dustin

  7. Hi,

    Not sure what I am doing wrong, but cannot seem to get it to work. Can you please supply each config file to google docs or something similar (or possibly create a script that executes it all?

  8. Hi,
    I am trying to user your instructions to setup 3G (ppp) as WAN, Please guide me if the above instructions will route traffic from wlan0 to ppp.

    Best regads,
    Chandan

  9. I’m trying to setup an Hotspot which only can connect with the outside internet. How can i configure a bridge that only allows to reach the router of my ISP to access the internet?

    • Add an extra rule to iptables to drop any traffic that has a destination IP of the LAN and an input interface of wlan0

      • Thanks for your response! During the time i rebooted my R Pi, but im only able to connect to it over SSH when the antenna is not plugged in.

        Any idea of what is going wrong? I cannot ping to the IP

        • Check iptables and dnsmasq to ensure they’re still running and/or configured.

          • dnsmasq wouldn’t start, tried to get additional config files from a dictionary that didnt exist. thanks for the advice ๐Ÿ˜‰

            I’ve tried to setup an firewall rule, but i dont seem to succeed:
            sudo iptables -I INPUT -i wlan0 -d 192.168.2.0/24 -j DROP

            Any guesses of what im doing wrong?

          • Even if i try sudo iptables -I INPUT -j DROP the wifi over the hotspot keeps working. My SSH ofcourse stops, but that asside, it looks like iptables has no effect to the bridge?

          • Hang on, are you using the Pi as a bridge with a br0 interface or as a router with iptables routing between wlan0 and eth0 ?

          • I’m using the bridge config in your article, i dont do any routing with iptables.

          • In that case, you need to use br0 rather than wlan0

            iptables -A INPUT -i br0 ..etcetc.

  10. Hi, I am confused, I’m afraid (not your fault, obviously, just my age!) as to whether these instructions will do what I want. I have tried various ways to achieve what I want but so far none have worked! What I want to do is get an internet connection from a usb wifi dongle and then make a hotspot so that my laptop can connect to it (in a motorhome – the RPi will use a lot less battery power than the laptop). Each method I have tried has failed for one reason or another. Is what I’m trying to do possible (it must be, surely?) ? If so, any pointers or tips would be wonderful. I first bought the RPi for this project 18 months ago and haven’t worked it out yet!

    • Yes, what I have posted is exactly what you need. Feel free to post some questions on here and I will try and answer them

 Leave a Reply

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

(required)

(required)

This site uses Akismet to reduce spam. Learn how your comment data is processed.