When working with Netcat (nc
) for network testing or debugging, socket binding failures can be particularly frustrating. The error messages we're seeing suggest multiple potential issues:
$ nc -vvv -l 5349
5349: inverse host lookup failed: Unknown host
nnetfd reuseport failed : Protocol not available
listening on [any] 38541 ... : Protocol not available
From the provided information, we can note several important details:
- Netcat works fine on Ubuntu 14.04 but fails on Debian 8.0 Jessie
- The port (5349) is confirmed available via
ss -tnl | grep 5349
- The IP address (10.1.6.189) is correctly configured on eth0
- The server is behind NAT
- Both specific IP and wildcard binding attempts fail
Several factors could contribute to this behavior:
1. Netcat Version Differences
Different Linux distributions may ship with different Netcat implementations. Let's check which variant we're using:
$ nc -h
# or
$ dpkg -l | grep netcat
The error message "nnetfd reuseport failed" suggests this might be the Nmap's Ncat version rather than traditional Netcat.
2. Protocol Support Issues
The "Protocol not available" error often indicates:
- Missing kernel support for socket options
- Firewall interference
- Network namespace restrictions
3. NAT Configuration Problems
While NAT shouldn't prevent binding, it can affect:
- Port forwarding rules
- Connection tracking
- IP masquerading behavior
Option 1: Try Traditional Netcat
On Debian, install the classic implementation:
$ sudo apt-get install netcat-traditional
$ sudo update-alternatives --config nc
Then retry binding:
$ nc.traditional -l -p 5349 -vvv
Option 2: Disable Advanced Socket Options
For Ncat versions, try disabling reuseport:
$ ncat -l 5349 -vvv --no-shutdown
Option 3: Verify Kernel Modules
Check relevant kernel modules are loaded:
$ lsmod | grep tcp
$ lsmod | grep ipv6
Option 4: Test Without NAT
If possible, test on a non-NATed interface or IP:
$ nc -l 127.0.0.1 5349 -vvv
For deeper investigation, consider these approaches:
1. Network Tracing
Use strace
to see system calls:
$ strace nc -l 5349
2. Alternative Tools
Test with other networking tools:
$ socat - TCP-LISTEN:5349,reuseaddr,fork
$ python -m http.server 5349
3. Firewall Check
Verify iptables/nftables rules:
$ sudo iptables -L -n -v
$ sudo nft list ruleset
Based on the symptoms, the most likely solutions are:
- Switch to traditional Netcat implementation
- Use simpler socket options (
--no-shutdown
or--keep-open
) - Verify kernel network protocol support
Remember that NAT typically affects routing, not binding, so the core issue likely lies with the Netcat implementation or system configuration rather than the NAT itself.
When working with netcat (nc
) on Linux systems, socket binding issues can be particularly frustrating. While basic listening works fine on my Ubuntu 14.04 workstation:
$ nc -l 5349 -vvv
Listening on [0.0.0.0] (family 0, port 5349)
The same command fails spectacularly on a Debian 8.0 server behind NAT:
$ nc -vvv -l 5349
5349: inverse host lookup failed: Unknown host
nnetfd reuseport failed : Protocol not available
listening on [any] 38541 ... : Protocol not available
First, let's verify the port availability:
$ ss -tnl | grep 5349
(empty)
And confirm the network interface configuration:
$ ip addr list
2: eth0: mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
link/ether 1e:89:93:f1:96:a4 brd ff:ff:ff:ff:ff:ff
inet 10.1.6.189/19 brd 10.1.31.255 scope global eth0
inet6 fe80::1c89:93ff:fef1:96a4/64 scope link
valid_lft forever preferred_lft forever
The error Protocol not available
typically indicates one of several possibilities:
- Kernel-level socket options mismatch
- Netcat version differences between systems
- NAT/firewall interference
- Missing kernel modules or capabilities
Debian Jessie ships with the BSD variant of netcat by default. Try installing the traditional version:
$ sudo apt-get install netcat-traditional
$ sudo update-alternatives --config nc
Then test with the traditional syntax:
$ nc -l -p 5349 -vvv
If the protocol error persists, try these kernel parameter adjustments:
$ sudo sysctl -w net.ipv4.tcp_fin_timeout=30
$ sudo sysctl -w net.ipv4.tcp_tw_reuse=1
When netcat fails, consider these alternatives:
Using socat:
$ socat TCP-LISTEN:5349,reuseaddr,fork -
Using Python as a quick listener:
$ python -c 'import socket; s=socket.socket(); s.bind(("",5349)); s.listen(1); conn,addr=s.accept()'
For servers behind NAT, additional steps may be required:
- Configure port forwarding on the NAT device
- Ensure proper iptables rules:
$ sudo iptables -A INPUT -p tcp --dport 5349 -j ACCEPT
After applying fixes, verify with:
$ netstat -tulnp | grep 5349
$ ss -tulnp | grep 5349
And test connectivity from another machine:
$ nc -zv your.server.ip 5349