
Nc: connect to 192.168.122.75 port 30 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 29 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 28 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 27 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 26 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 25 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 24 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 23 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 21 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 20 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 19 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 18 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 17 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 16 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 15 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 14 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 13 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 12 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 11 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 10 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 9 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 8 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 7 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 6 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 5 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 4 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 3 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 2 (tcp) failed: Connection refused Nc: connect to 192.168.122.75 port 1 (tcp) failed: Connection refused In this example we are only going to check ports 1 through to 30.Įxample Command: nc -vnz -w 1 192.168.122.75 1-30 We will also specify a range of ports to check. The " -z" flag specifies that netcat should scan for listening daemons without sending any data. By default, netcat will listen forever, however, in this example we are going to use a more realistic value of "1" second. The " -w" flag is used to specify a timeout limit. In this example we will be using the flags " -w" and " -z" in addition to the " -v" and " -n" flags. Nc: connect to 192.168.122.75 port 2000 (tcp) failed: Connection refusedĪnother popular use of the netcat command is to use it as a port scanner. If we now check for a port which is closed, you will see the difference in the output from the command: In this example we are looking at port 22 (normally used for ssh).Ĭonnection to 192.168.122.75 22 port succeeded!Īs we can see from the output port 22 is open for connections. In the above example we have specified the IP address of a CentOS 8 server followed by the port we wish to interrogate. The " -n" option specifies that we do not wish to use DNS or service lookups on any addresses, hostnames or ports.Įxample Command: nc -vn 192.168.122.75 22 The " -v" flag specifies that we would like verbose output (more detailed). We will use the netcat command in conjunction with the " -v" and " -n" flags. In this example we will use netcat to interrogate a port to see if it is open. In the following examples we will take a quick look at some of the popular uses of netcat/nmap-ncat.
INSTALL NC NETCAT ON LINUX INSTALL
To install this package, issue the following command: On RHEL 8 and CentOS 8 systems, "netcat" has been replaced by a package called " nmap-ncat". Installing nmap-netcat on RHEL/CentOS Systems If you need to install netcat, you can use the following commands: In the following examples I will be using a Linux Mint system and a CentOS system. Netcat can open TCP connections, send UDP packets of data, listen on arbitrary TCP and UDP ports, carry out port scanning, transfer data from one server to another. The netcat utility is used for almost anything under the sun involving TCP, UDP, or UNIX-domain sockets. This tool is very popular amongst System Administrators and Network Administrators because of its wide range of capabilities. The netcat utility or nc is often referred to as the Swiss Army Knife for working with TCP/IP networks. Linux netcat - nc command examples netcat - nc - Utility
