Image

Knowledge base → Monitoring a network on Linux using the tshark utility on the Command Line

[Virtual servers]
Date of publication: 28.03.2024

To monitor the network on the Linux Debian 12 operating system, install the tshark utility on the command line - this is the console version of the WireShark program.

1. Installation

apt update
apt install tshark

2. Examples of use

2.1 Listing all interfaces

tshark -D
1. enp3s0
2. any
3.lo (Loopback)
4. wlp2s0
5. enp1s0
6.bluetooth0
7.bluetooth monitor
8.nflog
9.nfqueue
10.dbus-system
11.dbus-session
12. ciscodump (Cisco remote capture)
13. dpauxmon (DisplayPort AUX channel monitor capture)
14. randpkt (Random packet generator)
15. sdjournal (systemd Journal Export)
16. sshdump (SSH remote capture)
17. udpdump (UDP Listener remote capture)
18. wifidump (Wi-Fi remote capture)

2.2 Monitoring the network interface

tshark -i enp3s0
Capturing on 'enp3s0'
  ** (tshark:4003) 00:29:16.013682 [Main MESSAGE] -- Capture started.
  ** (tshark:4003) 00:29:16.013782 [Main MESSAGE] -- File: "/tmp/wireshark_enp3s0RQIBL2.pcapng"
     1 0.000000000 192.zzz.1.zzz → 192.xxx.1.xxx SSH 298 Server: Encrypted packet (len=244)
     2 0.002655201 192.zzz.1.zzz → 192.xxx.1.xxx TCP 60 60466 → 22 [ACK] Seq=1 Ack=245 Win=510 Len=0

2.3 Monitoring the network interface UDP protocol

tshark -i enp3s0 udp
Capturing on 'enp3s0'
  ** (tshark:4031) 00:31:45.874197 [Main MESSAGE] -- Capture started.
  ** (tshark:4031) 00:31:45.874342 [Main MESSAGE] -- File: "/tmp/wireshark_enp3s0S5KIL2.pcapng"
     1 0.000000000 192.xxx.1.xxx → 239.255.255.250 UDP 122 39749 → 51200 Len=80
     2 0.023937161 192.zzz.1.zzz → 239.255.255.250 SSDP 483 NOTIFY * HTTP/1.1
     4 0.054497234 192.zzz.1.zzz → 239.255.255.250 SSDP 492 NOTIFY * HTTP/1.1

2.4 Monitor only a specific IP

tshark -i enp3s0 host 192.zzz.1.zzz

2.5 Monitoring only on a specific port

tshark -nnSX port 443

2.6 Monitoring by specific IP in HEX mode

tshark -i enp3s0 -x host 192.zzz.1.zzz
Capturing on 'enp3s0'
  ** (tshark:4111) 00:35:37.357806 [Main MESSAGE] -- Capture started.
  ** (tshark:4111) 00:35:37.357914 [Main MESSAGE] -- File: "/tmp/wireshark_enp3s0LOI7K2.pcapng"
0000 08 d2 3e ef 91 24 68 1d ef 3f 0a 0c 08 00 45 10 ..>..$h..?....E.
0010 01 1c ce 7b 40 00 40 06 e6 f0 c0 a8 01 7e c0 a8 ...{@.@......~..
0020 01 91 00 16 ec 32 43 04 e1 79 16 bc f7 ae 50 18 .....2C..y....P.
0030 01 f5 85 6e 00 00 00 00 00 d0 5a f2 ae a9 d0 18 ...n......Z.....

2.7 Logging

tshark -w /tmp/tshark-log.pcap -i enp3s0 -x host 192.zzz.1.zzz

2.8 Viewing the log file

tshark -r /tmp/tshark-log.pcap

There are several utilities for network monitoring in the console, for example netstat, tcpdump, iftop, nload.





No Comments Yet