Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


Help! I can't open port using iptables!
New on LowEndTalk? Please Register and read our Community Rules.

All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.

Help! I can't open port using iptables!

jaycjayc Member

Hi,

I have two vps, vps1 and vps2. vps1 needs to connect to vps2 thru port 2222 to exchange some data. So what I did in vps2 was, to run the following command:

iptables -A INPUT -p tcp -i eth0 --dport 2222 -j ACCEPT
iptables -A INPUT -p udp -i eth0 --dport 2222 -j ACCEPT

I have also tried:
iptables -A INPUT -p udp --dport 2222 -j ACCEPT
iptables -A INPUT -p tcp --dport 2222 -j ACCEPT
iptables -A OUTPUT -p tcp --dport 2222 -j ACCEPT
iptables -A OUTPUT -p udp --dport 2222 -j ACCEPT
service iptables save
service iptables restart

but when I use vps1 to do:
telnet vps2ipaddress 2222

I got the connection refused problem.

also tried to stop the iptables on vps2 then run the telnet command on vps1, no luck

Comments

  • When troubleshooting firewall issues, it's helpful to see all of the other rules in your configuration. There may be a BLOCK rule somewhere that is taking precedence over your ACCEPT rule.

  • jaycjayc Member

    iptables -nL

    Chain INPUT (policy ACCEPT)
    target prot opt source destination
    ACCEPT tcp -- 0.0.0.0/0 0.0.0.0/0 tcp dpt:2222
    ACCEPT udp -- 0.0.0.0/0 0.0.0.0/0 udp dpt:2222

    Chain FORWARD (policy ACCEPT)
    target prot opt source destination

    Chain OUTPUT (policy ACCEPT)
    target prot opt source destination

  • Is port 2222 blocked on VPS1? iptables -F will clear out all your rules. I'd flush rules on both VPS1 and VPS2, and try to telnet. If it works, then your VPS1 rules must be blocking it.

  • jaycjayc Member

    I have flushed the iptables by running "iptables -F" on both vps1 and 2. I'm still having the connection refused problem.

  • Is the node where your VPS is on has blocked 2222?

  • jaycjayc Member

    why would my node (chicagovps) block 2222 only?

  • @jayc said:
    I got the connection refused problem.

    Meaning nothing is running on the port you're trying to connect to, you could have googled that ;-)

  • jaycjayc Member

    flushing the iptables and retried again. now it's working fine :)

  • You're only half way to the solution. You now know that firewall rules on VPS1 were blocking the connection between VPS1 and VPS2. Now the question is whether you want to permanently open port 2222 on both sides via firewall rules, or permanently flush all your rules (effectively operating without a firewall).

Sign In or Register to comment.