Skip to content

Instantly share code, notes, and snippets.

@wzxjohn
Last active December 21, 2016 13:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wzxjohn/3d1f275b1a36b39475d8 to your computer and use it in GitHub Desktop.
Save wzxjohn/3d1f275b1a36b39475d8 to your computer and use it in GitHub Desktop.
iptables rules for IKEv2 VPN and SSH on Ubuntu
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A POSTROUTING -j MASQUERADE
-A POSTROUTING -s 172.0.0.0/24 -o eth0 -j MASQUERADE
COMMIT
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
#Accept Related Connections
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
#Accept SSH Connections Be sure to change the port to your own SSH port!
-A INPUT -p udp -m udp --dport 500 -j ACCEPT
#Accept IPSec connections
-A INPUT -p udp -m udp --dport 4500 -j ACCEPT
#Accept IPSec connections
-A FORWARD -s 172.0.0.0/24 -j ACCEPT
#Forward packages from 172.0.0.0/24 The subnet is defined in ipsec.conf
-A FORWARD -p tcp -m tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu
COMMIT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment