I think I've screwed up my iptables, I was trying to get postgresql to allow TCP/IP connections, not sure what I did but the iptables now look like this? How can I get them back to normal/default (allowing postgresql on port: 5432)
sudo iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- anywhere bonify.archaeolabs.nl tcp spts:1024:65535 dpt:postgresql state NEW,ESTABLISHED Chain FORWARD (policy ACCEPT) target prot opt source destination Chain OUTPUT (policy ACCEPT) target prot opt source destination ACCEPT tcp -- bonify.archaeolabs.nl anywhere tcp spt:postgresql dpts:1024:65535 state ESTABLISHED Chain DOCKER (0 references) target prot opt source destination Chain DOCKER-ISOLATION (0 references) target prot opt source destination RETURN all -- anywhere anywhere 13 Answers
This can be achieved with the following commands:
sudo iptables -t nat -F sudo iptables -t mangle -F sudo iptables -F sudo iptables -X -F: flush the iptables
-X: delete non-default rules
Use: sudo iptables -S to see what the defaults are after flushing with previous commands.
Set up the default rules:
sudo iptables -P INPUT ACCEPT sudo iptables -P FORWARD ACCEPT sudo iptables -P OUTPUT ACCEPT Setup iptables to allow postgres traffic:
sudo iptables -A INPUT -p tcp -s 15.15.15.0/24 --dport 5432 -m state --state NEW,ESTABLISHED -j ACCEPT sudo iptables -A OUTPUT -p tcp --sport 5432 -m state --state ESTABLISHED -j ACCEPT Source:
Iptables can be resetted to the following command:
iptables -F The option -F means "flush" and all custom rules are deleted.
Well, to flush all the rules on all the tables and reset iptables to default:
sudo iptables -P INPUT ACCEPT sudo iptables -P FORWARD ACCEPT sudo iptables -P OUTPUT ACCEPT sudo iptables -F sudo iptables -X sudo iptables -t nat -F sudo iptables -t nat -X sudo iptables -t mangle -F sudo iptables -t mangle -X sudo iptables -t raw -F sudo iptables -t raw -X Can be scripted, save this in ~/bin as say ``
#!/bin/bash iptables -P INPUT ACCEPT iptables -P FORWARD ACCEPT iptables -P OUTPUT ACCEPT iptables -F iptables -X iptables -t nat -F iptables -t nat -X iptables -t mangle -F iptables -t mangle -X iptables -t raw -F iptables -t raw -X Now run sudo iptables_reset assuming ~/bin is on your path, otherwise run sudo /home/your_user/bin/iptable_reset
Now save the defaults
sudo sh -c "iptables-save > /etc/iptables.default" and you can restore simple as pie
sudo iptables-restore /etc/iptables.default