I have a VPS for Apples push notification service I am trying to open a port 2195. I am currently doing this

vi /etc/sysconfig/iptables

then I go to insert mode of vi and enter these two lines

-A -I INPUT -p tcp --dport 2195 -j ACCEPT
-A -I OUTPUT -p tcp --dport 2195 -j ACCEPT

then I save the file and quit vi.

Then I restart iptables service by

service iptables restart.

But after that when I try to telnet by doing

 telnet localhost 2195

I get this

Trying 127.0.0.1... telnet: connect to address 127.0.0.1: Connection refused

Any pointers....?

Server is red hat on hostgator

link|improve this question
Could you add the output of iptables -L -n -v ? The policy of each chain and any other rules will be important in answering this question. – Ladadadada Jan 25 at 7:46
Try telnet your_ip 2195 and see if in this way is working. Where your_ip is the real ip not 127.0.0.1 . – Sacx Jan 25 at 7:47
feedback

3 Answers

Your rules are bad. You can't use -A and -I together, -A means append as last rule, -I menas insert as first rule.

link|improve this answer
Good spot. I didn't even notice that. I just jumped straight to the port bit. – Ladadadada Jan 25 at 8:26
feedback

Two things I notice immediately:

  1. You have allowed packets out with a destination port of 2195 but if someone contacts your server on 2195 then your return packets will have a source port of 2195. Depending on what traffic is needed, you can either change the --dport in the OUTPUT chain to --sport or add two extra rules with --sport as well.
  2. A connection refused error implies different things about what has happened to the connection than a timeout would. It suggests that your service is not listening on port 2195. Could you run netstat -tan | grep LISTEN and check that your service is listening on port 2195 on the loopback interface?
link|improve this answer
feedback

Please first validate your rules are applied or not via

sudo iptables -L -vnx

If the rules is there, make sure the service which listens on 2195 is running or not.

sudo netstat -tulpn 
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.