How can I configure netcat (or some other stock linux utility) to listen on a specific port on a secondary IP address?

Solution 1:

The syntax depends on the netcat package.

netcat-openbsd

nc -l 192.168.2.1 3000

netcat-traditional

nc -l -p 3000 -s 192.168.2.1

A simple way (at least in bash) for telling them apart in scripts is:

if ldd $(type -P nc) | grep -q libbsd; then
    nc -l 192.168.2.1 3000
else
    nc -l -p 3000 -s 192.168.2.1
fi

Solution 2:

For completion:

nc -l -p port -s ip

should work too. Works with nc6 version 1.0 and netcat (The GNU Netcat) 0.7.1.

The command from Laging doesn't work with nc6 (used in debian).