Skip to content

Instantly share code, notes, and snippets.

@jjasghar
Created September 22, 2016 00:18
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jjasghar/963f2f3387c3b8aa647bc21cf1d1cab1 to your computer and use it in GitHub Desktop.
Save jjasghar/963f2f3387c3b8aa647bc21cf1d1cab1 to your computer and use it in GitHub Desktop.
basic nat setup with iptables with default OpenVPN network
#!/bin/bash
iptables -F
iptables -t nat -F
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P FORWARD DROP
export LAN=ens160 #change to your nic
export WAN=ens192 #change to your nic
echo 1 > /proc/sys/net/ipv4/ip_forward
for f in /proc/sys/net/ipv4/conf/*/rp_filter ; do echo 1 > $f ; done
iptables -I FORWARD -j ACCEPT
iptables -t nat -A POSTROUTING -o ${LAN} -j MASQUERADE
iptables -t nat -A POSTROUTING -o ${WAN} -j MASQUERADE
iptables -t nat -I POSTROUTING -s 10.8.0.0/24 -o ${LAN} -j MASQUERADE
iptables -A FORWARD -i ${LAN} -o ${WAN} -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -i ${WAN} -o ${LAN} -j ACCEPT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment