20

I'm trying to get netcat to listen on port 4444, but it doesn't seem to be working. I am checking to see if the port is open using nmap, but it doesn't pick it up and I can't figure out why. I have tried various ports with no joy.

Here is a copy of my terminal so you can see what I am doing and what I have tried:

#iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination


# nmap localhost -p 4444

Starting Nmap 5.61TEST4 ( http://nmap.org ) at 2012-07-31 16:37 BST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.00019s latency).
Other addresses for localhost (not scanned): 127.0.0.1
PORT     STATE  SERVICE
4444/tcp closed krb524

Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds


# nc -l 4444 &
[1] 1951


# nmap  localhost -p 1-65535

Starting Nmap 5.61TEST4 ( http://nmap.org ) at 2012-07-31 16:42 BST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.0000070s latency).
Other addresses for localhost (not scanned): 127.0.0.1
Not shown: 65532 closed ports
PORT      STATE SERVICE
22/tcp    open  ssh
7337/tcp  open  unknown
33507/tcp open  unknown

Nmap done: 1 IP address (1 host up) scanned in 1.37 seconds


# ps -e | grep nc
   12 ?        00:00:00 sync_supers
 1156 tty1     00:00:00 ck-launch-sessi
 1232 tty1     00:00:00 dbus-launch
 1274 ?        00:00:00 klauncher
 1951 pts/2    00:00:00 nc
Grezzo
  • 932
  • 3
  • 9
  • 19

1 Answers1

27

I ran the verbose mode -v and got a clue back:

4444: inverse host lookup failed: Unknown server error : Connection timed out`
listening on [any] 41579 ...`

so I tried specifying a port with -p like this nc -lvp 4444 and it works:

listening on [any] 4444 ...

Obviously I need to use -p with -l with this version of nc.

I'd love it if anyone could tell my why there is this difference. Am I running an old version? (-h reports v1.10-38)

Grezzo
  • 932
  • 3
  • 9
  • 19
  • 7
    There are lots of different versions of Netcat (nc). The `-lp` syntax is from Hobbit's original version, I believe. Versions derived from BSD forbid the use of `-p` with `-l`. Many do not support `-e`. Always check your installation's man page or `-h` option output. – bonsaiviking Jul 31 '12 at 16:53
  • 1
    Just to satisfy your question as to whether your running an old version, I'd say yes. 1.89-3 stock here. – tao Jul 31 '12 at 18:11
  • 1
    Thanks guys. That explains the inconsistency between my Linux nc (hobbit/debian version) and my OS X nc (BSD version). – Grezzo Jul 31 '12 at 21:10
  • 1
    You have probably installed `netcat-traditional` instead of `netcat` or `netcat-openbsd` – semekh May 13 '13 at 08:09
  • In Debian 8.6 fresh installation -p is required for port, and i can confirm that netcat-traditional is installed by default (verified by apt) – George Vasiliou Jan 07 '17 at 23:40
  • it is really weird that `nc -l 5000` used to work in the past, but after some recent update, it no longer works, I have to use `nc -lp 5000`. Cannot be a retro right? – xuancong84 Mar 15 '21 at 07:50
  • 1
    ah this works! My sanity thanks you – lenz Sep 28 '21 at 03:52
  • @xuancong84, it's because of the different versions (not release versions, but completely different codebases) of the varying versions that are available, see semekh's comment above. – Grezzo Jun 13 '22 at 13:50