Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 --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
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

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 --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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .