Use Raspberry Pi as Router with PPPoE

中文版在这里

The router at my home has been troubled by the high temperature during summer days, and its performance has brought me headaches whenever I needed smooth network. Raspberry Pi is a robust mini-computer and I soon committed to the idea to turn a Raspi 3 into my new router. After 8-hour trial-and-error I finally managed to make it work on a PPPoE network and hence would like to share my experience. The following tutorial is largely based on Turn a RaspBerryPi 3 into a WiFi router-hotspot.

The Raspi I used is a Raspberry Pi 3 Model B. I expect Model B+ and Zero W to work but I didn’t test. If you are using an older version of Raspi you might need a wifi dongle.

First thing first, let’s make sure the Raspi can connect to the Internet with PPPoE. Download pppoeconf from here, and install it with sudo dpkg -i pppoeconf_1.21_all.deb. Now connect the Ethernet cable to Raspi and open pppoeconf with sudo pppoeconf. Follow the instruction and by the end you should be able to access the Internet.Execute the following command

sudo apt-get update
sudo apt-get dist-upgrade
sudo apt-get install hostapd isc-dhcp-server
sudo nano /etc/dhcp/dhcpd.conf

Comment these two lines:

option domain-name "example.org";
option domain-name-servers ns1.example.org, ns2.example.org;

Uncomment this line:

#authoritative;

Copy and paste the following code to the end of the file:

subnet 192.168.42.0 netmask 255.255.255.0 {
range 192.168.42.10 192.168.42.50;
option broadcast-address 192.168.42.255;
option routers 192.168.42.1;
default-lease-time 600;
max-lease-time 7200;
option domain-name "local";
option domain-name-servers 8.8.8.8, 8.8.4.4;
}

press ctrl+x to exit, y to save and enter to confirm.

sudo nano /etc/default/isc-dhcp-server

Change INTERFACES=”” to INTERFACES=”wlan0″. Save&exit.

sudo ifdown wlan0
sudo nano /etc/network/interfaces

Add the following lines to the end:

auto lo
iface lo inet loopback
iface eth0 inet dhcp
allow-hotplug wlan0
iface wlan0 inet static
address 192.168.42.1
netmask 255.255.255.0
post-up iw dev $IFACE set power_save off

Save&exit. Set ip of the router:

sudo ifconfig wlan0 192.168.42.1

DHCP setting is done. Time to handle wifi.

sudo nano /etc/hostapd/hostapd.conf

Add the following lines to the file:

interface=wlan0
ssid=RaspiPoweredWifi #change to name of your wifi
hw_mode=g
channel=6 #change to others if you know what you are doing
macaddr_acl=0
auth_algs=1
ignore_broadcast_ssid=0
wpa=2
wpa_passphrase=12345678 #change to your wifi password
wpa_key_mgmt=WPA-PSK
wpa_pairwise=TKIP
rsn_pairwise=CCMP

Save&exit. Now we can set up forwarding

sudo nano /etc/sysctl.conf

Jump to the very end and add:

net.ipv4.ip_forward=1

Save&exit.
Set up iptables:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE
sudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT
sudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT

Add to startup:

sudo sh -c "iptables-save > /etc/iptables.ipv4.nat"
sudo nano /etc/network/interfaces

Go to the end and add:

up iptables-restore < /etc/iptables.ipv4.nat

Save&exit.
Start two services:

sudo service hostapd start
sudo service isc-dhcp-server start

Reboot. Mission accomplished.

3 Replies to “Use Raspberry Pi as Router with PPPoE”

    1. Sorry I didn’t see your comments earlier. There was an issue with WordPress comment function that I just noticed… If anyone else has encountered the similar error as the services couldn’t be started, make sure you have both hostapd and isc-dhcp-server successfully installed. Try rebooting the machine then starting the services. If it still doesn’t work, feel free to comment under this thread and I’ll try my best to troubleshoot for you.

Leave a Reply

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