jackrabbit jackrabbit - 8 months ago 55
Linux Question

Netcat connection refused

I have two linux machines connected via ethernet. I tried to test sending packets from one to the other using netcat. On the listening machine I used the following command:

nc -l 10000

On the sending machine I used:

nc -4u <ip address of listening machine's ethernet port> 10000

When I tried to send something I would get the following message: "nc: Write error: No route to host"

Upon googling the problem I found suggestions of temporarily disabling the firewall. I did so using the commands:

/etc/init.d/iptables save
/etc/init.d/iptables stop

However, now when I try to send from one machine to the other, I get the following message:
"nc: Write error: Connection refused"

Any ideas what's going on?


Turns out the problem was with the netcat listener. By default, the -l command listens for TCP packets. I was sending UDP packets (the -u command). The "connection refused" message stemmed from the fact that the netcat sender did not have anything listening to it on the other machine. Not sure why this is the case, but from my experiments netcat will give you a "connection refused" message if you don't have a netcat listener that receives the packets from your netcat sender.

Anyways, the command on the receiving machine that worked was:

nc -4ul 10000