Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Im doing a file_get_contents but getting Connection refused

I used the following to allow outgoing connections from server2 to server1, and vice-versa. But I'm still getting failed to open stream: Connection refused

iptables -A OUTPUT -p tcp -d 123.123.123.123 --dport 8983 -j ACCEPT
iptables -A INPUT  -p tcp -s 321.321.321.321 --dport 8983 -j ACCEPT

Maybe there's some rule where i cant use file_get_contents between two different servers/ip?

I think for now i'll use curl, but interested to know what's not working here...

share|improve this question
1  
Connection refused could also means refused by the other end (the server you're connecting to). Are you sure the server accepts connection on that port? –  Darius May 26 '13 at 0:48
    
In my experience, "connection refused" has invariably come down to not having anything listening to the receiving port on the remote host. Have you verified that a daemon or service is listening to port 8983 on the remote host? If this were a firewall issue, chances are the firewall would have silently dropped the packets and your clue would have been request timeouts on the client side. –  dafydd May 26 '13 at 2:33
add comment

1 Answer 1

You are connecting to port 8983 on destination, so you must allow output traffic to that port on server 2, which you are:

iptables -A OUTPUT -p tcp -d 123.123.123.123 --dport 8983 -j ACCEPT

You should also accept incoming traffic on server 2 for related and established connections in general:

iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

Also, don't forget to add the corresponding rules on server 1:

iptables -A INPUT -p tcp -m tcp --dport 8983 -j ACCEPT
iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT

If you are still unable to connect after setting this rules, you are probably being blocked by an intermediate firewall between server 1 and server 2.

If that's not the case, maybe server 1 is behind a NAT and you have to set the NAT router to forward incoming connections to 8983 to the same port on server 1 behind that router.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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