Skip to content

Instantly share code, notes, and snippets.

@gilangvperdana
Last active September 17, 2024 01:49
Show Gist options
  • Save gilangvperdana/98857ab52c6acb3c5b765cd402b1e930 to your computer and use it in GitHub Desktop.
Save gilangvperdana/98857ab52c6acb3c5b765cd402b1e930 to your computer and use it in GitHub Desktop.
Add Routing Private Network OpenVPN CLI

General

If you want to add routing to Private Network like Pritunl Server, you can follow this step for OpenVPN CLI

Edit server.conf

Assume 192.168.10.0/24 are network we want to reach from OpenVPN Client

nano /etc/openvpn/server.conf
push route "192.168.10.0 255.255.255.0"
systemctl restart openvpn@server

Add Routing

Assume wg0 are interface to reach private segment network from OpenVPN Server & 10.8.0.0/24 are VPN Segment

sudo iptables -t nat -L --line-numbers

iptables -t nat -I POSTROUTING -o wg0 -s 10.8.0.0/24 -j MASQUERADE
iptables -t nat -D POSTROUTING -o wg0 -s 10.8.0.0/24 -j MASQUERADE

or you can use this

iptables -t nat -I POSTROUTING 1 -o wg0 -s 10.8.0.0/24 -j MASQUERADE
iptables -t nat -D POSTROUTING -o wg0 -s 10.8.0.0/24 -j MASQUERADE

Reference

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment