Created
September 22, 2016 00:18
-
-
Save jjasghar/963f2f3387c3b8aa647bc21cf1d1cab1 to your computer and use it in GitHub Desktop.
basic nat setup with iptables with default OpenVPN network
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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