My question: How to add a custom iptables rule to accept connection on a certain port?
I'm trying to open port 3500 on my server but failed. I started by using this command: (From http://wiki.centos.org/HowTos/Network/IPTables)
iptables -A INPUT -p tcp --dport 3500 -j ACCEPT
But then I run iptables -L I still do not see the new rules being listed: (My assumption it should include 3500 in the output)
Chain INPUT (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere
ACCEPT tcp -- anywhere anywhere tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere tcp dpt:rtmp-port
Chain FORWARD (policy ACCEPT)
target prot opt source destination
RH-Firewall-1-INPUT all -- anywhere anywhere
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Chain RH-Firewall-1-INPUT (2 references)
target prot opt source destination
ACCEPT all -- anywhere anywhere
ACCEPT icmp -- anywhere anywhere icmp any
ACCEPT esp -- anywhere anywhere
ACCEPT ah -- anywhere anywhere
ACCEPT udp -- anywhere 224.0.0.251 udp dpt:mdns
ACCEPT udp -- anywhere anywhere udp dpt:ipp
ACCEPT tcp -- anywhere anywhere tcp dpt:ipp
ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED
ACCEPT udp -- anywhere anywhere state NEW udp dpt:snmp
ACCEPT udp -- anywhere anywhere state NEW udp dpt:snmptrap
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ssh
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:http
ACCEPT tcp -- anywhere anywhere state NEW tcp dpt:ftp
REJECT all -- anywhere anywhere reject-with icmp-host-prohibited
Edit So I try to insert ACCEPT rule to the INPUT chain and my iptables now look like this:
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:3500
RH-Firewall-1-INPUT all -- 0.0.0.0/0 0.0.0.0/0
But it does not allow me to connect to 3500 from outside. (I can still telnet from inside). When I'm trying to telnet my_host 3500, I get this: telnet: Unable to connect to remote host: Connection refused
Edit 2: My netstat -an | grep "LISTEN " output:
tcp 0 0 127.0.0.1:3500 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:973 0.0.0.0:* LISTEN
tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN
tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN
tcp 0 0 :::22 :::* LISTEN
Edit 3: I followed lain advise, also have my service bind to 0.0.0.0:3500 instead of 127.0.0.1:3500 and it works.

/sbin/service iptables saveoriptables save? actually, wait, nevermind - you did. that is why all of those rules are under the INPUT chain. Just do what lain said. – tfitzgerald Sep 26 '11 at 21:52