Use Raspberry Pi 3 As Router

53,442

102

36

About: Check out my YouTube channel, for similar projects.

According to Wikipedia, a router is a networking device that forwards data packets between computer networks. If we tear-down a wireless router, we will probably find an application specific processor that handles data packets and an RF segment that handles wireless connectivity.

You know what else has a processor and an RF segment.

THAT'S RIGHT a raspberry pi model 3. So in this miniProject, we will convert a raspberry pi to act as a router.

Supplies:

Step 1: Video

Take a look at video for quick comprehensive guide in 3 mins.

Step 2: Boot-up Raspberry Pi.

First step is to get your raspberry pi up and running. Official getting started guide on Raspberry pi website is best resource for this.

Here is the link.

Go to next step once you have your raspberry pi up and running.

Step 3: Upgrading Raspberry Pi

First we will update package list available from repositories using

sudo apt-get update 

Once done, we can install these latest packages using

sudo apt-get upgrade

This might take a while depending on your internet connection speed.

Step 4: Installing Hostadp and Bridge-utils

Once raspberry pi is upgraded.

we need to install a user space background process called hostapd, used for wireless access points and authentication servers. We will also need a package called bridge-utils to manage bridge devices.

sudo apt-get install hostapd bridge-utils

We need to turn off some of the new services that we just installed do it using

sudo systemctl stop hostapd

Debug- Some times raspbian will display message saying hostapd and bridge-utils not found for install command. Do not worry. Run 'sudo apt-get update' once more and it should get resolved.

Step 5: Disable DHCP Config for Wlan0 and Eth0

Now, we set dhcp background process not to automatically configure wlan0 and eth0 interfaces. We do this by putting following two lines

denyinterfaces wlan0
denyinterfaces eth0

at the end of /etc/dhcpcd.conf file, open it using.

sudo nano /etc/dhcpcd.conf

Step 6: Creating Bridge Br0

Next, we create a bridge br0 using brctl command which is an Ethernet bridge administrator

sudo brctl addbr br0

and using

sudo brctl addif br0 eth0

command we add eth0 as one of the ports for bridge br0.

Step 7: Edit /etc/network/interfaces

Now open up a file called interfaces in /etc/network directory

sudo nano /etc/network/interfaces

and add these five lines.

allow-hotplug wlan0
iface wlan0 inet manual

auto br0
iface br0 inet dhcp
bridge_ports eth0 wlan0

First line starts wlan0 interface on a hotplug event. Second line creates a network interface without an IP address which is normally done for bridge elements. Third line starts br0 interface on boot up. Forth line helps in automatic assignment of IP address to br0 interface using DHCP server and finally fifth line connects eth0 interface with wlan0. Save this file and close it.

Step 8: Edit /etc/hostapd/hostapd.conf

Next, we will configure our wireless access point, we can do this using a file called hostapd.conf in /etc/hostapd folder. Open it up

sudo nano /etc/hostapd/hostapd.conf

and paste these lines.

interface=wlan0
bridge=br0
ssid=miniProjects
hw_mode=g
channel=7
wmm_enabled=0
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=subscribe
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Value assigned to ssid is the name that access point will use to broadcast its existence. Last five lines are focused on authentication and security of access point. Value of wpa_passsphrase is used as login password which is subscribe in our case. This is a link to document, where you can find definition of each variable that we have used here.

Step 9: Final Edit /etc/default/hostapd

Finally, open up hostapd file in /etc/default directory

sudo nano /etc/default/hostapd

uncomment DAEMON_CONF line and provide path to file we just created.

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

This completes setup for raspberry pi to act as router.

Step 10: Done

Now, power-on your raspberry pi with Ethernet cable connected.

You should see raspberry pi broadcasting ssid and access internet.

Thanks for reading.

Let me know if you face any issue while creating your own router.

Please vote for this instructable, if you liked it.

Share

    Recommendations

    • Gardening Contest

      Gardening Contest
    • Colors of the Rainbow Contest

      Colors of the Rainbow Contest
    • IoT Challenge

      IoT Challenge

    36 Discussions

    0
    None
    MatthewD250

    6 months ago

    This is awesome, but I was wondering about things: 1.What is the boot up time 2. Instead of re-reouting the data packets, could the input data into audio output? Application would be to stream audio, specially airplay. No single device exist to accomplish this, aside from expensive head units.

    I have been hitting a brick wall wall for the past 2 years in finding a device I can airplay to without using a wifi network or using my phone as a hotspot (kills my battery especially when streaming music). Another huge plus is that there exist quite a few high quality raz pi audio components to get high quality sound.

    I would think the hardest part would just be redirecting input into the open source software, Shairport Sync. If your interested a posted a tutorial for creating ras-pi airplay receiver.
    https://pimylifeup.com/raspberry-pi-airplay-receiv...

    I'm not sure if one raspberry pi could handle both processes, but if two were needed I suppose I would want to port the wifi pi output via eithernet to the audio processor pi.

    2 replies
    0
    None
    TitusR4MatthewD250

    Reply 17 days ago

    Apple TV? They also used to sell a router with a speaker port.

    0
    None
    ThomasdudeMatthewD250

    Reply 6 months ago

    Hello MatthewD250,
    Bootup time is extremely short. This is part of the basic Linux-settings after all, so it should boot about as fast as linux itself does.

    As far as streaming audio goes - these would still be data packets, right? It would still use TCP/IP to transfer those packets using this setup...

    I'd check if Shairport Sync has some kind of listener you can direct the input towards - that might encode the output in the correct way somehow.

    Let me know if you find something, it sounds really cool if you could pull it off!

    0
    None
    mohammed645415

    Question 22 days ago

    I connect the Eth cable betwen laptop and raspberry, and I can't see the ssid by raspberry, is it the cable connection?? And should be relly internet???

    0
    None
    IbrahimK44

    Question 6 weeks ago

    Please help! I am a noob sadly, I followed the instrucs to a tee, (except changed the SSID name and password). Itrebooted and there is noi SSID at all. It failed completely. Dont know what to look for...

    1 answer
    0
    None
    crisley00IbrahimK44

    Answer 23 days ago

    Have you tried running the command sudo systemctl start hostapd? If so, do you get an error "Failed to start hostapd.service: Unit hostapd.service is masked."?

    0
    None
    IlyaL1

    23 days ago

    I got the access point to work, but there is one problem. When trying to connect, it's stuck at obtaining IP adress, what does that mean?

    0
    None
    tdannecy

    Question 27 days ago

    I love that case you had in the title image. Where can I get one of those?

    1 answer
    0
    None
    miniProjectstdannecy

    Answer 27 days ago

    It's official raspberry pi 3 case. You should be able to get it from any official outlet. If my memory is not failing me I bought it on Amazon.

    0
    None
    RobertL282

    Question 6 weeks ago on Step 10

    Can I use an extra wlan port to make this wireless? How do I bridge from wlan0 to wlan 1

    0
    None
    mannumx01

    2 months ago

    all very well until you get to the topic of internet access. If you do not correct the DNSs you will never have Internet access.. keep in main.
    0
    None
    BenHarp

    Question 3 months ago on Step 10

    I lose connection to the internet when I plug in the ethernet cable. What should I do?

    0
    None
    janbenes

    Question 3 months ago

    Hello! I am able to run AP. I would like to know how to find the IP address of AP, so I can ssh to it. Also how do I know IP addresses of other device connected via WiFi to Raspberry AP? DHCP leased addresses? Thanks, Jan

    0
    None
    Jacobs02

    3 months ago

    Ist a WLAN-Bridge not a Router...

    1
    None
    JayeshS3

    Tip 8 months ago

    I had a problem with the command
    - sudo brctl addbr br0

    It returned the error

    - sudo brctl addbr br0 add bridge failed: package not installed

    To avoid fix this issue I reinstalled raspian and I did a reboot after step 4

    Hopefully this helps somebody avoid the issue I faced :)

    1 reply
    0
    None
    skischlumpfJayeshS3

    Reply 3 months ago

    I had the same problem running the raspbian jessie image. After flashing raspbian stretch, the issue was solved!

    0
    None
    andr3w2

    Question 3 months ago

    Hi guys, can anyone help me?...I m becoming crazy!!!
    I first followed the steps to configure the PI3 as an access point (there are a series of extra commands...) and then the procedure above.
    In the end, however, I can not navigate.
    Indeed if in the first case I saw blinking the two arrows and recognized the interfaces now instead the two arrows of the connection are barred, with dhcpcd lost and no wireless interface.
    I have re-checked everything, I can make further changes only on hostapd.conf, but I left the standard values on non-personal parameters.

    0
    None
    dreedx2

    Question 3 months ago

    I've had my pirouter running for a few months. My isp router is on the 2nd floor and now I have a strong signal downstairs. I would like to get more signal in my back yard... My questions are: 1 Can you recommend a hi-gain usb antenna compatible with RPi for this project. 2 Can I edit my existing Setup for what I presume would be a change from Wlan0 to Wlan1? Or do I need to redo my original setup substituting Wlan0 for Wlan1 at each step? Thanks for the original project and any help you can add for my update.

    0
    None
    JasonB586

    3 months ago

    the instructions are great, except for one significant item. What you have described is NOT a Router, it's a Bridge. It would be great if you could change the title, just in case people follow your instructions expecting to end up with a Router, and then get confused, or even locked out of their Pi because it's a Bridge. Perhaps 9 out of 10 people don't care because both a Bridge and a Router will do the same job of connecting WiFi to Ethernet. However, some of us specifically want to create 2 discrete subnets, and following your instructions would make that very difficult to achieve.

    0
    None
    enpboss

    4 months ago

    I have made it, Wi-Fi is working fine, but locally while trying to install some updates (apt-get update ) no internet access ,i have tried with browser also