in

LinuxLinux

How to View TCP and UDP Ports in Ubuntu Linux?

Commands to view all tcp and udp connections available on your Ubuntu Linux PC!

View UDP and TCP Connections on Linux

V

iew TCP & UDP Connections in Linux: Finding ports is the essential process while troubleshooting your Linux server. It is important to know all the connections of your server. In this article, we described about 4 types of commands which actually helps you to find the available TCP and UDP connections on your server. Lets get into the tutorial.

Jump To:

Using the SS command to find TCP and UDP Connections:

It is possible to find all the available TCP and UDP connections on your server using SS command. Follow the below command to do,

$ss -lntup

The output of the following command is,

ss -lntup command output
ss -lntup command output

From the above image, the TCP and UDP connections available on your server are listed.

Using the NETSTAT command to find TCP and UDP Connections:

NETSTAT command will help you find the TCP and UDP connections on your server. You need to install the “NETSTAT” utility on your system. Use the below command to install the netstat utility:

$sudo apt install net-tools

After the installation process got completed, now you need to run the below command to find all the listening TCP and UDP ports in your system.

$netstat -ltu

Command Explanation:

  • l: List all the listening connections
  • t: List all the available TCP connections
  • u: List all the available UDP connections.
Check this too  Basic Linux Commands- Ever Green Commands For Quick Actions

The output of the netstat -ltu command is,

[email protected]:~$ netstat -ltu
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 localhost:5939          0.0.0.0:*               LISTEN     
tcp        0      0 localhost:domain        0.0.0.0:*               LISTEN     
tcp        0      0 localhost:ipp           0.0.0.0:*               LISTEN     
tcp        0      0 localhost:9050          0.0.0.0:*               LISTEN     
tcp6       0      0 ip6-localhost:ipp       [::]:*                  LISTEN     
udp        0      0 localhost:domain        0.0.0.0:*                          
udp        0      0 tecrobust-eoaner:bootpc 0.0.0.0:*                          
udp        0      0 0.0.0.0:53832           0.0.0.0:*                          
udp        0      0 0.0.0.0:ipp             0.0.0.0:*                          
udp        0      0 224.0.0.251:mdns        0.0.0.0:*                          
udp        0      0 224.0.0.251:mdns        0.0.0.0:*                          
udp        0      0 224.0.0.251:mdns        0.0.0.0:*                          
udp        0      0 0.0.0.0:mdns            0.0.0.0:*                          
udp6       0      0 [::]:54269              [::]:*                             
udp6       0      0 [::]:mdns               [::]:*                             
[email protected]:~$ 

From the above output, you may find the available TCP and UDP connections on your server.

Using the LSOF command to find TCP and UDP Connections:

The LSOF command can be used to find the TCP and UDP all available connections on your server. Use the below command to do:

$lsof -i tcp

The above command will display all the available TCP connections on your server.

[email protected]:~$ lsof -i tcp
COMMAND  PID      USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
chrome  2861 tecrobust   25u  IPv4 255261      0t0  TCP tecrobust:59260->cloudfront.net:https (ESTABLISHED)
chrome  2861 tecrobust   28u  IPv6 255265      0t0  TCP tecrobust:50184->[2606:4700:30::681f:422c]:https (ESTABLISHED)
chrome  2861 tecrobust   29u  IPv4 259829      0t0  TCP tecrobust:37660->amazonaws.com:https (ESTABLISHED)
chrome  2861 tecrobust   30u  IPv6 184305      0t0  TCP tecrobust:40310->1e100.net:https (ESTABLISHED)
chrome  2861 tecrobust   31u  IPv4 252809      0t0  TCP tecrobust:43282->104.244.42.130:https (ESTABLISHED)
chrome  2861 tecrobust   42u  IPv4 262421      0t0  TCP tecrobust:59330->cloudfront.net:https (ESTABLISHED)
chrome  2861 tecrobust   48u  IPv4 265519      0t0  TCP tecrobust:36882->amazonaws.com:https (ESTABLISHED)
chrome  2861 tecrobust   55u  IPv4 259995      0t0  TCP tecrobust:54386->amazonaws.com:https (ESTABLISHED)
chrome  2861 tecrobust   58u  IPv4 184306      0t0  TCP tecrobust:58848->151.101.36.233:https (ESTABLISHED)
chrome  2861 tecrobust   62u  IPv4 252808      0t0  TCP tecrobust:46300->net:https (ESTABLISHED)
chrome  2861 tecrobust   70u  IPv4 206694      0t0  TCP tecrobust:38984->amazonaws.com:https (ESTABLISHED)
chrome  2861 tecrobust   73u  IPv4 165549      0t0  TCP tecrobust:43330->104.244.42.130:https (ESTABLISHED)
chrome  2861 tecrobust   90u  IPv6 257665      0t0  TCP tecrobust:51316->fbcdn.net:https (ESTABLISHED)
[email protected]:~$ 

You can see the available all TCP connections on your server from the above output.

Check this too  Linux Ubuntu 18.04.2 LTS Edition Released, Download & What's New In it!!

To find the available UDP connections:

$lsof -i udp

The output of the command is,

[email protected]:~$ lsof -i udp
COMMAND  PID      USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
chrome  2820 tecrobust  135u  IPv4 253404      0t0  UDP 224.0.0.251:mdns 
chrome  2861 tecrobust   40u  IPv4  58039      0t0  UDP 224.0.0.251:mdns 
chrome  2861 tecrobust   51u  IPv4 206671      0t0  UDP 224.0.0.251:mdns 
chrome  2861 tecrobust   61u  IPv6 265117      0t0  UDP tecrobust:45650->1e100.net:443 
chrome  2861 tecrobust   71u  IPv6 265075      0t0  UDP tecrobust:41318->1e100.net:443 
[email protected]:~$ 

The above output displays the available UDP connections on your server.

Using the NMAP command to find TCP and UDP Connections:

First, you need to install the NMAP utility on your server. Use the below command to install the Nmap utility tool.

$sudo apt install nmap

After installation, you need to use the below command to display TCP and UDP connections on your server.

$sudo nmap -sT -O localhost

The command will display all the available TCP connection on your server,

[email protected]:~$ sudo nmap -sT -O localhost
Starting Nmap 7.80 ( https://nmap.org ) at 2019-11-07 00:36 IST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000079s latency).
Not shown: 998 closed ports
PORT     STATE SERVICE
631/tcp  open  ipp
9050/tcp open  tor-socks
Device type: general purpose
Running: Linux 2.6.X
OS CPE: cpe:/o:linux:linux_kernel:2.6.32
OS details: Linux 2.6.32
Network Distance: 0 hops

OS detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 1.53 seconds
[email protected]:~$
$sudo nmap -sU localhost

The command will display all the available UDP connection on your server,

[email protected]:~$ sudo nmap -sU localhost
Starting Nmap 7.80 ( https://nmap.org ) at 2019-11-07 00:36 IST
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000013s latency).
Not shown: 998 closed ports
PORT     STATE         SERVICE
631/udp  open|filtered ipp
5353/udp open|filtered zeroconf

Nmap done: 1 IP address (1 host up) scanned in 1.34 seconds
[email protected]:~$ 

Verdict:

That’s it. This is how you can use the netstat, lsof, nmap & ss commands to display all the available TCP and UDP connections on your system and server. If you have any queries related to this topic and then feel free to comment us below.

Check this too  The Easy Hacks In Linux Using Command Line Codes, Command Line Hacks
Article Review
  • Article Explanation
  • Commands Provided
  • Images Explanation
  • Alternate Commands
4.8

Summary

For more articles, Kindly visit our HomePage

Leave a Reply

Your email address will not be published. Required fields are marked *

Written by Rachel

I'm Rachel, From Arizona. Am playing the "Content Management" Role in Tec Robust. I started working in TR from Jan 2019. Big Marvel Fan.

Contact me:
tecrobust [@] gmail.com
Sub: Message to Rachel

KdenLive for Ubuntu

Kdenlive for Ubuntu- Install Kdenlive on Ubuntu 18.04 LTS & 19.10

Drawing Image Editor for Ubuntu- Install Drawing on Ubuntu 18.04 LTS & 19.10