Skip to content

Instantly share code, notes, and snippets.

@ram0973
Last active October 3, 2022 12:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ram0973/272f0c60ecf1f7b31e566c4255448934 to your computer and use it in GitHub Desktop.
Save ram0973/272f0c60ecf1f7b31e566c4255448934 to your computer and use it in GitHub Desktop.
Iptables rules for IPSEC IKEV2 VPN
iptables -A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 22 -j ACCEPT # SSH
iptables -A INPUT -p udp --dport 500 -j ACCEPT # for ISAKMP (handling of security associations)
iptables -A INPUT -p udp --dport 4500 -j ACCEPT # for NAT-T (handling of IPsec between natted devices)
iptables -A INPUT -p 50 -j ACCEPT # ESP - IP port 50 for ESP payload (the encrypted data packets)
iptables -A INPUT -j DROP
# Protect from trafic routing outside (WAN). Use outer interface here if any
iptables -A FORWARD -m state --state ESTABLISHED,RELATED -j ACCEPT
#iptables -A FORWARD -j REJECT
iptables -t nat -A POSTROUTING -j MASQUERADE
#iptables -t nat -A POSTROUTING -m policy --pol ipsec --dir out -j MASQUERADE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment