Posts Tagged ‘iptables’

Iptables rules loaded every time after a reboot

Thursday, November 7th, 2019

Even if it has been disabled firewalld and iptables, some iptables rules could be activated after a reboot. It’s due to libvirtd .

I’ve just read a good post here where it’s fully explained why even though iptables is turned OFF, after every boot the command iptables -L -n still displays some rules to be activated.

redirecting a TCP connection using iptables

Friday, May 8th, 2009

Yesterday I was requested to redirect the traffic to the 80 TCP port of an host to the TCP 8080 port of a second host just for some hours. Thanks to iptables it was been very easy.
First it’s better to enable port forwarding:

# echo 1 >/proc/sys/net/ipv4/ip_forward

Then here comes some iptables commands and rules:

# iptables -F
# iptables -X
# iptables -t nat -F
# iptables -t nat -X
# iptables -t mangle -F
# iptables -t mangle -X
# iptables -P INPUT ACCEPT
# iptables -P FORWARD ACCEPT
# iptables -P OUTPUT ACCEPT

# iptables -t nat -A PREROUTING  -p tcp -m tcp -d HOST1 –dport PORT1 -j DNAT –to-destination HOST2:PORT2
# iptables -t nat -A POSTROUTING -p tcp -d HOST2 –dport PORT2 -j MASQUERADE

If You like, just download this simple shell script.

To display the nat rule:

# iptables -t nat -n -L

many thanks to cyberciti.biz and Chris Siebenmann‘s wiki.