Skip to content

Instantly share code, notes, and snippets.

@jriguera
Created December 17, 2015 12:52
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 jriguera/4d038a3a9576513f72cf to your computer and use it in GitHub Desktop.
Save jriguera/4d038a3a9576513f72cf to your computer and use it in GitHub Desktop.
Iptables redirect port
# All incoming trafic (mainly via eth2) will be redirected to 2005 (old graphite relay)
iptables -t nat -A PREROUTING -p tcp --dport 2003 -j REDIRECT --to-port 2005
iptables -t nat -A PREROUTING -p udp --dport 2003 -j REDIRECT --to-port 2005
# Another example using ips
#iptables -t nat -A PREROUTING -i eth2 -p udp -d 10.9.2.197 --dport 2003 -j REDIRECT --to-port 2005
# loopback traffic do not go via PREROUTING chain
iptables -t nat -A OUTPUT -o lo -p tcp --dport 2003 -j REDIRECT --to-port 2005
# just the same but using ips instead of interfaces (for udp)
iptables -t nat -A OUTPUT --src 0/0 --dst 127.0.0.1 -p udp --dport 2003 -j REDIRECT --to-port 2005
# Show it
iptables -t nat -L -n -v
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment