Skip to content

Instantly share code, notes, and snippets.

@nyrahul
Created December 4, 2018 10:25
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 nyrahul/2570a7b0d273b8bf7b6bc5f4c905aaf2 to your computer and use it in GitHub Desktop.
Save nyrahul/2570a7b0d273b8bf7b6bc5f4c905aaf2 to your computer and use it in GitHub Desktop.
Iptables ip/port range spec:
Multiple individual ports:
iptables -t mangle -A OUTPUT -p udp --match multiport --dports 110,143,993,955 -j MARK --set-mark 13
Port Range:
iptables -t mangle -A OUTPUT -p udp --match multiport --dports 1024:3000 -j MARK --set-mark 13
Multiple Port ranges:
iptables -t mangle -A OUTPUT -p udp --match multiport --dports 1000:2000,3000:4000 -j MARK --set-mark 13
Port ranges and individual ports mixed:
iptables -t mangle -A OUTPUT -p udp --match multiport --dports 1000:2000,3000:4000,10,20,30 -j MARK --set-mark 13
IP address range:
iptables -t mangle -A OUTPUT -p udp -m iprange --dst-range 192.168.10.100-192.168.10.200 -j MARK --set-mark 13
IP address range (last octet range)
iptables -t mangle -A OUTPUT -p udp -m iprange --dst-range 192.168.10.80-100 -j MARK --set-mark 13
… matches ip address range 192.168.10.80 to 192.168.10.100
IP address mask:
iptables -t mangle -A OUTPUT -p tcp -d 192.168.10.10/24 -j MARK --set-mark 13
Filtering specific ports
iptables -A INPUT -s 81.48.0.0/16 -p udp --destination-port ! 80 -j DROP
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment