Skip to content

Instantly share code, notes, and snippets.

@jjasghar jjasghar/nat.sh
Created Sep 22, 2016

Embed
What would you like to do?
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
You can’t perform that action at this time.