Raspberry Pi Uncategorized

Raspberry Pi and Routing: Turning a Pi into A Router

The Raspberry Pi can be used as a router–great if you need a pocket-sized device to share an Internet connection.  It can also be used in conjunction with a cantenna.

Requirements For This Walkthrough


  1. Local network
  2. Mac or PC
  3. Raspberry Pi  running Raspbian “wheezy”
  4. Wireless USB Adapter
  5. HDMI Cable (*optional)
  6. Keyboard (*optional)
  7. Mouse (*optional)
  8. Monitor with HDMI input (*optional)

*If the Raspberry Pi is set up as a headless machine, you will not need a monitor, keyboard, or mouse–just another computer, which would be used to access it remotely over the network via SSH.


  1. Older hostapd (only needed if the driver via apt  does not work)
  2. Copies of config files on Github (optional or for reference)

Knowledge, Skills, and Abilities

  1. Ability to navigate throughout a computer OS
  2. Knowledge of basic computer terminology
  3. Ability and confidence to enter commands in the Terminal, adjusting them to suit your environment, if necessary
  4. Familiarity with core networking concepts



Conceptual Overview

  1. Install Required Components via apt-get
  2. Verify Wi-Fi Adapter dongle functionality
  3. Configure /etc/network/interfaces 
  4. Create /etc/hostapd/hostapd.conf  with desired AP settings
  5. Point hostapd  to the configuration file in step 4 by modifying /etc/default/hostapd
  6. Replace /sbin/hostapd  with the older version (if necessary)
  7. Configure DHCP to allow clients to connect
  8. Enable IPv4 forwarding to reach the Internet


Prepare the RPi

Make certain that the RPi is up-to-date and all the newest packages are available for download/installation.

sudo apt-get update
sudo apt-get upgrade

Install Required Components

The following components will be required for setting this up as an access point:

  • rfkill: a wireless utility
  • zd1211-firmware: common firmware that works with many Wi-Fi dongles
  • hostapd: the hostap wireless access point daemon
  • hostap-utils: supplemental hostap tools
  • iw: wireless configuration utility
  • dnsmasq: DHCP and DNS utility
  • bridge-utils:  used for connecting multiple Ethernet devices together

Install these components using the command:

sudo apt-get install rfkill zd1211-firmware hostapd hostap-utils iw dnsmasq bridge-utils

Configure the Wireless Dongle

Verify The Dongle is Recognized by the RPi

Check that the RPi recognizes the Wi-Fi dongle.


You should see a listing mentioning the adapter you have plugged in.

Verify that the Wi-Fi dongle supports AP mode

If the output of the following command does not show anything about AP mode, then the dongle will not work for this project. But if it does, continue following the step-by-step directions.

iw list

Unfortunately, my dongle did not work and produced the error nl80211 not found , which is OK.  Run this command:

dmesg | grep rtl

if the output is similar to:

[    6.240292] usbcore: registered new interface driver rtl8192cu

then it will probably still work.  This will be fixed in a later step.

Configure the Wireless Interface

Make a backup of /etc/network/interfaces  and then open it in a text editor:

sudo cp /etc/network/interfaces /etc/network/interfaces.orig
sudo vi /etc/network/interfaces

Modify the file as below (highlighted lines are the additions):

auto lo
auto br0

iface lo inet loopback
iface eth0 inet dhcp

allow-hotplug wlan0
allow-hotplug eth0
iface wlan0 inet manual

iface br0 inet dhcp
        bridge_fd 1
        bridge_hello 3
        bridge_maxage 10
        bridge_stp off
        bridge_ports eth0 wlan0

Restart the wlan0  interface:

sudo ifdown wlan0
sudo ifup wlan0

Configure hostapd Settings

Next, make a backup of the /etc/hostapd/hostap.conf  file and open it in a text editor to make some changes (ignore the first command if the file does not exist yet).

sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.orig
sudo vi /etc/hostapd/hostapd.conf

If using a different adapter than the one I used, just modify the file by adjusting any unique items (i.e. country_code , ssid , etc).  If the iw list  command mentioned previously reported the error nl80211 not found , then modify the file as follows:


If the iw list  command reported the error, you should also to make a backup of the /etc/default/hostapd  file (if it exists),

sudo cp /etc/default/hostapd /etc/default/hostapd.orig
sudo vi /etc/default/hostapd

and then modify the highlighted line below (be sure to uncomment the line):

# Defaults for hostapd initscript
# See /usr/share/doc/hostapd/README.Debian for information about alternative
# methods of managing hostapd.
# Uncomment and set DAEMON_CONF to the absolute path of a hostapd configuration
# file and hostapd will be started during system boot. An example configuration
# file can be found at /usr/share/doc/hostapd/examples/hostapd.conf.gz

# Additional daemon options to be appended to hostapd command:-
#       -d   show more debug messages (-dd for even more)
#       -K   include key data in debug messages
#       -t   include timestamps in some debug messages

If you are using the same dongle I did, you will need to take another additiona step and replace  /usr/sbin/hostapd  with a newer version, which you can get here (but we will use a command to download it next).  Following our best practice, make a backup first and then edit it:

sudo cp /usr/sbin/hostapd /usr/sbin/hostapd.orig

Delete the original file, which will be replaced by the one downloaded via the command below:

cd /usr/sbin
sudo rm -f hostapd
sudo wget

Set the proper permissions on the new file and make sure it is executable:

sudo chown root:root hostapd
sudo chmod 755 hostapd

Restart thehostapd  service to activate the settings.

sudo service networking restart
sudo service hostapd restart

If the hostapd restart did not work.  Try running this to view the output and see if you can find where the problem is in the config file and fix it:

sudo hostapd -d /etc/hostapd/hostapd.conf

The wireless network should show up if you were to scan for it from another device.  However, a few other settings need to be configured before anyone can connect to it.  In particular, dnsmasq .


Configure dnsmasq Settings

Following best practices, make a backup of the config file before editing it and then open the file in a text editor.

sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo vi /etc/dnsmasq.conf

Uncomment the following lines and adjust them to your environment:


After saving the file, you can easily verify all the settings were correct with the following command (it just parses out the comments and blank lines):

cat /etc/dnsmasq.conf | grep -v "#" | sed '/^$/d'

Restart thednsmasq  service to apply the settings:

sudo service dnsmasq restart

Attempt to connect to the network using another device.  You should be able to connect, but you won’t be able to get out the the Internet yet.

Enable Forwarding to Reach the Internet

Enable IPv4 forwarding

sudo sysctl -w net.ipv4.ip_forward=1

Enable NAT

sudo iptables -t nat -A POSTROUTING -j MASQUERADE

Other Dongles and Other Uses

The main reason I chose the Wi-Fi dongle that I did was so that I could connect my cantenna to it and blast the signal a long distance.  It would have certainly been easier to use an adapter that worked right out of the box, but now I have a lot more flexibility with antenna types.

Donate Bitcoins


Here are all the commands from the walkthrough needed to set up the router (excluding the information needing to be added to the files):

sudo apt-get install rfkill zd1211-firmware hostapd hostap-utils iw dnsmasq bridge-utils
sudo cp /etc/network/interfaces /etc/network/interfaces.orig
sudo vi /etc/network/interfaces
sudo ifdown wlan0
sudo ifup wlan0
sudo cp /etc/hostapd/hostapd.conf /etc/hostapd/hostapd.conf.orig
sudo vi /etc/hostapd/hostapd.conf
sudo cp /etc/default/hostapd /etc/default/hostapd.orig
sudo vi /etc/default/hostapd
sudo cp /usr/sbin/hostapd /usr/sbin/hostapd.orig
cd /usr/sbin
sudo rm -f hostapd
sudo wget
sudo chown root:root hostapd
sudo chmod 755 hostapd
sudo service networking restart
sudo service hostapd restart
sudo cp /etc/dnsmasq.conf /etc/dnsmasq.conf.orig
sudo vi /etc/dnsmasq.conf
sudo service dnsmasq restart
sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -j MASQUERADE


I recently followed my own walkthrough and ran into an issue on the last command for iptables .  It returned the error:

libkmod: ERROR ../libkmod/libkmod.c:554 kmod_search_moddep: could not open moddep file '/lib/modules/3.10.25+/modules.dep.bin'
iptables v1.4.14: can't initialize iptables table `nat': Table does not exist (do you need to insmod?)
Perhaps iptables or your kernel needs to be upgraded.

I was using the image of raspian from back in January 2014.  After running

sudo rpi-update

I was able to execute the command and get out to the Internet via the Raspberry Pi Router!

119 replies on “Raspberry Pi and Routing: Turning a Pi into A Router”

[…] This seemed interesting – turing a RPi into a wireless router… Like many Raspberry Pis, mine is currently sitting in a drawer doing little more than collecting dust… I was previously using it as a local git repo, but it made little sense with the many other running PCs in my household with far more sufficient resources (namely storage space) than the Pi has… In an effort to find a use for it and having previously been in need of a new router (wound up replacing with a Buffalo with DD-WRT instead), I stumbled across this project in some reading and thought it neat – […]

Any thoughts on turning a Raspberry Pi into an aircard router for one device (IP Cam) via Lan? I’d like to plug a USB Aircard into the Pi and connect the cam via ethernet.

If you are just looking to get an IP webcam, take a look at my other post on turning the Pi into a live-steam Webcam over the Internet. If you have already set up the Pi as a router, you could just plug in the USB Webcam, bypassing the aircard all together.

If you are trying to use the celluar data service for the Webam, you would probably need the driver for the aircard first. Since an aircard is basically another network interface, you might be able to modify the steps in this walkthrough for that interface instead of the ethernet/wi-fi interfaces.

Thanks for the info J. I am following your design since I just have to swap the interfaces and make a couple of changes. I’m new to linux so it is taking me a bit longer to learn my way around. Once I get the wwan0-eth0 bridge working I’ll post the results.

Dear Jacob;
good job for this post, i want to ask you a question, i need to make a small project like router,i.e i need to forward any data comes from local network to outside the local network through a GPRS / USB modem,
and also i need to access a device connected to the local network remotly through the same GPRS or USB modem.
I successfully did it using a TP-Link router and usb modem and using the port forward, but now i want to use my own Embedded system to add some control to my system,
Could i know if the rabry Pi or any platform is suitable for this project or not. also i need to buy thousands of this system so i need to compile all command to the kernel instead of write all these command for each device.

hope that i explained my problem successfully and i appreciate your support.

Best regards
Mohamed Hamed

Yeah, port forwarding isn’t the easiest thing in the world. I wouldn’t recommend it if you aren’t completely comfortable with it.

My *nix skills seem to fade if I don’t use them for a while, so I cannot answer this upfront. I am planning to follow my own tutorial and set this up on the faster B+ model and maybe make some sort of RPi mesh network or something…

This tutorial makes a fine access point from the wlan interface, but it does not function as a nat router for me.

The windows pc still is connecting to the upstream dhcp and gets an address in the range of the upstream (tplink) router.

e.g. i am missing the place where a ip number is assigned to the wlan interface.

What do you have set in your dnsmasq.conf file? You should have the dhcp-range= option set in order to distribute DHCP addresses.

/etc/network/interfaces is the file where you can assign how an interface gets its IP address. In this walkthrough, I had my Pi connected directly to my router via eth0, so I had this in the file: iface eth0 inet dhcp. This says that eth0 should have its IP set via DHCP (i.e. from my existing router). I set it this way so I could configure the entire thing via SSH.

You will probably want to look at adjusting both of the files mentioned above.

I think the easiest way would be to run this command:
cat /var/lib/misc/dnsmasq.leases
Client requets also show up in the main log file along with other information:
cat /var/log/daemon.log

Nice Tutorial! Saved me several hours of digging. Just one comment. IMHO I think the setup is little cleaner (and probably more secure) without a bridge between eth0 and wlan0. I configured wlan0 with a fixed address on the DHCP subnet and added a few extra entries in iptables to forward packets. This way both networks are correctly separated. Thanks!

I suppose its the same issues you would find with any router minus a WPS vector. You might even get a little security-through-obscurity, as comparatively, not that many people will be running a Pi router.

I am having trouble with this… i got everything setup and it works fine when i have it plugged in via ethernet cable, but i need to be able to use is as a true router, and have it unplugged.
I am bulding a robot and have everything else working but need to know how to set this up as a standalone router. when it is unplugger from the ethernet i am able to connect to the network but my computer then says there i s an error and the rpi doesnt have a gateway.
I have tried searching for an answer but nothing is working please help

I only need it for ad-hoc purposes.

and for some reason i thought it was a good idea to start on my robot project one week before i need to have the entire thing done..

BTW thankyou for this tutorial it was really helpful.

I have not tested this, but you should be able to just use it in ad-hoc mode as-is. If you went through the entire walkthrough, you should have set up DHCP. So any client that connects will get an IP address and can communicate with each other.

Hi Derek, I would recommend you do the same as me and not bridge eth0 with wlan0. You will need to remove the br0 interface and give wlan0 a static IP address on the same subnet you have assigned to the DHCP pool (but not one assigned to the pool of course). This way you will be able to connect to the Pi even when eth0 does not have an IP address.

oh bud. this is unbelievable. Seriously, in a short word: Your are a genius guy, I’ve never seen.
Your tutorial is really the best one in the whole net about the seem issue, speciously on the driver wifi chip rtl8192cu that I have.
believe it or not, I was digging around the net for the whole week to get my issue resolve for my boss.
I found most the forums and discussions are about to recompile the kernal to get the rtl8192cu, and create an image then copy it to boot pi’s SD card. and there many methods to create that shit image, and I followed all of them step by step without any advance, because you know about more issues that I faced to create that image, like for example command: “make command” within the rtl8192cu driver folder to identify the wifi chip.
honestly, I found your hostapd file very useful to get all issues done, and I change it your commands a little as following in general:

1- downloading dhcp server and let it gives all your IPs.
2- For the nat table, I added to it to more rows commands, and then swabbing between etho and wlan0, and let eth0 get the IP address by your external dhcp router, as long as it is connected by ethernet link to the router, so I can get to access to pi by ssh in later time.
3- using static wlan0 instead of bridge.
that is it, and now I can access to internet through pi as access point and browsing youtube, facebook, etc. from my laptop and iPhone mobile .
and now I will prepare php script to get control for those customers on pi.
the pi after a while disconnected for one minute. and I think that for drop power. and there is a command to fix it.
———— ——MANY——————————–THANKS—————————-

I sincerely appreciate your kind words!

I, too, spent a long time searching for how to do this, so I cannot take all the credit. I just tried to make it a bit easier to follow in more of a step-by-step way.

The hostapd file was from someone else, but I also saved a copy to my public Dropbox in case they ever stop sharing it for some reason.

I’m glad you found the tutorial useful–it’s satisfying!


This tutorial is really good and descriptive! much better than any i have found on the net. I’m just having a slight issue, I’m a noob when it comes to anything linux/unix! The steps I’m having an issue with are:

Configure hostapd Settings

Next, make a backup of the /etc/hostapd/hostap.conf file and open it in a text editor to make some changes (ignore the first command if the file does not exist yet).

I keep getting an error (see image attached) any help would be greatly appreciated!

You do not need to back up the file because it does not exist, which is OK. Some users will have an file there already, which is what the backup is meant for. You can simply create the new file.

Thanks for getting back to me so quick! Thanks for that, was just a little worried I was missing something that I needed.

I have another issue again, sorry to be a pain! I have now followed all of the steps but when i go to restart the hostapd service it doesn’t restart, i was wondering if this could a driver issue? is any dongle that is compatible with the pi good for this? also i am using the original raspberry pi, would this cause an issue also?

Thanks for all your assistance!

(screenshot of the error i get when restarting the service)

hostapd failing to start usually has something to do with an error in the config file. Try starting hostapd in debug mode using your config file with this command:

sudo hostapd -d /etc/hostapd/hostapd.conf

Look for any clues as to what might be causing it to fail. You can post the output here if you can’t figure it out.

There are many dongles that will work out of the box. For this tutorial, I was most interested in an adapter that had a removable antenna so that I could connect my cantenna. But I’m sure if you get the right one, it will work much easier.

the error I’m getting back is for the driver?

pi@raspberrypi ~ $ sudo hostapd -d /etc/hostapd/hostapd.conf

random: Trying to read entropy from /dev/random

Configuration file: /etc/hostapd/hostapd.conf

Line 3: invalid/unknown driver ‘rtl871xdrv’


1 errors found in configuration file ‘/etc/hostapd/hostapd.conf’

Here is a link to the package i got, I’m not using this pi though I’m just using the wifi dongle from it –

thanks again for all your time and help

i managed to find the problem! it was a driver issue so i tried commenting it out and that worked! thanks for all your help man 🙂

This happened to me too. I fixed it by editing /etc/hostapd/hostapd.conf again. I found extra lines with random numbers on them. Delete those and you’ll be good.

Ok, so I was debugging the hostapd.conf file and the following message apeared: /usr/sbin/hostapd: 1: /usr/sbin/hostapd: syntax error: redirection unexpected

What do I need to check?

Would something like this work to turn the Pi into a wired router? I would like to tether my iPhone via USB and have the Pi act as a wired router (no wifi desired). I would run the ethernet from the Pi to an ethernet over powerline device.

I don’t see why not. You would just need to adjust the interfaces appropriately. Perhaps get some sort of ethernet splitter for more ports or something.

You can follow the steps in reverse and restore the original config files, which would be the easiest. You could also uninstall all the services.

I am using Raspberry Pi Model A which doesn’t have an ethernet port. Can I still do it? And If yes, how am i going to install hostapd and the drivers for the Wi-Fi dongle without the ethernet cable? Thanks!

You might be able to use a USB to Ethernet adapter, but you might have to find drivers for that. Once you get it working, then you could download whatever you need from online.

I cannot guarantee anything, but it looks like you can use the driver found here. I found this information along with some directions on this page.

So, of course with the statement “If the output of the following command does not show anything about AP mode, then the dongle will not work for this project.” one has to ask,

1. Is there a repo or list somewhere of AP mode supported dongles (ideally for 802.11ac) out there?

2. I’m assuming MIMO’s out of the question with this solution?

3. Due to comm’s limitations on the board via the USB channels (even at USB 2.0), I could see this getting really hot, is there any danger (or at the very least performance risk) to not running an active cooling solution while running in AP mode? Wouldn’t be difficult to pin off a case face but before adding that headache to mix I figured I’d ask first.

I do not know of a repo that lists whether or not the dongle supports AP mode. There is a column for AP mode listed on this page, but they are all question marks.

As for your other question, it seems to run fine without overheating, but I’m sure it could if you pushed it hard enough.

Hi, Great How-to, but can someone tell me where “sudo iptables -t nat -A POSTROUTING -j MASQUERADE” is stored as I can not find it

I’m not sure of the file, but you can view current rules with

iptables -L

and if you want to delete, use the -D flag

Thanks for the quick response. I’m trying to set Rpi AP without br0 interface, and not sure what rules I need to enter. Any help would be appriciated

iptables has always been the bane of my existence, so I’m afraid I won’t be able to help much. I usually just Google whenever I need to find how to set a specific rule, but even then…

Hi, and thanks for the great tutorial!I am using the Edimax ew-7811un nano usb for WIFI dongle and I want to create a standalone router for ad-hoc purposes. Not sure though which changes I should make.Could you please help me?
Thank you for your time

Ok thank you. Since I need not to connect to existing internet network, does this tutorial still apply to my case since you are bridging ? or can it still work?

Making the bridge lets you get out to the Internet, but if you just want to use it as a local access point, then you don’t need to do that part.

Thank you for the tutorial.
The process seems kind of easy as described and I think that I might be able to do it on my Arch system as well. Nevertheless, I would like to ask you a question. Is the DHCP server capability limited to the wlan0 interface only? I am interested in it, because I cannot allow the DHCP server to offer ip addresses to the LAN through eth0. A router we used did this (did offer IP addresses via WAN port) after a power shortage and we were without internet at work for a while because of conflicting DHCP broadcasts.

You can change the interface to whatever you want. I believe it is just a setting in dnsmasq.

Hi Jacob, I was following your guide and I successfully create wifi network from raspberry pi. But now I’m in the project that I need to create 3 ssid using 3 wireless adapter. I tried to add more interface in hostapd.conf file, but it seems only the last ssid up and working. I really want all 3 ssid up and running, please help me I was struggling with this for ages with no success. Thanks.

So you are trying to use three wireless adapters to make three different SSIDs, all on a single Raspberry Pi? I’m not 100% certain how to do this, but as an educated guess, you should start by modifying the /etc/network/interfaces</code< to include your dongles. So maybe something like:
bridge_ports eth0 wlan0
bridge_ports eth0 wlan1
bridge_ports eth0 wlan2

Then, you would need to duplicate the /etc/hostapd/hostapd.conf for each SSID you want.

Thank you for quick reply.
Yes, correct. I was messing up with interfaces, now when I do ifconfig, there is no ip add on wlan0,1 and 2. I tried your suggestion, but it doesn’t work yet and there is still only 1 ssid up and running. I don’t think I can duplicate hostapd.conf file in the same directory using the same name. I was thinking to put more interface in hostapd file like:

INTERFACE=wlan0 wlan1 wlan2 and also 3 ssid and 3 passphrase, but I don’t know how it works and configure it properly 🙁


Hi Jacob, I would like to thank you for this guide on my final project in my IT net sec degree, and now I graduated. Anyway, I end up using 3 different Pi with 3 wifi dongle to advertise all 3 different network. Even my tutor doesnt really now how to make it works on single pi.


Congratulations on graduating. It sounded like a challenging project. I guess you got some practice by setting them up three times then! ?

Hi. This project of yours seems very interesting and if possible, i want to do my final project by using your ideas and codes? Thanks

Flat out plagiarism isn’t good, but if you want to reference my site, go ahead.

It’s hard to say. I only tried it with about five devices and it seemed to work OK. Anything more than that you will have to just try and see. Let me know how many you get.

I just got the Pi and this is my first project, it worked flawlessly. Only issue I ran into was that during the

Restart the wlan0 interface:

sudo ifdown wlan0

I was disconnected from the Pi as I was SSH’ing into it wirelessly, I had to connect with an ethernet cable to re-gain access.

Also, I never had to do IPV4 forwarding or NAT, I could reach the internet without those steps.

Thanks for the excellent tutorial Jacob

I had that happen a few times. I think there is some way to restart the networking without kicking you out of ssh, but I’m not sure of how to do it.

I’m glad it worked for you. Thanks so much!

Good article. Would be trying this out and connect my iPhone VNC app to the Pi via Pi wireless. Wondering if the Pi can be setup both (and together) as a wireless router for internal access point and also connect to my wireless 4G home internet network – Both wirelessly using a single USB dongle. I am using a Tenda W311M N150 Wireless USB Adapter. Kindly advice.

I think you might need a separate adapter. I don’t think the interface can be an access point and connect to another network. Maybe you could do it if you made a virtual interface for the adapter…

I wonder if there are adaptors to make it a wired switch/router and also have modem capabilities (DSL or Cable).

i have a cable modem connected to a router. then i have used ethernet cable to connect to raspberry pi. My router ip address is and the raspberry pi is assigned to ip of and i have followed all the step but the hotspot connected device cannot access the internet. I think dhcp is not working properly. and how to configure the dnsmasq. Please help me..

Hi, I’ve tried this project on a few ipv4 networks and it works. But now when using it on a ipv6 network, the Wifi broadcast is seen, but somehow, I can’t connect to it. Any ideas?

Great tutorial, i did all the steps

but i am facing a strange problem: when i do :
sudo service hostapd start
It fails, but when i do:
sudo hostapd -d /etc/hostapd/hostapd.conf

the service start and i am able to connect and to surf the net. it seems that the service daemon is pointing to the wrong .conf file ?

any way i tried to do:

bash -x /etc/init.d/hostapd start

+ PATH=/sbin:/bin:/usr/sbin:/usr/bin

+ DAEMON_SBIN=/usr/sbin/hostapd

+ DAEMON_DEFS=/etc/default/hostapd


+ NAME=hostapd

+ DESC=’advanced IEEE 802.11 management’

+ PIDFILE=/var/run/

+ ‘[‘ -x /usr/sbin/hostapd ‘]’

+ ‘[‘ -s /etc/default/hostapd ‘]’

+ . /etc/default/hostapd

++ DAEMON_CONF=$’342200235/etc/hostapd/hostapd.conf342200235′

+ ‘[‘ -n $’342200235/etc/hostapd/hostapd.conf342200235’ ‘]’

+ DAEMON_OPTS=’-B -P /var/run/ ”/etc/hostapd/hostapd.conf”’

+ . /lib/lsb/init-functions

+++ run-parts –lsbsysinit –list /lib/lsb/init-functions.d

++ for hook in ‘$(run-parts –lsbsysinit –list /lib/lsb/init-functions.d 2>/dev/null)’

++ ‘[‘ -r /lib/lsb/init-functions.d/20-left-info-blocks ‘]’

++ . /lib/lsb/init-functions.d/20-left-info-blocks


++ ‘[‘ -e /etc/ ‘]’

++ true

+ case “$1” in

+ log_daemon_msg ‘Starting advanced IEEE 802.11 management’ hostapd

+ ‘[‘ -z ‘Starting advanced IEEE 802.11 management’ ‘]’

+ log_daemon_msg_pre ‘Starting advanced IEEE 802.11 management’ hostapd

+ log_use_fancy_output

+ TPUT=/usr/bin/tput

+ EXPR=/usr/bin/expr

+ ‘[‘ -t 1 ‘]’

+ ‘[‘ xxterm ‘!=’ x ‘]’

+ ‘[‘ xxterm ‘!=’ xdumb ‘]’

+ ‘[‘ -x /usr/bin/tput ‘]’

+ ‘[‘ -x /usr/bin/expr ‘]’

+ /usr/bin/tput hpa 60

+ /usr/bin/tput setaf 1

+ ‘[‘ -z ‘]’


+ case “$FANCYTTY” in

+ true

+ /bin/echo -n ‘[….] ‘

[….] + ‘[‘ -z hostapd ‘]’

+ /bin/echo -n ‘Starting advanced IEEE 802.11 management: hostapd’

Starting advanced IEEE 802.11 management: hostapd+ log_daemon_msg_post ‘Starting advanced IEEE 802.11 management’ hostapd

+ :

+ start-stop-daemon –start –oknodo –quiet –exec /usr/sbin/hostapd –pidfile /var/run/ — -B -P /var/run/ $’342200235/etc/hostapd/hostapd.conf342200235′

+ log_end_msg 1

+ ‘[‘ -z 1 ‘]’

+ local retval

+ retval=1

+ log_end_msg_pre 1

+ log_use_fancy_output

+ TPUT=/usr/bin/tput

+ EXPR=/usr/bin/expr

+ ‘[‘ -t 1 ‘]’

+ ‘[‘ xxterm ‘!=’ x ‘]’

+ ‘[‘ xxterm ‘!=’ xdumb ‘]’

+ ‘[‘ -x /usr/bin/tput ‘]’

+ ‘[‘ -x /usr/bin/expr ‘]’

+ /usr/bin/tput hpa 60

+ /usr/bin/tput setaf 1

+ ‘[‘ -z 1 ‘]’

+ true

+ case “$FANCYTTY” in

+ true

++ /usr/bin/tput setaf 1

+ RED=”

++ /usr/bin/tput setaf 2


++ /usr/bin/tput setaf 3


++ /usr/bin/tput op


+ /usr/bin/tput civis

+ /usr/bin/tput sc

+ /usr/bin/tput hpa 0

+ ‘[‘ 1 -eq 0 ‘]’

+ ‘[‘ 1 -eq 255 ‘]’

+ /bin/echo -ne ‘[FAIL’

[FAIL+ /usr/bin/tput rc

+ /usr/bin/tput cnorm

+ log_use_fancy_output

+ TPUT=/usr/bin/tput

+ EXPR=/usr/bin/expr

+ ‘[‘ -t 1 ‘]’

+ ‘[‘ xxterm ‘!=’ x ‘]’

+ ‘[‘ xxterm ‘!=’ xdumb ‘]’

+ ‘[‘ -x /usr/bin/tput ‘]’

+ ‘[‘ -x /usr/bin/expr ‘]’

+ /usr/bin/tput hpa 60

+ /usr/bin/tput setaf 1

+ ‘[‘ -z 1 ‘]’

+ true

+ case “$FANCYTTY” in

+ true

++ /usr/bin/tput setaf 1

+ RED=”

++ /usr/bin/tput setaf 3


++ /usr/bin/tput op


+ ‘[‘ 1 -eq 0 ‘]’

+ ‘[‘ 1 -eq 255 ‘]’

+ /bin/echo -e ‘ failed!’


+ log_end_msg_post 1

+ :

+ return 1

+ exit 0

do you have any idea how to fix this ?

It’s been a while since I have had to debug this thing, but most often, there is a syntax error in the config file. That would be the first place to check.

This is likely due to a syntax error in /etc/default/hostapd . Pay close attention to the quotes that surround the DAEMON_CONF line. If you copy-pasted from the guide there is a syntax error. I had the same issue. Make sure to use the real quotes like this ” and you should be fine.

I just fixed the post to remove the annoying smart quotes. It should be copy/pasteable now. Sorry about that. I usually have them turned off, but must have been editing the post from some other computer.

Thanks for the tutorial. I have a problem though:
After I entered the command “sudo service networking restart”, things are running nicely but then I get the message “can’t add wlan0 to bridge br0: Operation not supported”
I can’t find what I did wrong. Anyone knows how to fix that?

You could do some through the GUI like installing the packages and downloading files, but most of it should be done at the command line. I tried to make it as straight forward as possible for all experience levels, but I even get confused myself sometimes!

Hi, thank you for the tutorial. It just works! 🙂
Unfortunately it doesn’t do what I expected. I am connecting to a network that allows me to obtain only one IP address. Thus I want raspberry to obtain this IP address via ethernet and propagate the connection to my local wifi network. I wonder if it is possible? Could it be done with a slight modification of the above setup, or does it require a completely new approach? I understand it may extend a lot beyond this tutorial, but perhaps you could suggest me a direction where I should go?

Well the Pi hands out it’s own addresses because of dnsmasq, so as long as your Pi can get back to the Internet, the clients should be able to as well. Or are you saying you want the wireless client to have the single IP you mentioned?

The wireless interface is bridged with the ethernet port so they are essentially the same interface. It’s a bit confusing.

Yes, this is the problem, Raspberry takes one IP, and wireless device takes another. So I wanted Raspberry to connect to internet, and create a private wifi network with independent IPs. Now I understand that “bridge” is not exactly what I wanted. Anyway, I’m glad the tutorial worked smoothly.

Can you not use port forwarding to expose your network devices to the Internet? Why do you need independant IPs? It’s standard to have a single outward IP address, and multiple inward IP addresses for your network.

Yes, single outward IP and multiple inward addresses is what I want, but this is not how the solution described in this tutorial – unless I did something wrong.
The network I am connecting to allows me to obtain only one IP, probably due to technical limitations.

Is there a component here that will stop me sshing into my pi via a direct ethernet connection? When I set it up and try to ssh into my pi, it just times out.

It happened to me, as I restarted “networking”, actually it changed the eth0 ip. It might be your issue.

Hey Man, strange thing
I use a Raspberry Pi B, with Raspbian JESSIE Lite, downloaded on official link (Kernel v4.4)
I stopped just before the “Configure dnsmasq Settings” step (to see if i could connect to the RPi)
So, i can, and internet is working !

Here’s what i’ve done :
$ sudo apt-get install rfkill zd1211-firmware hostapd hostap-utils iw dnsmasq bridge-utils
-> success
$ lsusb
-> success
$ iw list
-> success
$ dmesg | grep rtl
$ sudo su
$ nano /etc/network/interfaces
$ ifdown wlan0
$ ifup wlan0
$ nano /etc/hostapd/hostapd.conf
$ nano /etc/default/hostapd
$ service networking restart
$ service hostapd restart

Then, taking phone (i don’t have 4G, or Mobile Data enabled), connecting to RPiAP, go Firefox, “”, and then redirected to, and i can now watch videos.

That’s strange uh ?

Hi… Now that I will have my pi as a router, can I run a webserver on the pi and access it from one of the connected clients?

How would I let devices on the pi’s network interact with each other? like being able to ssh from my laptop to a different pi on the network.

As long as you know the IP address and the two networks can talk to each other, there shouldn’t be an issue.

Is it possible to setup Raspberry Pi to connect to a WIFI with a usb dongle and connect to Raspberry Pi for Internet with my laptop via wired Ethernet?

Could you walk me through it? What equipment do I need? What do you think about ODROID? Is it better? How to I program it?

I don’t have time to do that, sorry. Part of the fun of the Pi is figuring things out on your own and experimenting.

Leave a Reply to 設定 Raspberry Pi 成為 3G Router 教學 | Focus Cancel reply