Network management related commands

1. Command netstat to display information such as local network connection, running port and routing table

netstat command: used to display various network related information, such as network connection, routing table, interface status, dead link, multicast membership, etc.

options

-a : list all network connections in the system

-t : List TCP data

-u : List UDP data

-l : List listening network services

-n : Display services by port instead of service name

-p : List the process ID (pid) of the service

-s : Statistics by each protocol

-c : Execute the command at a fixed time

-r : routing information

[root@zcf ~]# netstat -tlunp
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      1586/sshd: root@pts
tcp        0      0 0.0.0.0:111             0.0.0.0:*               LISTEN      753/rpcbind
tcp        0      0 192.168.122.1:53        0.0.0.0:*               LISTEN      1358/dnsmasq
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      1187/sshd
tcp        0      0 127.0.0.1:631           0.0.0.0:*               LISTEN      1188/cupsd
tcp6       0      0 ::1:6010                :::*                    LISTEN      1586/sshd: root@pts
tcp6       0      0 :::3306                 :::*                    LISTEN      1564/mysqld
tcp6       0      0 :::111                  :::*                    LISTEN      753/rpcbind

Definition of each field:

proto: The protocol of the data packet, divided into TCP and UDP

Recv-Q: The number of packets that indicate that the received data has been cached locally, but has not been taken away by the process

Send-Q: The data packet that the other party has not received, or that there is no ACK reply, is still in the local buffer.

Local Address: local IP: port, through the port you can know which services are enabled at this level

Foreign Address : remote host: port is the IP that uses that port to connect to the machine

State: connection state, mainly two states of established connection (ESTABLISED) and listening (LISTEN)

PID/Program name: main process ID and process command

Active UNIX domain sockets (servers and established)
Proto RefCnt Flags       Type       State         I-Node   Path
unix  2      [ ACC ]     STREAM     LISTENING     9223     /run/systemd/journal/stdout
unix  2      [ ]         DGRAM                    20746    /var/run/chrony/chronyd.sock
unix  5      [ ]         DGRAM                    9226     /run/systemd/journal/socket
unix  2      [ ACC ]     STREAM     LISTENING     19210    /var/run/libvirt/virtlockd-sock
unix  20     [ ]         DGRAM                    9228     /dev/log
unix  2      [ ACC ]     STREAM     LISTENING     19213    /var/run/avahi-daemon/socket
unix  2      [ ACC ]     STREAM     LISTENING     19217    /run/dbus/system_bus_socket
unix  2      [ ACC ]     STREAM     LISTENING     19221    /var/run/libvirt/virtlogd-sock

Field definition:

Proto: protocol, usually linux

Refcnt: The number of processes connected to this Socket (socket)

Flags: connection identification

Type: Socket access type

State: connection state, mainly two states of established connection (ESTABLISED) and listening (LISTEN)

I-node: the inode number of the program file

path: the path of the Socket program, or the output path of the related data

2. Configure the network or command ss to display the current network interface status

The ss command is used to display socket status.

Common options:

-t : connection of tcp protocol

-u : udp protocol connection

-l : connection listening status

-a : connections in all states

-n: Display in numeric format

-o : state

-s : List current socket details

3. Get the route (gateway) from the current host to the target host

Use of traceroute and mtr commands

1.traceroute command:

[root@zcf ~]# traceroute  www.baidu.com
traceroute to www.baidu.com (14.215.177.38), 30 hops max, 60 byte packets
 1  gateway (192.168.150.2)  0.106 ms  0.113 ms  0.091 ms
 2  * * *
 3  * * *
 4  * * *
 5  * * *
 6  * * *
 7  * * *
 8  * * *
 9  * * *
10  * * *
11  * * *

2.mtr command:

Options:

-s: used to specify the size of the ping packet

-r: reported mode display

[root@zcf ~]# mtr -r 192.168.150.129
Start: Thu Aug 11 21:14:54 2022
HOST: zcf                         Loss%   Snt   Last   Avg  Best  Wrst StDev
  1.|-- zcf                        0.0%    10    0.1   0.1   0.1   0.1   0.0

The first column: shows the IP address and the local domain name

The second column: is the packet loss rate of each corresponding IP displayed

The third column: Snt: 10 sets the number of packets sent per second, the default value is 10

Fourth column: the most recent return delay displayed

The fifth column: the average, is the average delay in sending ping packets

Column 6: The one with the shortest delay

Column 7: longest delay

Eighth column: time standard deviation

4. Communicate with the remote host or obtain the information command of the corresponding port of the host telnet

telnet is to check whether a port is accessible. When we are engaged in development, the port we often use is 8080. Then you can start the server and use telnet to see if the port is available.

telnet ip port : Check whether a certain port on a certain machine can be accessed

[root@zcf bin]# telnet 192.168.150.129 80
Trying 192.168.150.129...
Connected to 192.168.150.129.

5. Download the software command wget from the network and copy the command scp

1.wget is a free tool for automatically downloading files from the Internet.

Common options:

-o : specify the directory

-O: rename

2.scp is a SSH-based tool for copying or copying directories between different linux systems.

-r : means recursive copy directory

-p : keep the original permission information of the file

Tags: Java network programming language

Posted by Spitfire on Mon, 12 Sep 2022 21:01:50 +0300