Cyberithub

How to Install netstat on Ubuntu 20.04 LTS (Focal Fossa)

Advertisements

In this article, I will take you through the steps to install netstat on Ubuntu 20.04 LTS. netstat is a free and open source command line tool to list the port and protocol statistics. It can be used to display the status of TCP and UDP endpoints in table format, routing table information, and interface information. It is a very famous tool used mostly by Unix and Linux administrators all over the globe to troubleshoot any port and network interface issues.

It is shipped as part of net-tools package so to install this utility, you need to actually install net-tools package. It can be easily installed on almost all the Linux distribution but here we will see the steps to install netstat on Ubuntu 20.04 LTS System.

 

How to Install netstat on Ubuntu 20.04 LTS (Focal Fossa)

How to Install netstat on Ubuntu 20.04 LTS (Focal Fossa)

Also Read: How to Install Plex Media Server on Ubuntu 20.04 LTS (Focal Fossa)

Step 1: Prerequisites

a) You should have a running Ubuntu 20.04 LTS 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 a new package in the system, it is wise to first sync the system packages with the latest available updates from Ubuntu repo by using sudo apt update && sudo apt upgrade command as shown below.

cyberithub@ubuntu:~$ sudo apt update && sudo apt upgrade
[sudo] password for cyberithub:
Hit:1 https://downloads.plex.tv/repo/deb public InRelease
Get:2 https://dl.google.com/linux/chrome/deb stable InRelease [1,811 B]
Get:3 http://security.ubuntu.com/ubuntu focal-security InRelease [114 kB]
Get:4 https://dl.google.com/linux/chrome/deb stable/main amd64 Packages [1,093 B]
Hit:5 http://in.archive.ubuntu.com/ubuntu focal InRelease
Get:6 http://in.archive.ubuntu.com/ubuntu focal-updates InRelease [114 kB]
Get:7 http://security.ubuntu.com/ubuntu focal-security/main amd64 Packages [1,892 kB]
Get:8 http://in.archive.ubuntu.com/ubuntu focal-backports InRelease [108 kB]
Get:9 http://security.ubuntu.com/ubuntu focal-security/main i386 Packages [530 kB]
Get:10 http://security.ubuntu.com/ubuntu focal-security/main amd64 DEP-11 Metadata [40.7 kB]
Get:11 http://security.ubuntu.com/ubuntu focal-security/main amd64 c-n-f Metadata [11.5 kB]
Get:12 http://security.ubuntu.com/ubuntu focal-security/universe i386 Packages [574 kB]
.....................................................

 

Step 3: Install Netstat

Next step is to install netstat utility from default Ubuntu repo by using sudo apt install net-tools command as shown below. This will download and install the package along with all its dependencies.

cyberithub@ubuntu:~$ sudo apt install net-tools
[sudo] password for cyberithub:
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
libfwupdplugin1 libllvm11 libxmlb1
Use 'sudo apt autoremove' to remove them.
The following NEW packages will be installed:
net-tools
0 upgraded, 1 newly installed, 0 to remove and 45 not upgraded.
Need to get 196 kB of archives.
After this operation, 864 kB of additional disk space will be used.
Get:1 http://in.archive.ubuntu.com/ubuntu focal/main amd64 net-tools amd64 1.60+git20180626.aebd88e-1ubuntu1 [196 kB]
Fetched 196 kB in 1s (138 kB/s)
Selecting previously unselected package net-tools.
(Reading database ... 201454 files and directories currently installed.)
Preparing to unpack .../net-tools_1.60+git20180626.aebd88e-1ubuntu1_amd64.deb ...
Unpacking net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Setting up net-tools (1.60+git20180626.aebd88e-1ubuntu1) ...
Processing triggers for man-db (2.9.1-1) ...

 

Step 4: Check Version

After successful installation, you can check the installed version by using netstat --version command as shown below.

cyberithub@ubuntu:~$ netstat --version
net-tools 2.10-alpha
Fred Baumgarten, Alan Cox, Bernd Eckenfels, Phil Blundell, Tuan Hoang, Brian Micek and others
+NEW_ADDRT +RTF_IRTT +RTF_REJECT +FW_MASQUERADE +I18N +SELINUX
AF: (inet) +UNIX +INET +INET6 +IPX +AX25 +NETROM +X25 +ATALK +ECONET +ROSE -BLUETOOTH
HW: +ETHER +ARC +SLIP +PPP +TUNNEL -TR +AX25 +NETROM +X25 +FR +ROSE +ASH +SIT +FDDI +HIPPI +HDLC/LAPB +EUI64

 

Step 5: Verify Installation

You can also verify the installed files path by using dpkg -L net-tools command as shown below.

cyberithub@ubuntu:~$ dpkg -L net-tools
/.
/bin
/bin/netstat
/sbin
/sbin/ifconfig
/sbin/ipmaddr
/sbin/iptunnel
/sbin/mii-tool
/sbin/nameif
/sbin/plipconfig
/sbin/rarp
/sbin/route
/sbin/slattach
/usr
/usr/sbin
/usr/sbin/arp
/usr/share
/usr/share/doc
/usr/share/doc/net-tools
/usr/share/doc/net-tools/NEWS.Debian.gz
/usr/share/doc/net-tools/README
/usr/share/doc/net-tools/TODO
/usr/share/doc/net-tools/changelog.Debian.gz
/usr/share/doc/net-tools/copyright
/usr/share/man
...................................

 

Step 6: Using Netstat

Now that netstat utility is successfully installed, let's use it to list the status of TCP Port 32400 using sudo netstat -ntlp | grep -i 32400 command as shown below.

cyberithub@ubuntu:~$ sudo netstat -ntlp | grep -i 32400
tcp6 0 0 :::32400 :::* LISTEN 5768/Plex Media Ser

 

Step 7: Check all the available options

To check all the options available with netstat command, you need to use netstat --help command as shown below.

cyberithub@ubuntu:~$ netstat --help
usage: netstat [-vWeenNcCF] [<Af>] -r netstat {-V|--version|-h|--help}
netstat [-vWnNcaeol] [<Socket> ...]
netstat { [-vWeenNac] -i | [-cnNe] -M | -s [-6tuw] }

-r, --route display routing table
-i, --interfaces display interface table
-g, --groups display multicast group memberships
-s, --statistics display networking statistics (like SNMP)
-M, --masquerade display masqueraded connections

-v, --verbose be verbose
-W, --wide don't truncate IP addresses
-n, --numeric don't resolve names
--numeric-hosts don't resolve host names
--numeric-ports don't resolve port names
--numeric-users don't resolve user names
-N, --symbolic resolve hardware names
-e, --extend display other/more information
-p, --programs display PID/Program name for sockets
-o, --timers display timers
-c, --continuous continuous listing

-l, --listening display listening server sockets
-a, --all display all sockets (default: connected)
-F, --fib display Forwarding Information Base (default)
-C, --cache display routing cache instead of FIB
-Z, --context display SELinux security context for sockets

1 thought on “How to Install netstat on Ubuntu 20.04 LTS (Focal Fossa)”

Leave a Comment