Skip to content

Instantly share code, notes, and snippets.

@Max95Cohen
Last active February 28, 2023 09:18
Show Gist options
  • Save Max95Cohen/d1d48743724c99e7b6b5976a7eeea586 to your computer and use it in GitHub Desktop.
Save Max95Cohen/d1d48743724c99e7b6b5976a7eeea586 to your computer and use it in GitHub Desktop.
iptables examples
# show, delete
iptables -t nat -v -L PREROUTING -n --line-number
iptables -t nat -D PREROUTING 5
# forward
iptables -t nat -A PREROUTING -i ens3 -p tcp --dport 33080 -j DNAT --to 10.0.27.67:33080
# Global IP to Local IP Ubuntu
iptables -t nat -A OUTPUT -p all -d 123.45.67.89 -j DNAT --to-destination 127.0.0.1
# forward port to another server
iptables -t nat -A PREROUTING -i eth0 -p tcp -d 10.0.11.12 --dport 2222 -j DNAT --to-destination 192.168.10.7:22
iptables -t nat -A POSTROUTING -d 192.168.10.7 -p tcp --dport 22 -j MASQUERADE
# port range
iptables -t nat -A PREROUTING -p tcp --dport 40000:50000 -j DNAT --to-destination 192.168.10.7:40000-50000
# drop ICMP packet from output
iptables -A INPUT -p icmp --icmp-type 8 -j DROP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment