Use Raspberry Pi 3 As Router

171,177

144

63

Introduction: Use Raspberry Pi 3 As Router

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.

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.

Pocket-Sized Contest

Participated in the
Pocket-Sized Contest

Microcontroller Contest

Participated in the
Microcontroller Contest

Be the First to Share

    Recommendations

    • Fruit and Veggies Speed Challenge

      Fruit and Veggies Speed Challenge
    • Summer Fun: Student Design Challenge

      Summer Fun: Student Design Challenge
    • Fandom Contest

      Fandom Contest

    63 Comments

    0
    AbhiR38
    AbhiR38

    Question 8 weeks ago on Introduction

    Internet in not available on this network is shown when I tried to conect with my raspberry router

    0
    KalibyrTech
    KalibyrTech

    4 months ago on Step 1

    It would appear that this tutorial is due for a rewrite. Alot of people hear do not realize that the eth0 is being bridge to wlan0 so that it can be broadcast with hostapd. Other people are having trouble with just getting this to connect or even showing up as a connectable device on there phones. This would mostly be due to older phones or phones with greater security. Some devices such as samsungs try to prevent insecure connection. I will start looking into fixes. But I suggest that anybody who comes by and finds that the internet is not working to reinstall the os and try again from scratch. This tutorial is not wrong and it should work. For all of the people saying that they are losing internet connection because `DHCP connection has been lost` are not realizing that you still have internet access. As a fact, I'm writing this on my RPi3b+ and I have the same error but I'm still connected to the internet. You all must experiement to learn more. I will work on rewriting this tutorial myself with due credit to the author.

    Happy Programming :)

    0
    xianwu.luo
    xianwu.luo

    1 year ago

    finished every steps. reboot.
    use my tablet , try to find the wifi ssid, "miniProjects" .
    did not find it. anyone else has this issue?
    thx

    0
    McJoshuaGaming
    McJoshuaGaming

    1 year ago

    When I try and connect it says "can not connect, please check password and retry, but I'm using the correct password

    0
    FordS2
    FordS2

    1 year ago

    I came here looking for a router, but found a bridge :'(

    0
    dbanttari
    dbanttari

    Reply 1 year ago

    I haven't tried yet to do this, but it looks like it's bridging eth0 (local LAN) and wifi. eth1 should be the upstream Internet connection...er ... nope, you're correct. This is just a wifi bridge, not a router at all. Damn

    0
    jeanfrancois.d
    jeanfrancois.d

    1 year ago

    Just use OpenWRT. Push it on your Pi. Have fun.

    0
    webtop
    webtop

    Reply 1 year ago

    I think you need to be a little more detailed in your answer For example: how does OpenWRT replace this method?

    0
    mohammed645415
    mohammed645415

    Question 2 years 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
    webtop
    webtop

    Answer 1 year ago

    Yes, the eth0 is the connection from the RPi to the modem (ISP box). You should then see a new WiFi point to connect to, same as the one you named in the SSID field in the hostapd.conf file.
    This will allow the RPi to collect the data packets and pass then onto whatever is connected to the WiFi.

    0
    WillemNorval
    WillemNorval

    1 year ago

    I followed every instruction to the T. No luck.
    Somewhere there was code involving a Mac. I'm not working on a Mac.
    Does it matter ?

    0
    webtop
    webtop

    Reply 1 year ago

    Mac !== MAC

    0
    CameronJ21
    CameronJ21

    Reply 1 year ago

    Not that kind of Mac, but a MAC address. It's used to connect to the internet.

    0
    downloadrid
    downloadrid

    1 year ago

    not working not found any ssid :'(. now my wifi is not working anymore

    0
    EthicHacker1428
    EthicHacker1428

    Reply 1 year ago

    If you haven't fixed that then just open the nano file /etc/dhcpcd.conf and remove denyinterfaces command

    0
    EdoardoM
    EdoardoM

    1 year ago on Step 9

    Not working, no connection with eth0 no wifi

    0
    lynngflys1
    lynngflys1

    Question 1 year ago

    If I plugged a USB drive into this, could I transfer files wirelessly to and from other devices?

    0
    IlyaL1
    IlyaL1

    2 years 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
    tass46
    tass46

    Reply 1 year ago

    Same problem here.
    Have you found any solution ?