⚠️ Since version 2.4.1, Mozilla VPN automatically adds nftables rules that block routing traffic. ⚠️
I recently bought the new Mozilla VPN because I think it's a good way to support the foundation.
For now, the VPN is compatible with Windows 10, macOS, Android, iOS and Ubuntu. Which is already not bad but not enough for me as I'm an ArchLinux user. So I created an VPN gateway under Ubuntu in my network to make me able to use it from non compatible machines.
⚠️ Mozilla VPN licence allows you to use up to 5 devices. The goal of this topic is not to bypass this limit. ⚠️
⚠️ Mozilla VPN can work on Ubuntu Focal Fossa 20.04 and Bionic Beaver 18.04 only.
user@ubuntu:~$ sudo add-apt-repository ppa:mozillacorp/mozillavpn
user@ubuntu:~$ sudo apt-get update
user@ubuntu:~$ sudo apt-get install mozillavpn
user@ubuntu:~$ mozillavpn
user@ubuntu:~$ echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
net.ipv4.ip_forward=1
user@ubuntu:~$ sudo sysctl -p
user@ubuntu:~$ sudo iptables -t nat -A POSTROUTING -o moz0 -j MASQUERADE
user@ubuntu:~$ ip -6 addr sh
2: enp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
inet6 2001:db8::/64 scope global dynamic mngtmpaddr
valid_lft 86187sec preferred_lft 14187sec
inet6 fe80::fe80::aaff:874a:dead:beef/64 scope link
valid_lft forever preferred_lft forever
user@ubuntu:~$ echo 1 | sudo tee /proc/sys/net/ipv6/conf/all/forwarding
net.ipv6.conf.all.forwarding=1
user@ubuntu:~$ sudo sysctl -p
user@ubuntu:~$ sudo ip6tables -t nat -A POSTROUTING -o moz0 -j MASQUERADE
Here we can choose between routing all traffic or to use the Port Based Routing, wich consits of routing specific protocols to our Ubuntu gateway.
PBR consists in marking frames we want to route to VPN gateway. Only frames which are marked with 0x80 value will be routed to VPN.
root@arch:~# echo "200 vpn" >> /etc/iproute2/rt_tables
root@arch:~# ip rule add fwmark 0x80 table vpn
root@arch:~# ip route add default via 172.31.0.200 dev ens160 table vpn
root@arch:~# ip route list table vpn default via 172.31.0.200 dev ens160
For the example we will mark http and https frames.
root@arch:~# nft add chain ip filter MANGLE { type route hook output priority -150\; policy accept \; }
root@arch:~# nft add rule ip filter MANGLE tcp dport { 80, 443 } ip daddr \!= { 172.31.0.0/24, 10.0.0.0/24 } meta mark set 0x80 counter
root@arch:~# nft add rule ip filter MANGLE tcp sport \>= 1024 ip daddr \!= { 172.31.0.0/24, 10.0.0.0/24 } meta mark set 0x80 counter
root@arch:~# nft add rule ip filter MANGLE udp sport \>= 1024 ip daddr \!= { 172.31.0.0/24, 10.0.0.0/24 } meta mark set 0x80 counter
Easier we can simply route all traffic to our VPN gateway :
root@arch:~# route del default
root@arch:~# route add default via 172.31.0.200 dev ens160
root@arch:~# curl ipinfo.io/ip
root@arch:~# ip -6 route del default
root@arch:~# ip -6 route add default via fe80::aaff:874a:dead:beef dev ens160 metric 1
root@arch:~# telnet -6 ipv6.telnetmyip.com
Contact :