{"id":129,"date":"2018-07-22T05:04:06","date_gmt":"2018-07-22T10:04:06","guid":{"rendered":"https:\/\/blog.qianyurui.com\/?p=129"},"modified":"2021-02-19T12:30:07","modified_gmt":"2021-02-19T20:30:07","slug":"use-raspberry-pi-as-router-with-pppoe","status":"publish","type":"post","link":"https:\/\/blog.qianyurui.com\/index.php\/2018\/07\/22\/use-raspberry-pi-as-router-with-pppoe\/","title":{"rendered":"Use Raspberry Pi as Router with PPPoE"},"content":{"rendered":"<p><a href=\"https:\/\/blog.qianyurui.com\/index.php\/2018\/07\/22\/raspirouter\/\">\u4e2d\u6587\u7248\u5728\u8fd9\u91cc<\/a><\/p>\n<p>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\u00a0<a href=\"https:\/\/medium.com\/@edoardo849\/turn-a-raspberrypi-3-into-a-wifi-router-hotspot-41b03500080e\">Turn a RaspBerryPi 3 into a WiFi router-hotspot<\/a>.<\/p>\n<p>The Raspi I used is a Raspberry Pi 3 Model B. I expect Model B+ and Zero W to work but I didn&#8217;t test. If you are using an older version of Raspi you might need a wifi dongle.<\/p>\n<p>First thing first, let&#8217;s make sure the Raspi can connect to the Internet with PPPoE. Download pppoeconf from <a href=\"https:\/\/packages.debian.org\/stretch\/all\/pppoeconf\/download\">here<\/a>, and install it with <code>sudo dpkg -i pppoeconf_1.21_all.deb<\/code>. Now connect the Ethernet cable to Raspi and open pppoeconf with\u00a0<code>sudo pppoeconf<\/code>. Follow the instruction and by the end you should be able to access the Internet.<\/p>\n<p>Now let&#8217;s set up DHCP. Feel free to change the parameters like IP address or DNS in the following code if you know what&#8217;s going on, otherwise you can safely copy&amp;paste all the code here to proceed. Execute the following command<\/p>\n<pre>sudo apt-get update\nsudo apt-get dist-upgrade\nsudo apt-get install hostapd isc-dhcp-server\nsudo nano \/etc\/dhcp\/dhcpd.conf<\/pre>\n<p>Comment these two lines:<\/p>\n<pre>option domain-name \"example.org\";\noption domain-name-servers ns1.example.org, ns2.example.org;<\/pre>\n<p>Uncomment this line:<\/p>\n<pre>#authoritative;<\/pre>\n<p>Copy and paste the following code to the end of the file:<\/p>\n<pre>subnet 192.168.42.0 netmask 255.255.255.0 {\nrange 192.168.42.10 192.168.42.50;\noption broadcast-address 192.168.42.255;\noption routers 192.168.42.1;\ndefault-lease-time 600;\nmax-lease-time 7200;\noption domain-name \"local\";\noption domain-name-servers 8.8.8.8, 8.8.4.4;\n}<\/pre>\n<p>press ctrl+x to exit, y to save and enter to confirm.<\/p>\n<pre>sudo nano \/etc\/default\/isc-dhcp-server<\/pre>\n<p>Change INTERFACES=&#8221;&#8221; to INTERFACES=&#8221;wlan0&#8243;. Save&amp;exit.<\/p>\n<pre>sudo ifdown wlan0\nsudo nano \/etc\/network\/interfaces<\/pre>\n<p>Add the following lines to the end:<\/p>\n<pre>auto lo\niface lo inet loopback\niface eth0 inet dhcp\nallow-hotplug wlan0\niface wlan0 inet static\naddress 192.168.42.1\nnetmask 255.255.255.0\npost-up iw dev $IFACE set power_save off<\/pre>\n<p>Save&amp;exit.<\/p>\n<p>Configure ip of the router:<\/p>\n<pre>sudo ifconfig wlan0 192.168.42.1<\/pre>\n<p>DHCP setting is done. Time to handle wifi.<\/p>\n<pre>sudo nano \/etc\/hostapd\/hostapd.conf<\/pre>\n<p>Add the following lines to the file:<\/p>\n<pre>interface=wlan0\nssid=RaspiPoweredWifi #change to name of your wifi\nhw_mode=g\nchannel=6 #change to others if you know what you are doing\nmacaddr_acl=0\nauth_algs=1\nignore_broadcast_ssid=0\nwpa=2\nwpa_passphrase=12345678 #change to your wifi password\nwpa_key_mgmt=WPA-PSK\nwpa_pairwise=TKIP\nrsn_pairwise=CCMP<\/pre>\n<p>Save&amp;exit. Now we can set up forwarding<\/p>\n<pre>sudo nano \/etc\/sysctl.conf<\/pre>\n<p>Jump to the very end and add:<\/p>\n<pre>net.ipv4.ip_forward=1<\/pre>\n<p>Save&amp;exit.<br \/>\nSet up iptables:<\/p>\n<pre>sudo sh -c \"echo 1 &gt; \/proc\/sys\/net\/ipv4\/ip_forward\"\nsudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE\nsudo iptables -A FORWARD -i eth0 -o wlan0 -m state --state RELATED,ESTABLISHED -j ACCEPT\nsudo iptables -A FORWARD -i wlan0 -o eth0 -j ACCEPT<\/pre>\n<p>Add to startup:<\/p>\n<pre>sudo sh -c \"iptables-save &gt; \/etc\/iptables.ipv4.nat\"\nsudo nano \/etc\/network\/interfaces<\/pre>\n<p>Go to the end and add:<\/p>\n<pre>up iptables-restore &lt; \/etc\/iptables.ipv4.nat<\/pre>\n<p>Save&amp;exit.<br \/>\nStart two services:<\/p>\n<pre>sudo service hostapd start\nsudo service isc-dhcp-server start<\/pre>\n<p>Reboot. Mission accomplished.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e2d\u6587\u7248\u5728\u8fd9\u91cc 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 &hellip; <\/p>\n<p class=\"link-more\"><a href=\"https:\/\/blog.qianyurui.com\/index.php\/2018\/07\/22\/use-raspberry-pi-as-router-with-pppoe\/\" class=\"more-link\">Continue reading<span class=\"screen-reader-text\"> &#8220;Use Raspberry Pi as Router with PPPoE&#8221;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-129","post","type-post","status-publish","format-standard","hentry","category-tech"],"_links":{"self":[{"href":"https:\/\/blog.qianyurui.com\/index.php\/wp-json\/wp\/v2\/posts\/129","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qianyurui.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qianyurui.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qianyurui.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qianyurui.com\/index.php\/wp-json\/wp\/v2\/comments?post=129"}],"version-history":[{"count":6,"href":"https:\/\/blog.qianyurui.com\/index.php\/wp-json\/wp\/v2\/posts\/129\/revisions"}],"predecessor-version":[{"id":256,"href":"https:\/\/blog.qianyurui.com\/index.php\/wp-json\/wp\/v2\/posts\/129\/revisions\/256"}],"wp:attachment":[{"href":"https:\/\/blog.qianyurui.com\/index.php\/wp-json\/wp\/v2\/media?parent=129"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qianyurui.com\/index.php\/wp-json\/wp\/v2\/categories?post=129"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qianyurui.com\/index.php\/wp-json\/wp\/v2\/tags?post=129"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}