Configuring OpenVPN for adblocking.

Need help configuring your VPN? Just post here and you'll get that help.

Moderators: TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech, TinCanTech

Forum rules
Please use the [oconf] BB tag for openvpn Configurations. See viewtopic.php?f=30&t=21589 for an example.
Post Reply
anudeep
OpenVpn Newbie
Posts: 6
Joined: Mon Jan 16, 2017 2:49 pm

Configuring OpenVPN for adblocking.

Post by anudeep » Mon Jan 16, 2017 2:57 pm

Hi,
This is my first post here, I'm a beginner so bear with me! :)
I have an adblocking server running on raspberry pi 3. It's called 'pihole'. I love the project. In a nutshell it doesn't resolve the ad serving domains. So when I have this on my home network and works fine. But I want it to work when I'm away from home. So I need VPN.

Firstly I want both of them to run on the same computer. I want help to set up OpenVPN and configure OpenVPN's DNS server as my pihole. I don't know how to make it work together. Please help.

SomeGuy
OpenVPN Power User
Posts: 64
Joined: Sat Dec 17, 2016 1:58 am

Re: Configuring OpenVPN for adblocking.

Post by SomeGuy » Mon Jan 16, 2017 3:32 pm

For your server configs, check out options "redirect-gateway" with its options, depending on how you want your traffic to be passed, and for DNS read about option "dhcp-option" (specifically "DNS" under "dhcp-option")

Reading how to use those options should help you to get what you want.

anudeep
OpenVpn Newbie
Posts: 6
Joined: Mon Jan 16, 2017 2:49 pm

Re: Configuring OpenVPN for adblocking.

Post by anudeep » Tue Jan 17, 2017 6:01 am

I don't want route all web traffic to OpenVPN only the DNS queries, adblocking is only my intention.
Is this the right command-push "dhcp-option DNS 10.8.0.1?
Since both pihole and OpenVPN is running on same machine, setting up it's static IP as DNS server of VPN can cause problems?

Also I want to install OpenVPN using piVPN since it is easy, what do you say about this?
www.pivpn.io

SomeGuy
OpenVPN Power User
Posts: 64
Joined: Sat Dec 17, 2016 1:58 am

Re: Configuring OpenVPN for adblocking.

Post by SomeGuy » Tue Jan 17, 2017 10:50 am

anudeep wrote:I don't want route all web traffic to OpenVPN only the DNS queries, adblocking is only my intention.
Is this the right command-push "dhcp-option DNS 10.8.0.1?
Since both pihole and OpenVPN is running on same machine, setting up it's static IP as DNS server of VPN can cause problems?
So, if you only plan to rely on DNS lookup over the VPN, then the server config of:

Code: Select all

push "dhcp-option DNS 10.8.0.1"
This assumes that the IP address "10.8.0.1" is reachable by your openvpn clients that connect.
If that IP address is not immediately reachable by OpenVPN clients that connect, then you may also need to push routes, and/or check your network filtering rules and routing rules on the OpenVPN Server.
After you have a working OpenVPN Server config, you would then connect to it using a working OpenVPN client, and then you would then test your DNS lookup over the VPN link.
With *nix, there is "dig" and "nslookup" (check the man pages on how to specify a *specific* DNS server you want to use to resolve a name when testing)
If Windows is your client, then in a "cmd" shell try "nslookup /?" to see how to use that to query a specific DNS Server by IP.
For Android, there are many tools. Find your own, or consider one like the app from "Hurricane Electric" (HE.net) called "Network Tools" but it is not the only one.

Once you have DNS lookups working over the working VPN Link, then you will need to check your OS configuration to see if the DNS Setting pushed replaced all of your other DNS Server IP address, or was just appended added to an existing list.

Once that is working, look into the options "block-outside-dns" and "register-dns" if your OpenVPN client is running on a supported Windows OS. (Other considerations for Windows include possible leaks for resolution of a name to an IP address through a WINS Server, which may be pushed by DHCP to a Windows OS.)

If you are using something else as a client, then you may have more work to ensure that client uses the pushed DNS server and only that pushed DNS Server.

Then, after all of the above, you will probably want to check your work to make sure that DNS lookups are not leaking through any other DNS Services. You can use a packet capture tool, and specify that you only want to collect packets to/from a name resolution protocol service port that do not include your OpenVPN DNS Server IP address as the source or destination. (It is often good to test and confirm your goals are met by the the plan intended.)
Also I want to install OpenVPN using piVPN since it is easy, what do you say about this?
http://www.pivpn.io
I have not used that, and have nothing to comment about its use.

anudeep
OpenVpn Newbie
Posts: 6
Joined: Mon Jan 16, 2017 2:49 pm

Re: Configuring OpenVPN for adblocking.

Post by anudeep » Tue Jan 17, 2017 3:31 pm

The reason I want to route only DNS queries is I'm on a limited data plan on home (where OpenVPN is located) so default routing option can use more data? If it's not I will not change any settings. Can you please explain what will be the data usage by VPN and how it will be calculated?

SomeGuy
OpenVPN Power User
Posts: 64
Joined: Sat Dec 17, 2016 1:58 am

Re: Configuring OpenVPN for adblocking.

Post by SomeGuy » Tue Jan 17, 2017 9:41 pm

anudeep wrote:The reason I want to route only DNS queries is I'm on a limited data plan on home (where OpenVPN is located) so default routing option can use more data?
For average use of the Internet, tunnelling all traffic through the VPN with a remote client will use more network data than just tunnelling DNS requests.
If it's not I will not change any settings. Can you please explain what will be the data usage by VPN and how it will be calculated?
Relying on having all traffic run over the VPN decreases risk of DNS leakage, or use of other DNS. It creates a foundation for the server that contains the OpenVPN service to have the option of intercepting all DNS traffic because all traffic is passing through it.

Not relying on this, and only using the OpenVPN server for DNS lookups does not make your task impossible, it just pushes more testing to the client side: You will need to verify that your OpenVPN client is not using other DNS Servers when it is pushed a DNS server to use when the link is up. (Even if there is a DNS server available over the VPN link, if the OS that is using your client is also using other DNS servers for lookups, then the ad-lookup feature you want will not be reliably used by the OS which may use your DNS along with whatever DNS it is configured to use.)

Routing all of your traffic through the vpn will consume throughput at your wherever your OpenVPN server is located. The cost in traffic to/from your home would be more than double what the client runs through your home. (Everything you request from the Internet through the tunnel would be downloaded by your home OpenVPN , and then uploaded by your home OpenVPN through the tunnel to the remote client.

How much network traffic will be consumed by the tunnel depends on the configuration of the VPN client, the VPN server their OS, and use of the network.

At a minimum, for data meant to go to/from the Internet passing through the tunnel, you can estimate a nearly symmetric consumption of traffic outside the tunnel. If you download a 1MB DNS zone transfer through the tunnel, then your home OpenVPN Server will be downloading 1MB and then uploading 1MB (at a minimum) when computing bits used outside the tunnel.

On top of that, there s the overhead of maintaining the tunnel, which varies in cost depending on the size of the packet data vs. the packet.. (Larger data vs header such as large file download is more efficient, while smaller data vs. header such as with interactive shell sessions is less efficient.) Then issues like the period of "reneg-sec" can have an on-going periodic, time-based cost that remains a fairly constant rate while connected, and pretty small percent compared to average Internet traffic.

An estimate based on average Internet use of a human browsing the web and using the VPN? The amount of data the client sends/received *through* the tunnel should probably be multiplied by around 1.2 to estimate the data used outside the tunnel for maintenance of the tunnel and overhead of encapsulation.

For the OpenVPN server, you can estimate that it will need to download from the Internet, and then upload to the client that data the client requests from the Internet through the tunnel, so if you get charged for bit going to/from your home whether they are received or transmitted, then there is a double-cost minimum for this data, but only the upload to the client would get the additional ~1.2x multiplier for traffic because of tunnel encapsulation and maintenance.

If your home network is only charged for downloads, then the data that will matter for that calculation will be what data your openVPN client sends to it through the tunnel, and what is downloaded from the Internet.

The above are generalizations and estimates based on common use. How much data the VPN will actually cost you will depend on many things, including things not explicitly mentioned above.

DNS is usually a small percent of network traffic when requesting a web page. It should not include anything like a DNS zone transfer by the OpenVPN client. The DNS request and response is probably smaller than the total amount of "text" (html) content in the average web page. The size of the DNS response can increase quite a bit if DNSSEC extensions are supported and included, but even with DNSSEC data in the request/response, the amount of data used by DNS is still probably less than the average amount of text (html) on a web page requested.

If you plan to run just DNS lookups over the VPN tunnel, then do it, but then verify there is no DNS leakage by the client.

anudeep
OpenVpn Newbie
Posts: 6
Joined: Mon Jan 16, 2017 2:49 pm

Re: Configuring OpenVPN for adblocking.

Post by anudeep » Wed Jan 18, 2017 6:13 am

Thanks for the detailed information. You cleared my doubts. :-)

anudeep
OpenVpn Newbie
Posts: 6
Joined: Mon Jan 16, 2017 2:49 pm

Re: Configuring OpenVPN for adblocking.

Post by anudeep » Fri Jan 20, 2017 9:44 am

....I have a OpenVPN option in my router. So enabling VPN on router will block ads? (Assuming that I have enabled pihole and configured DNS settings on router)

SomeGuy
OpenVPN Power User
Posts: 64
Joined: Sat Dec 17, 2016 1:58 am

Re: Configuring OpenVPN for adblocking.

Post by SomeGuy » Fri Jan 20, 2017 10:11 pm

Not all routers support OpenVPN equally, and some do not make setting options you want easy or possible.

If your router supports OpenVPN, and you can specify your Pi DNS server as what it should push to clients, and clients can reach it over the VPN, then that may work for you, but it is likely beyond the normal config discussion here, unless you can export the configuration file and logs from the router if/when things do not work.

anudeep
OpenVpn Newbie
Posts: 6
Joined: Mon Jan 16, 2017 2:49 pm

Re: Configuring OpenVPN for adblocking.

Post by anudeep » Sat Jan 21, 2017 5:09 am

SomeGuy wrote:Not all routers support OpenVPN equally, and some do not make setting options you want easy or possible.
Yes, it doesn't have any options to tweak the settings. Also it is not a high-end router, the processor is weak, so it is not reliable

Post Reply