21

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

1 Answer 1

28

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)

8
  • 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. Jul 31, 2012 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, 2012 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, 2012 at 21:10
  • 1
    You have probably installed netcat-traditional instead of netcat or netcat-openbsd
    – semekh
    May 13, 2013 at 8:09
  • 1
    ah this works! My sanity thanks you
    – lenz
    Sep 28, 2021 at 3:52

You must log in to answer this question.

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