I’m setting up rules in iptables on my small virtual server. How do I add port 5432 connection permission to iptables? Here are the rules now:
$ sudo iptables -L
Chain INPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT tcp -- anywhere anywhere multiport dports 2233,8033,8013
ACCEPT icmp -- anywhere anywhere icmp echo-reply
ACCEPT tcp -- anywhere anywhere multiport dports postgresql
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:postgresql
Chain FORWARD (policy DROP)
target prot opt source destination
Chain OUTPUT (policy DROP)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT all -- anywhere anywhere state NEW,RELATED,ESTABLISHED
I tried adding a resolution this way:
$ sudo /sbin/iptables -A INPUT -p tcp --dport 5432 -j ACCEPT
$ sudo /sbin/iptables -A INPUT -p tcp -m multiport --dport 5432 -j ACCEPT
$ sudo /sbin/iptables-save
# Generated by iptables-save v1.8.7 on Tue Jun 18 14:53:24 2024
*filter
:INPUT DROP [4036:178199]
:FORWARD DROP [0:0]
:OUTPUT DROP [0:0]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m multiport --dports 2233,8033,8013 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 0 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 5432 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 5432 -j ACCEPT
-A OUTPUT -o lo -j ACCEPT
-A OUTPUT -m state --state NEW,RELATED,ESTABLISHED -j ACCEPT
COMMIT
# Completed on Tue Jun 18 14:53:24 2024
There is no reaction. There is no information about port 5432 in Iptables. What did I do wrong?