{"id":3,"date":"2016-04-16T17:34:51","date_gmt":"2016-04-16T21:34:51","guid":{"rendered":"http:\/\/energychaser.com\/blog\/?p=3"},"modified":"2017-01-17T13:17:59","modified_gmt":"2017-01-17T18:17:59","slug":"raspberry-pi-vpn-server","status":"publish","type":"post","link":"https:\/\/blog.energychaser.com\/?p=3","title":{"rendered":"Raspberry Pi VPN server"},"content":{"rendered":"<p>I was looking for a way to make a Raspberry Pi into a VPN Gateway for my home network.<\/p>\n<p>This solution started with this page: https:\/\/gist.github.com\/superjamie\/ac55b6d2c080582a3e64<\/p>\n<p>Change \/etc\/network\/interfaces to suit your networking configuration:<br \/>\nauto lo<br \/>\niface lo inet loopback<\/p>\n<p>auto eth0<br \/>\nallow-hotplug eth0<br \/>\niface eth0 inet static<br \/>\naddress 192.168.1.2<br \/>\nnetmask 255.255.255.0<br \/>\ngateway 192.168.1.1<br \/>\ndns-nameservers 8.8.8.8 8.8.4.4<\/p>\n<p>Then SSH in and install a VPN client. I use OpenConnect:\u00a0http:\/\/www.infradead.org\/openconnect\/<\/p>\n<p>root#: apt-get install openconnect<\/p>\n<h2>Setup Routing and NAT<\/h2>\n<p>Enable IP Forwarding:<\/p>\n<pre><code>echo -e '\\n#Enable IP Routing\\nnet.ipv4.ip_forward = 1' | sudo tee -a \/etc\/sysctl.conf\r\nsudo sysctl -p\r\n<\/code><\/pre>\n<p>Setup NAT fron the local LAN down the VPN tunnel:<\/p>\n<pre><code>sudo iptables -t nat -A POSTROUTING -o tun0 -j MASQUERADE\r\nsudo iptables -A FORWARD -i tun0 -o eth0 -m state --state RELATED,ESTABLISHED -j ACCEPT\r\nsudo iptables -A FORWARD -i eth0 -o tun0 -j ACCEPT\r\n<\/code><\/pre>\n<p>Make the NAT rules persistent across reboot:<\/p>\n<pre><code>sudo apt-get install iptables-persistent\r\n<\/code><\/pre>\n<p>The installer will ask if you want to save current rules, select <strong>Yes<\/strong><\/p>\n<p>If you don&#8217;t select yes, that&#8217;s fine, you can save the rules later with <code>sudo netfilter-persistent save<\/code><\/p>\n<p>Make the rules apply at startup:<\/p>\n<pre><code>sudo systemctl enable netfilter-persistent\r\n\r\nOlder system (Wheezy) may need: sudo dpkg-reconfigure iptables-persistent<\/code><\/pre>\n<h2>Configure Other Systems on the LAN<\/h2>\n<p>Now we&#8217;re ready to tell other systems to send their traffic through the Raspberry Pi.<\/p>\n<p>Configure other systems&#8217; network so they are like:<\/p>\n<ul>\n<li>Default Gateway: Pi&#8217;s static IP address (eg: <code>192.168.1.2<\/code>)<\/li>\n<li>DNS: Something public like Google DNS (<code>8.8.8.8<\/code> and <code>8.8.4.4<\/code>)<\/li>\n<\/ul>\n<p>Don&#8217;t use your existing internet router (eg: <code>192.168.1.1<\/code>) as DNS, or your DNS queries will be visible to your ISP and hence may be visible to organizations who wish to see your internet traffic.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was looking for a way to make a Raspberry Pi into a VPN Gateway for my home network. This solution started with this page: https:\/\/gist.github.com\/superjamie\/ac55b6d2c080582a3e64 Change \/etc\/network\/interfaces to suit your networking configuration: auto lo iface lo inet loopback auto &hellip; <a href=\"https:\/\/blog.energychaser.com\/?p=3\">Continue reading <span class=\"meta-nav\">&rarr;<\/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":[1],"tags":[],"class_list":["post-3","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/blog.energychaser.com\/index.php?rest_route=\/wp\/v2\/posts\/3","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.energychaser.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.energychaser.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.energychaser.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.energychaser.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3"}],"version-history":[{"count":4,"href":"https:\/\/blog.energychaser.com\/index.php?rest_route=\/wp\/v2\/posts\/3\/revisions"}],"predecessor-version":[{"id":9,"href":"https:\/\/blog.energychaser.com\/index.php?rest_route=\/wp\/v2\/posts\/3\/revisions\/9"}],"wp:attachment":[{"href":"https:\/\/blog.energychaser.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.energychaser.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.energychaser.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}