Cyberithub

How to Install netcat(nc) command on Linux(Ubuntu 18.04/20.04) in 7 Easy Steps

Advertisements

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) in 7 Easy Steps

How to Install netcat(nc) command on Linux(Ubuntu 18.04 / 20.04)

Also Read: How to Install GNOME Desktop(GUI) on CentOS 7

Step 1: Prerequisites

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.

Advertisements
root@cyberithub:~# apt-get update
Hit:1 http://in.archive.ubuntu.com/ubuntu focal InRelease
Hit:2 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease
Hit:3 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease
Hit:5 http://ppa.launchpad.net/nilarimogard/webupd8/ubuntu focal InRelease
Hit:6 https://dl.google.com/linux/chrome/deb stable InRelease
Get:7 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Hit:4 https://downloads.apache.org/cassandra/debian 40x InRelease
Get:8 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.6 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/universe amd64 DEP-11 Metadata [66.3 kB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/multiverse amd64 DEP-11 Metadata [2,464 B]
Fetched 223 kB in 6s (38.9 kB/s)
Reading package lists... Done

 

Step 3: Install Netcat(nc)

To install netcat from default Ubuntu repo, you need to use apt-get install netcat command as shown below. This will install the netcat utility along with all its required dependencies.

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.

root@cyberithub:~# dpkg -L netcat
/.
/usr
/usr/share
/usr/share/doc
/usr/share/doc/netcat
/usr/share/doc/netcat/copyright
/usr/share/doc/netcat/changelog.Debian.gz

 

Step 5: Using Netcat(nc)

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.

root@cyberithub:~# nc -h
OpenBSD netcat (Debian patchlevel 1.206-1ubuntu1)
usage: nc [-46CDdFhklNnrStUuvZz] [-I length] [-i interval] [-M ttl]
[-m minttl] [-O length] [-P proxy_username] [-p source_port]
[-q seconds] [-s source] [-T keyword] [-V rtable] [-W recvlimit] [-w timeout]
[-X proxy_protocol] [-x proxy_address[:port]] [destination] [port]
Command Summary:
-4 Use IPv4
-6 Use IPv6
-b Allow broadcast
-C Send CRLF as line-ending
-D Enable the debug socket option
-d Detach from stdin
-F Pass socket fd

 

Step 7: Uninstall Netcat(nc)

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) ...

Leave a Comment