I'm using the OpenVPN client through the OpenVPN Network Manager plugin on a dual stack (meaning configured both for IPv4 and IPv6 connectivity) Ubuntu 13.10 to redirect all traffic through the VPN (redirect-gateway). It generally works fine.
However, due to the fact that IPv6 is preferred by the system, the VPN "leaks" and when connecting to sites that are also available over IPv6 (like Google, or Wikipedia), the browser connects directly.
One solution would be to configure the OpenVPN server to provide IPv6 connectivity. While possible with OpenVPN, the plugin for Network Manager currently doesn't support it.
Since IPv6 connectivity over the VPN is not strictly necessary, I'd like to simply disable IPv6 on the client when connecting to the OpenVPN server. Is it possible? If so, how can I do it?
Add this to your kernel line in your boot loader to disable IPv6 altogether:
If you're using Grub (if you haven't installed your own boot-loader, then you are using Grub), your kernel line should look something like this:
The recommended approach, for adding something to the kernel line, is to add the desired kernel parameter to the
GRUB_CMDLINE_LINUX_DEFAULT
variable in the/etc/default/grub
file:Once you've added that to
/etc/default/grub
, run the following command to regenerate yourgrub.cfg
:Alternatively, adding
ipv6.disable_ipv6=1
instead will keep the IPv6 stack functional but will not assign IPv6 addresses to any of your network devices.OR
To disable IPv6 via sysctl, place the following into your
/etc/sysctl.conf
file:Don't forget to comment out any IPv6 hosts in your
/etc/hosts
file:NOTE
a reboot may be required for the sysctl method, and a reboot is definitely required for the kernel line approach.
OR
To temporarily disable ipv6:
To temporarily enable it:
So if you need to disable ipv6 on a given condition, then write a bash script somewhere along these lines:
NOTE
You might need to disable any ipv6 hosts in your
/etc/hosts
file for this method too, just as I recommended in the previous method.You can disable ipv6 at the client level for a specific Network Manager connection by setting the IPv6 option ipv6.method to "ignore"
// SOP: Recreate my LAN connection using FIXED IP 192.168.0.95 to Ethernet. ````
````
I think it is less intrusive to disable ip6 in the client file (edit client_conf_file.ovpn) that modify the kernel tcp stack.
Open your conf_file.ovpn and add follow lines:
I tried it and after this the ipv6 disappears.
Before. I run
ip a |grep global
and result is:After. I run
ip a |grep global
and result is:I'm on Ubuntu 16.04.03 LTS, connecting to a Pi-Hole server through PiVPN.
This is what I did to switch IPv6 automatically on and off when connecting to a VPN through the Network Manager:
Create a script in
/etc/NetworkManager/dispatcher.d
:Add the following content into the file (modify the contents for your requirements):
Make the script executable:
That's it. I had to manually add my Pi-Hole DNS because of a
dnsmasq
bug that preventsresolv.conf
from being updated correctly, so modify the lines indicated if you find your DNS leaking.Edit the OpenVPN profile in NetworkManager, open the IPv6 tab and manually add a route:
Address: 2000 Prefix: 3 Gateway: 0100::1
2000::/3 captures all publicly routable IPv6 addresses. 0100::/64 prefix is a special prefix designated to discarding traffic. Essentially you'll be sending all IPv6 traffic to a gateway that doesn't exist.
Upside: easy and completely automatic.
Downside: some apps, namely command-line tools, may not fall-back to IPv4 as quickly as one would like when this method is used.
Try my straight-forward script I just made now, this will,
If there is still ipv6 address on certain interfaces, the client still try ipv6 routing but as DNS uses UDP, there are chances of DNS Leak that TCPwrapper can't manage to disable.
This script also works well with other interfaces because it doesn't rely on NetworkManager's argument anymore, such as vpn-up vpn-down.
create an executable file in /etc/NetworkManager/dispatcher.d/
paste the code below
then make it executable
P.S. OpenVPN with Network Manager loses lot's of OpenVPN benefit options from command line versions.
If anyone still needs this info and none of the other options work; I've solved this issue by going into Openvpn's server config file.
First type in
sudo chmod a+w /etc/openvpn/server.conf
since server.conf doesn't let you edit it, without making it writable.Then type in
vim /etc/openvpn/server.conf
; you can interchange vim for any-other text editor, just note we're going to edit this file.Then comment out by adding an # to the beginning of these lines:
After saving the file, we're going to restart Openvpn by using the following command:
sudo systemctl restart openvpn
At this point, the issue at hand should be fixed. When I execute my ovpn file, it shows no info about ivp6 being in use. Hope this works for you.