openvpn.is
English
简体中文繁體中文EnglishРусскийفارسی

HomeGuidesAll traffic through the gate

All traffic through the gate

Send all traffic through OpenVPN: redirect-gateway def1, forwarding and NAT, pushing DNS, DNS leaks on Windows, what to do with IPv6, and checking it.

All traffic passes through the city gate
All traffic passes through the city gate Olivier, CC BY-SA 4.0

Three lines on the server

server.conf
push "redirect-gateway def1"
push "dhcp-option DNS 1.1.1.1"
push "block-ipv6"

def1 adds two more specific routes over the default one, so it is back by itself when you disconnect. If the server has no IPv6, block-ipv6 keeps IPv6 traffic from slipping past.

Forwarding and rewriting

On the server
echo 'net.ipv4.ip_forward=1' | sudo tee /etc/sysctl.d/99-ovpn.conf
sudo sysctl --system
sudo iptables -t nat -A POSTROUTING -s 10.9.0.0/24 -o eth0 -j MASQUERADE

Find the interface name with ip route get 1.1.1.1.

DNS on Windows

Windows asks several DNS servers at once and takes the fastest. Add block-outside-dns to the client profile and the other adapters' DNS is no longer used.

Check it

Look atIt should show
A what-is-my-IP siteThe server's address
A DNS leak testOnly the one you pushed
An IPv6 testNo address, or the server's
AdLuoboyunNo server abroad yet? A ready line is another way: 1 GB for a new account, to try within 24 hours, with Clash / Mihomo.Try a ready line
No internet once connected?

Usually the wrong interface in the NAT rule, or forwarding is off.

Only part of the traffic?

Remove redirect-gateway and push a few routes instead.

Walk onIssue and revoke papers

Nearby gates

Signposts: OpenVPN all traffic, redirect-gateway def1, OpenVPN DNS leak