OpenVpn and IpTables

I have a VPS, somewhere in the US (provided by digital ocean – so far they are the best I found. Cheap, easy to use, flexible, SSD disks with a decent amount of space), which I want to use for VPN.

There are tons of great tutorials about how to setup OpenVPN, but after following them I could connect to the vpn indeed, but I could not use it for anything. There was no internet connection.

One thing was missing, the iptables setup. It is indeed talked about in the howto, but it is not fully complete. I hope this little script will help other people as well:

# enable forwrading
echo 1 > /proc/sys/net/ipv4/ip_forward
# set up forwarding
iptables -A FORWARD -i eth0 -o tun0 -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -t nat -A POSTROUTING -s -o eth0 -j MASQUERADE

You can copy this in a script a file (eg. /etc/, and have it run at startup by adding it to /etc/rc.local for instance.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s