[Linux] RHCE exam preparation review network communication netstat and ping commands

netstat command

netstat command comes from the abbreviation of the English phrase "network statistics". Its function is to display various network related information, such as network connection status, routing table information, interface status, NAT, multicast members, etc.

netstat command is not only applied to Linux system, but also supported by default in Windows XP, Windows 7, Windows 10 and Windows 11, and the available parameters are the same. Experienced operation and maintenance personnel can start it directly.

Syntax format: netstat [parameter]
parameterfunction
-aDisplays the sockets in all connections
-pDisplays the program ID and program name of the Socket being used
-lOnly the service status that is listening is listed
-tDisplays the connection status of TCP transmission protocol
-uDisplays the connection status of UDP transport protocol
-iDisplay web interface information form
-rDisplay routing table information
-nUse the IP address directly, not through the domain name server

example

Displays all connection information in the system network status

[root@monster ~]# netstat -a
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State      
tcp        0      0 0.0.0.0:ssh             0.0.0.0:*               LISTEN     
tcp        0      0 localhost:smtp          0.0.0.0:*               LISTEN     
tcp        0      0 0.0.0.0:esmagent        0.0.0.0:*               LISTEN 

Displays the UDP connection port number usage information in the system network status

[root@monster ~]# netstat -apu
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name    
udp        0      0 localhost:323           0.0.0.0:*                           802/chronyd         
udp6       0      0 localhost:323           [::]:*                              802/chronyd 

Displays the current status information of the network card

[root@monster ~]# netstat -i
Kernel Interface table
Iface             MTU    RX-OK RX-ERR RX-DRP RX-OVR    TX-OK TX-ERR TX-DRP TX-OVR Flg
ens192           1500   582241      0      0 0        380009      0      0      0 BMRU
lo              65536  5998466      0      0 0       5998466      0      0      0 LRU

Display network routing table status information

[root@monster ~]# netstat -r
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
default         gateway         0.0.0.0         UG        0 0          0 ens192
192.168.170.0   0.0.0.0         255.255.255.0   U         0 0          0 ens192

ping command

The function of ping command is to test the network connectivity between hosts, send data packets based on ICMP transmission protocol and ask the other host to reply. If the network function of the other host is OK and the firewall releases traffic, we will reply to this information, and we can know that the other host system is online and running normally.

Syntax format: ping [parameter] Target host
parameterfunction
-cSpecify the number of times to send messages
-iSpecify the interval between sending and receiving messages
-sSet packet size
-vDisplay the execution process of the instruction in detail

example

Test network connectivity between

[root@monster ~]# ping 192.168.159.236
PING 192.168.159.236 (192.168.159.236) 56(84) bytes of data.
64 bytes from 192.168.159.236: icmp_seq=1 ttl=127 time=0.816 ms
64 bytes from 192.168.159.236: icmp_seq=2 ttl=127 time=1.02 ms
64 bytes from 192.168.159.236: icmp_seq=3 ttl=127 time=0.822 ms
64 bytes from 192.168.159.236: icmp_seq=4 ttl=127 time=0.669 ms
64 bytes from 192.168.159.236: icmp_seq=5 ttl=127 time=0.582 ms
64 bytes from 192.168.159.236: icmp_seq=6 ttl=127 time=0.724 ms
^C
--- 192.168.159.236 ping statistics ---
6 packets transmitted, 6 received, 0% packet loss, time 116ms
rtt min/avg/max/mdev = 0.582/0.771/1.015/0.138 ms
[root@monster ~]# 

Test the network connectivity between, and limit the sending of request packets to 3 times

[root@monster ~]# ping -c 3 192.168.159.236
PING 192.168.159.236 (192.168.159.236) 56(84) bytes of data.
64 bytes from 192.168.159.236: icmp_seq=1 ttl=127 time=0.858 ms
64 bytes from 192.168.159.236: icmp_seq=2 ttl=127 time=0.906 ms
64 bytes from 192.168.159.236: icmp_seq=3 ttl=127 time=0.707 ms

--- 192.168.159.236 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 33ms
rtt min/avg/max/mdev = 0.707/0.823/0.906/0.091 ms
[root@monster ~]# 

Send the request packet 3 times with an interval of 3 seconds

[root@monster ~]# ping -c 3 -i 3 192.168.159.236
PING 192.168.159.236 (192.168.159.236) 56(84) bytes of data.
64 bytes from 192.168.159.236: icmp_seq=1 ttl=127 time=0.772 ms
64 bytes from 192.168.159.236: icmp_seq=2 ttl=127 time=0.691 ms
64 bytes from 192.168.159.236: icmp_seq=3 ttl=127 time=0.544 ms

--- 192.168.159.236 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 26ms
rtt min/avg/max/mdev = 0.544/0.669/0.772/0.094 ms
[root@monster ~]# 

Tags: Linux Operation & Maintenance network server Ping netstat

Posted by perrij3 on Sun, 22 May 2022 03:35:27 +0300