Table of Contents
In this article, i will take you through the steps to install netcat command in Linux. nc command in Linux can be used for variety of purposes like checking the status of remote ports, initiating chat services between server and client, start listening on some ports for incoming connections etc. Now a days there are lot of open source networking tools available in Linux Based Systems to perform network troubleshooting activity. netcat is one such tool.
In this session we will only look into the steps to install netcat on RedHat Based Systems. I will cover other networking tools in future articles. Since netcat package does not comes by default in RedHat Based systems, so we need to install it manually using below steps.
Install Netcat(nc) Command on Linux
Also Read: 17+ Popular nc command examples in Linux (RedHat/CentOS 7/8)
Step 1: Prerequisites
a)You need to have a running RedHat/CentOS 7/8 System.
b)You should have sudo
access to install netcat package.
c)Also you need to have yum
command installed in your system.
NOTE:
root
user to run all the commands below. You can use any user with sudo
access to run all these commands.Step 2: Update Your System
You need update all the packages to use latest updates before proceeding with the netcat package installation. Packages can be updated by running yum install -y
command as shown below. In this case, since system has all the latest updates installed hence there are no further updates available to install.
[root@localhost ~]# yum update -y Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile epel/x86_64/metalink | 6.4 kB 00:00:00 * base: mirrors.piconets.webwerks.in * epel: ftp.jaist.ac.jp * extras: mirrors.piconets.webwerks.in * updates: mirrors.piconets.webwerks.in base | 3.6 kB 00:00:00 epel | 4.7 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/3): extras/7/x86_64/primary_db | 190 kB 00:00:00 (2/3): epel/x86_64/updateinfo | 1.0 MB 00:00:01 (3/3): epel/x86_64/primary_db | 6.8 MB 00:00:17 No packages marked for update
Step 3: Install Netcat Package
Once system is updated you can install netcat package using yum install -y nc
command as shown below. This command will also install any dependent packages which needs to be installed with netcat package.
[root@localhost ~]# yum install -y nc Loaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.piconets.webwerks.in * epel: mirrors.piconets.webwerks.in * extras: mirrors.piconets.webwerks.in * updates: mirrors.piconets.webwerks.in Resolving Dependencies --> Running transaction check ---> Package nmap-ncat.x86_64 2:6.40-19.el7 will be installed --> Processing Dependency: libpcap.so.1()(64bit) for package: 2:nmap-ncat-6.40-19.el7.x86_64 --> Running transaction check ---> Package libpcap.x86_64 14:1.5.3-12.el7 will be installed --> Finished Dependency Resolution Dependencies Resolved ======================================================================================================================================================================== Package Arch Version Repository Size ======================================================================================================================================================================== Installing: nmap-ncat x86_64 2:6.40-19.el7 base 206 k Installing for dependencies: libpcap x86_64 14:1.5.3-12.el7 base 139 k Transaction Summary ======================================================================================================================================================================== Install 1 Package (+1 Dependent package) Total download size: 345 k Installed size: 740 k Downloading packages: (1/2): nmap-ncat-6.40-19.el7.x86_64.rpm | 206 kB 00:00:00 (2/2): libpcap-1.5.3-12.el7.x86_64.rpm | 139 kB 00:00:00 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ Total 500 kB/s | 345 kB 00:00:00 Running transaction check Running transaction test Transaction test succeeded Running transaction Installing : 14:libpcap-1.5.3-12.el7.x86_64 1/2 Installing : 2:nmap-ncat-6.40-19.el7.x86_64 2/2 Verifying : 2:nmap-ncat-6.40-19.el7.x86_64 1/2 Verifying : 14:libpcap-1.5.3-12.el7.x86_64 2/2 Installed: nmap-ncat.x86_64 2:6.40-19.el7 Dependency Installed: libpcap.x86_64 14:1.5.3-12.el7 Complete!
Step 4: Verify netcat package installation
After successful installation of netcat package, you can check the rpm db
to confirm if the netcat package is installed successfully using rpm
command as shown below.
[root@localhost ~]# rpm -qa | grep -i nmap-ncat nmap-ncat-6.40-19.el7.x86_64
Step 5: Test nc command
Now that we have netcat package installed successfully in the System, you can quickly verify the functionality of nc
command by checking google.com
port 443 as shown below. As you can check in the below output, system is currently able to reach to google.com
on port 443.
[root@localhost ~]# nc -vz google.com 443 Ncat: Version 7.50 ( https://nmap.org/ncat ) Ncat: Connected to 216.58.196.174:443. Ncat: 0 bytes sent, 0 bytes received in 0.07 seconds.
-v : Set verbosity level (can be used several times)
z : Zero-I/O mode, report connection status only
Check other options that can be used with nc command using -h flag as shown below.
[root@localhost ~]# nc -h Ncat 7.50 ( https://nmap.org/ncat ) Usage: ncat [options] [hostname] [port] Options taking a time assume seconds. Append 'ms' for milliseconds, 's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms). -4 Use IPv4 only -6 Use IPv6 only -U, --unixsock Use Unix domain sockets only -C, --crlf Use CRLF for EOL sequence -c, --sh-exec <command> Executes the given command via /bin/sh -e, --exec <command> Executes the given command --lua-exec <filename> Executes the given Lua script -g hop1[,hop2,...] Loose source routing hop points (8 max) -G <n> Loose source install netcat pointer (4, 8, 12, ...) -m, --max-conns <n> Maximum <n> simultaneous connections -h, --help Display this help screen -d, --delay <time> Wait between read/writes
I hope you liked this article on How to Install netcat command in Linux. Please let me know your feedback on Comment Box.
Popular Recommendations:-
RHEL/CentOS 8 Kickstart Example | Kickstart Generator
How to Enable or Disable SELinux Temporarily or Permanently on RedHat/CentOS 7/8
10 Popular Examples of sudo command in Linux(RedHat/CentOS 7/8)
9 useful w command in Linux with Examples
Awesome ! Thank you for the steps. I was troubleshooting AWS EC2 to RDS connectivity and was in need of nc. I am pretty novice on Linux/Unix. This was a cake walk.
Good Information. Please keep it up!!!
Thanks Satya for your valuable feedback.
thanks - from a windows person trying to see why a Linux box can't connect to a dhcp server on udp67/68... telnet doesn't work for udp, so netcat is perfect. Cheers
Excellent guide. Many thanks 🙂
Thank you very much for your info! It really worked.