Linux – netcat unable to connect to remote host

linuxnetcat

I've asked this on the DigitalOcean forum but haven't heard any responses. I have a droplet running Debian 8.1 x64 and I'm trying to set up a basic netcat connection (I'm using nc.openbsd on both my local and remote machine). I ssh into my server and enter

nc -l -v 5555

and get back

Listening on [0.0.0.0] (family 0, port 5555)

Then I go to my local machine and enter

nc -v [domain.com] 5555

and never hear anything back. Entering text does not cause it to come up on the other end. I've tried these exact commands on local machines connected over my LAN and it works fine. Also even when listening on the ports an nmap scan returns the port as filtered.

Anyone know what could be causing this? I've been looking at every tutorial and searching as many sites as I can find for the last 24 hours and no luck. I'm guessing this is an easy fix and I'm not typing in the right search terms.

Best Answer

The cause is a firewall. Either on your droplet or around your local machine (that you can use this port within your LAN doesn't mean outside connections are allowed to use it). You can mostly eliminate the Debian droplet's firewall as the block with the following commands on it:

iptables -I INPUT -p tcp --dport 5555 -j ACCEPT
iptables -I OUTPUT -p tcp --sport 5555 -j ACCEPT

Which poke a hole for this port that disregards most other iptables rules - specifically, any in the very likely place of the INPUT and OUTPUT filter chains.

Or if Debian 8.1 is on firewalld, do the firewalld thing

If the port is other than 5555, like a common IRC or torrent port or whatever, it may actually be blocked at the datacenter. I can't say if DigitalOcean does this, though.