View network connections of Linux Servers
technology
10 months ago
Network monitoring is an essential task for any system administrator, as it can help diagnose problems, optimize performance, and secure the network. In this blog, I will show you how to install and use some of the most popular tools for network monitoring on Linux, such as:
- netstat: A command-line tool that displays information about the network connections, routing tables, interface statistics, and more.
- pktstat: A tool that displays the bandwidth usage of each network interface, showing the current, average, and peak values.
How to Install netstat and pktstat
To install these tools on your Linux server, you can use the following commands:
- For Debian-based distributions (such as Ubuntu), use
sudo apt-get install net-tools pktstat
- For Arch-based distributions, use
sudo pacman -S net-tools pktstat
- For Red Hat-based distributions, use
sudo dnf install net-tools pktstat
How to Use netstat and pktstat
To use netstat, you can run the command netstat
with various options to filter and display the information you need. For example, to list only the active TCP and/or UDP connections, you can use the -t
and -u
options, respectively. To show the numerical addresses and ports instead of the hostnames and service names, you can use the -n
option. To show the process ID and name that owns each socket, you can use the -p
option. To show the state of each connection, you can use the -s
option.
For example, to list only the HTTP connections, you can use the following command:
netstat -tunp | grep :80
This will show the TCP and UDP connections that use port 80, which is the default port for HTTP. You will see the local address, the foreign address, the state, and the process ID and name for each connection.
root@ubuntu# netstat -tunp | grep :80 tcp 0 0 24.199.119.xx:80 177.231.24.212:43860 ESTABLISHED 458176/nginx: worke tcp 0 0 24.199.119.xx:80 177.231.24.212:42919 ESTABLISHED 458176/nginx: worke root@ubuntu# netstat -tunp | grep :443 tcp 0 0 24.199.119.xx:43086 3.223.179.78:443 ESTABLISHED 520140/bun tcp 0 0 24.199.119.xx:56634 52.40.50.104:443 ESTABLISHED 520140/bun tcp 0 0 24.199.119.xx:38102 44.199.146.189:443 ESTABLISHED 520140/bun tcp 0 0 24.199.119.xx:57028 54.91.109.128:443 ESTABLISHED 520140/bun tcp 0 0 24.199.119.xx:60610 34.234.148.207:443 ESTABLISHED 520140/bun tcp 0 0 24.199.119.xx:443 96.49.215.54:56259 ESTABLISHED 458176/nginx: worke tcp 0 0 24.199.119.xx:443 96.49.215.54:56269 ESTABLISHED 458176/nginx: worke tcp 0 0 24.199.119.xx:443 66.249.66.197:44987 TIME_WAIT - tcp 0 0 24.199.119.xx:443 96.49.215.54:56127 ESTABLISHED 458176/nginx: worke
To use pktstat, you can run the command pktstat
with the -i
option to specify the interface you want to monitor. For example, to monitor the eth0 interface, you can use the following command:
pktstat -i eth0
This will show the bandwidth usage of the eth0 interface in real time, with the following columns:
- Rate: The current data rate in bits per second (bps) or bytes per second (Bps), depending on the
-B
option. - Peak: The peak data rate in the last 10 seconds.
- Avg: The average data rate in the last 10 seconds.
- Total: The total amount of data transferred in the current session.
- Pkt: The number of packets transferred in the current session.
- Tag: The descriptive string of the packet class, such as the protocol, the source and destination addresses and ports, and the service name.
You can also use other options to customize the output of pktstat, such as:
-1
: Single-shot mode, which collects data for a specified time and then exits.-c
: Do not combine some packet classes into one class, such as multiple TCP connections.-F
: Show full hostnames instead of truncated ones.-n
: Do not resolve hostnames or service port numbers, just show numerical addresses and ports.-p
: Show packet counts instead of bit counts.-t
: Top mode, which sorts the display by bit count or packet count, depending on the-p
option.-w
: Specify the refresh interval in seconds.
You can also press some keys while pktstat is running to toggle some options, such as:
q
: Quit the program.Ctrl-L
: Redraw the screen.t
: Toggle the top mode.T
: Toggle the totals mode.w
: Change the wait time value.n
: Toggle the numeric mode.p
: Toggle the packets mode.b
orB
: Toggle the bps or Bps mode.f
orF
: Toggle the full hostnames mode.r
: Reset the collected statistics and flush the flow history and caches.l
: Show and sort flows by when they were last active.?
: Toggle the display of help/status text at the bottom of the screen.
root@ubuntu:~# pktstat -n
interface: eth0 bps % desc 93.5 0% tcp 119.164.22.4:43331 <-> 24.199.114.51:22 tcp 24.199.114.xx:22 <-> 80.210.26.105:44289 tcp 24.199.114.xx:22 <-> 87.6.135.137:42205 tcp 24.199.114.xx:22 <-> 87.6.135.137:42344 2.0k 9% tcp 24.199.114.xx:22 <-> 87.6.135.137:42478 7.8k 35% tcp 24.199.114.xx:22 <-> 87.6.135.137:42618 4.7k 21% tcp 24.199.114.xx:22 <-> 87.6.135.137:42735 317.3 1% tcp 24.199.114.xx:22 <-> 96.49.215.54:59441
You may also like:
D o you want to connect with people who share your interests, passions, and goals? Do you want to express yourself, showcase your talents, and discover new opportunities? Do you want to enjoy a safe and enjoyable platform that offers everything you need for your daily computing needs? If you answered yes to any of these questions, then you should join NXplan.com, the new all-in-one social platform that features blog, messaging, chat, inbox, and marketplace.
NXplan.com is more than just a social network.
It’s a social ecosystem that allows you to create, communicate, and collaborate with others in a variety of ways. You can:Create your own blog and share your thoughts, opinions, and experiences with the world. You can also follow other bloggers and get inspired by their content. Message your friends and family and stay in touch with them. You can also make new friends and join groups that match your interests.
Chat with other users and have fun conversations. You can also join live events and webinars and learn from experts and influencers. Manage your inbox and organize your emails. You can also send and receive files, photos, and videos with ease. Explore the marketplace and find products and services that suit your needs. You can also sell your own products and services and earn money.
NXplan.com is designed to provide you with a safe and enjoyable platform that respects your privacy and security.
You can: Control your own data and decide who can see and access your information. Report and block any abusive or inappropriate content or users. Enjoy a spam-free and ad-free environment that does not track or sell your data. Access the platform from any device and any browser, without any downloads or installations. NXplan.com is free to join and use, and you can get started in minutes. All you need is a valid email address and a password. You can also customize your profile and settings to make it your own.Ready to give it a try?
Join NXplan.com today and discover a new way of socializing online. You’ll be amazed by what you can do and who you can meet on NXplan.com. Don’t miss this opportunity to join the next big thing in social media. Register now and start your NXplan journey.Technology is nothing. What's important is that you have a faith in people, that they're basically good and smart, and if you give them tools, they'll do wonderful things with them
Top rated comment:
Make your comment up here!
Leave a comment
Like: Dislike: Delete