Troubleshooting “nc: Protocol not available” Error in CentOS 6.7 Netcat Listener Mode


3 views

When attempting to launch netcat in listening mode on CentOS 6.7 with command:

nc -l 1234
nc: Protocol not available

This behavior occurs regardless of the port number specified. Let's dive into why this happens and how to resolve it.

The problem stems from the specific netcat package version (1.84) shipped with CentOS 6.x. This implementation has limitations when handling IPv6 configurations, even when attempting IPv4 connections.

Here are three approaches that consistently work:

1. Force IPv4 Mode

nc -4 -l 1234

This explicitly tells netcat to use IPv4 protocol stack. The -4 flag is crucial here.

2. Alternative Netcat Implementation

Install the nmap-ncat package:

yum install nmap-ncat
ncat -l 1234

This provides a more modern and fully functional netcat implementation.

3. Classic Netcat Compilation

Compile the original netcat from source:

wget http://downloads.sourceforge.net/netcat/netcat-0.7.1.tar.gz
tar -xzf netcat-0.7.1.tar.gz
cd netcat-0.7.1
./configure
make
sudo make install

Verify listener functionality with these commands in separate terminals:

# Terminal 1 (server)
nc -4 -l 1234

# Terminal 2 (client)
nc localhost 1234

The CentOS 6.7 netcat package attempts to use IPv6 by default when available, but fails to properly fall back to IPv4. The solutions either:

  • Force IPv4 usage (-4 flag)
  • Use a more robust implementation (nmap-ncat)
  • Bypass the problematic package entirely (source compilation)

For production systems, we recommend:

yum remove nc
yum install nmap-ncat

This provides long-term stability and additional features like SSL encryption.

If issues persist, check:

# Verify port availability
netstat -tulnp | grep 1234

# Check SELinux context
getsebool -a | grep nis

When attempting to start a netcat listener on CentOS 6.7 with the command:

nc -l 1234

Many users encounter the frustrating error:

nc: Protocol not available

The problem occurs specifically with the following netcat package version:

Name        : nc
Arch        : x86_64
Version     : 1.84
Release     : 24.el6

This issue stems from how the traditional netcat implementation was compiled for RHEL/CentOS 6. The binary was built without proper IPv6 support while attempting to use IPv6 sockets by default.

Here are three working approaches:

Solution 1: Force IPv4 Usage

Explicitly tell netcat to use IPv4:

nc -4 -l 1234

Solution 2: Use Alternative Netcat Implementation

Install nmap-ncat which handles this properly:

yum install nmap-ncat
ncat -l 1234

Solution 3> Recompile Netcat

For advanced users who need to keep the original nc:

yum install gcc glibc-devel
wget http://downloads.sourceforge.net/project/netcat/netcat/0.7.1/netcat-0.7.1.tar.gz
tar xvfz netcat-0.7.1.tar.gz
cd netcat-0.7.1
./configure --prefix=/usr --mandir=/usr/share/man --infodir=/usr/share/info
make
make install

After applying any solution, verify with:

netstat -tulnp | grep 1234
# or
ss -tulnp | grep 1234

For production systems, consider:

  • Upgrading to CentOS 7+ where this is fixed
  • Creating an alias in bashrc: alias nc='nc -4'
  • Using socat as a more robust alternative

Here are some practical examples that now work:

# Basic listener
nc -4 -l 1234

# With verbose output
nc -4 -lv 1234

# Pipe output to file
nc -4 -l 1234 > received_file