In this article, I will take you through the steps to install netcat(nc) command on Linux(Ubuntu 18.04 /20.04) in 7 Easy Steps. nc is a free and open source utility to read and write data across networks using UDP or TCP connections. It is a very handy tool often used by Linux and System Administrators to perform various network related tasks. It provides excellent port scanning and listening capabilities, be it a TCP or UDP traffic.
Along with this you can also use this utility to transfer a file based on the specific
port number
. We will see some more important features in upcoming articles but for now we will the steps to install netcat(nc) utility on Ubuntu 18.04/20.04 based systems in great detail. More on netcat(nc)
Man
Page.
How to Install netcat(nc) command on Linux(Ubuntu 18.04 / 20.04)
a) You should have a running
Ubuntu 18.04/20.04
Server.
b) You should have
sudo
or
root
access to run privileged commands.
c) You should have
apt
or
apt-get
utility available in your Server.
Step 2: Update Your Server
Before installing any new package in the System, it is always advisable to check for any latest available updates using
apt-get update
command as shown below. If any of the package needs upgradation, then upgrade it by using
apt-get upgrade
command.
root@cyberithub:~# apt-get install netcat
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
dmeventd libaio1 libdevmapper-event1.02.1 liblvm2cmd2.03 libreadline5 thin-provisioning-tools
Use 'apt autoremove' to remove them.
The following NEW packages will be installed:
netcat
0 upgraded, 1 newly installed, 0 to remove and 177 not upgraded.
Need to get 2,172 B of archives.
After this operation, 15.4 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu focal/universe amd64 netcat all 1.206-1ubuntu1 [2,172 B]
Fetched 2,172 B in 0s (5,464 B/s)
Selecting previously unselected package netcat.
(Reading database ... 182228 files and directories currently installed.)
Preparing to unpack .../netcat_1.206-1ubuntu1_all.deb ...
Unpacking netcat (1.206-1ubuntu1) ...
Setting up netcat (1.206-1ubuntu1) ...
Step 4: Verify Installation
Once it is successfully installed, you can verify the installation path by using
dpkg -L netcat
. This will show all the installed files path of netcat package.
Now that netcat(nc) is installed in the System, it is time to test this utility. This can be done by checking Let's say
google.com
remote https port by using
nc -vz google.com 443
command as shown below.
root@cyberithub:~# nc -vz google.com 443
Connection to google.com 443 port [tcp/https] succeeded!
-v :
verbose mode
-z :
Zero-I/O mode [used for scanning]
Step 6: Check all the Available Options
If you want to check all the options available with
nc command
then you need to use
nc -h
command as shown below.
In case you decide to uninstall netcat utility from your System due to certain reasons then you can do that by using
apt-get remove netcat
command as shown below.
root@cyberithub:~# apt-get remove netcat
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
dmeventd libaio1 libdevmapper-event1.02.1 liblvm2cmd2.03 libreadline5 thin-provisioning-tools
Use 'apt autoremove' to remove them.
The following packages will be REMOVED:
netcat
0 upgraded, 0 newly installed, 1 to remove and 177 not upgraded.
After this operation, 15.4 kB disk space will be freed.
Do you want to continue? [Y/n] Y
(Reading database ... 182231 files and directories currently installed.)
Removing netcat (1.206-1ubuntu1) ...