{"id":675,"date":"2021-10-14T00:09:54","date_gmt":"2021-10-13T22:09:54","guid":{"rendered":"https:\/\/blog.chloesoe.ch\/?p=675"},"modified":"2021-10-26T00:31:19","modified_gmt":"2021-10-25T22:31:19","slug":"openvpn-for-your-pihole","status":"publish","type":"post","link":"https:\/\/blog.chloesoe.ch\/?p=675","title":{"rendered":"OpenVPN for Your PiHole"},"content":{"rendered":"<h1>Goal<\/h1>\n<p>PiHole only available via OpenVPN<\/p>\n<h1>Steps to Achieve<\/h1>\n<p>Install OpenVPN on PiHole server according to <a href=\"https:\/\/ubuntu.com\/server\/docs\/service-openvpn\">https:\/\/ubuntu.com\/server\/docs\/service-openvpn<\/a><\/p>\n<p>At <a href=\"https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-set-up-an-openvpn-server-on-ubuntu-16-04\">https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-set-up-an-openvpn-server-on-ubuntu-16-04<\/a> you find a hint, how to set up a client config script.<\/p>\n<p>create a file <code>\/etc\/openvpn\/client\/make_config.sh<\/code> on the server, below the adjusted to the current ubuntu configuration with easy-rsa<\/p>\n<pre><code>#!\/bin\/bash\n\n# First argument: Client identifier\n\nOPENVPNDIR=\/etc\/openvpn\n\nKEY_DIR=$OPENVPNDIR\/easy-rsa\/pki\nOUTPUT_DIR=$OPENVPNDIR\/client\/files\nBASE_CONFIG=$OPENVPNDIR\/client\/base.conf\n\ncat ${BASE_CONFIG} \\\n    &lt;(echo -e &#039;&lt;ca&gt;&#039;) \\\n    ${KEY_DIR}\/ca.crt \\\n    &lt;(echo -e &#039;&lt;\/ca&gt;\\n&lt;cert&gt;&#039;) \\\n    ${KEY_DIR}\/issued\/${1}.crt \\\n    &lt;(echo -e &#039;&lt;\/cert&gt;\\n&lt;key&gt;&#039;) \\\n    ${KEY_DIR}\/private\/${1}.key \\\n    &lt;(echo -e &#039;&lt;\/key&gt;\\n&lt;tls-auth&gt;&#039;) \\\n    ${OPENVPNDIR}\/ta.key \\\n    &lt;(echo -e &#039;&lt;\/tls-auth&gt;&#039;) \\\n    &gt; ${OUTPUT_DIR}\/${1}.ovpn<\/code><\/pre>\n<p>Then you can run <code>\/etc\/openvpn\/client\/make_config.sh CLIENTNAME<\/code> and you get a ovpn file in <code>\/etc\/openvpn\/client\/files\/<\/code><\/p>\n<p>You now can import that in your NetworkManager. The good old resolv.conf does not work, so you can add the IP address 10.8.0.1 of the VPN server as DNS in theconfiguration, where the pihole is running.<\/p>\n<h1>Add iptable rules<\/h1>\n<p>We have to block the external interface in the chain DOCKER-USER, see <a href=\"https:\/\/docs.docker.com\/network\/iptables\/\">https:\/\/docs.docker.com\/network\/iptables\/<\/a>. <\/p>\n<p>With these commands you can successful block everything, except port 80 from outside (for letsencrypt) and everything in the network 10.8.0.1\/24 (openVPN)<\/p>\n<pre><code>sudo iptables -I DOCKER-USER -i ens3 ! -s 10.8.0.1\/24 -j DROP\nsudo iptables -I DOCKER-USER -i ens3 -m comment --comment &quot;Accept all connections from VPN to Docker - Drop all other&quot; ! -s 10.8.0.1\/24 -j DROP\nsudo iptables -I DOCKER-USER -i ens3 -p tcp --dport 80 -m comment --comment &quot;Accept HTTP for letsencrypt&quot; -j ACCEPT\n\n# block all IPv6 traffic except 80 for letsencrypt and 22 for ssh\nsudo ip6tables -A INPUT -p tcp --dport 80 -j ACCEPT\nsudo ip6tables -A INPUT -p tcp --dport 22 -j ACCEPT\nsudo ip6tables -A INPUT -j DROP\n<\/code><\/pre>\n<p>Save them (<code>iptables-persistent<\/code> must be installed):<\/p>\n<pre><code>iptables-save &gt; \/etc\/iptables\/rules.v4\nip6tables-save &gt; \/etc\/iptables\/rules.v6<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Goal PiHole only available via OpenVPN Steps to Achieve Install OpenVPN on PiHole server according to https:\/\/ubuntu.com\/server\/docs\/service-openvpn At https:\/\/www.digitalocean.com\/community\/tutorials\/how-to-set-up-an-openvpn-server-on-ubuntu-16-04 you find a hint, how to set up a client config script. create a file \/etc\/openvpn\/client\/make_config.sh on the server, below the adjusted to the current ubuntu configuration with easy-rsa #!\/bin\/bash # First argument: Client identifier OPENVPNDIR=\/etc\/openvpn&#8230; <a href=\"https:\/\/blog.chloesoe.ch\/?p=675\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">OpenVPN for Your PiHole<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[10,7],"tags":[],"class_list":["post-675","post","type-post","status-publish","format-standard","hentry","category-it-sec","category-linux"],"_links":{"self":[{"href":"https:\/\/blog.chloesoe.ch\/index.php?rest_route=\/wp\/v2\/posts\/675","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.chloesoe.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.chloesoe.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.chloesoe.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.chloesoe.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=675"}],"version-history":[{"count":6,"href":"https:\/\/blog.chloesoe.ch\/index.php?rest_route=\/wp\/v2\/posts\/675\/revisions"}],"predecessor-version":[{"id":682,"href":"https:\/\/blog.chloesoe.ch\/index.php?rest_route=\/wp\/v2\/posts\/675\/revisions\/682"}],"wp:attachment":[{"href":"https:\/\/blog.chloesoe.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.chloesoe.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.chloesoe.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}