Even after 3 minutes googling I was not able to find a complete iptables reset script. This post tries to change this situation:
#!/bin/bash
echo "Disabling IPv4 packet forwarding..."
echo 0 > /proc/sys/net/ipv4/ip_forward
echo "Flushing chains..."
iptables -F
iptables -t nat -F
iptables -t mangle -F
echo "Deleting user defined chains..."
iptables -X
iptables -t nat -X
iptables -t mangle -X
echo "Setting default chain policies..."
iptables -P INPUT ACCEPT
iptables -P FORWARD ACCEPT
iptables -P OUTPUT ACCEPT
iptables -t nat -P OUTPUT ACCEPT
iptables -t nat -P PREROUTING ACCEPT
iptables -t nat -P POSTROUTING ACCEPT
iptables -t mangle -P INPUT ACCEPT
iptables -t mangle -P FORWARD ACCEPT
iptables -t mangle -P OUTPUT ACCEPT
iptables -t mangle -P PREROUTING ACCEPT
iptables -t mangle -P POSTROUTING ACCEPT
Anybody interested in building a simple NAT gateway will find the following lines quite helpful:
echo "Enabling IPv4 packet forwarding..."
echo 1 > /proc/sys/net/ipv4/ip_forward
echo "Enabling SNAT of outgoing packages..."
iptables -t nat -A POSTROUTING -o XXX -j MASQUERADE
Don’t forget to replace XXX with your outgoing interface name eg. ppp0.
Recent Comments