This is the 18th day of my participation in the August Challenge

Linux environment deployment, network troubleshooting need to use a lot of commands, it is necessary to master some core commands. Here are some commands that are frequently mentioned in jobs and interviews.

ifconfig

Ifconfig is a tool for viewing, configuring, enabling, or disabling network interfaces.

View network interface information

Disable Enables the network interface

ifconfig eth0 down 
ifconfig eth0 up
Copy the code

ping

The ping command is used to test the connectivity and delay of a remote host based on ICMP.

Format: ping Parameter Destination host ADDRESS

  • -c: number of times. Indicates the number of times for sending ICMP packets. Otherwise, ICMP packets are always sent.
  • -i: indicates the interval at which two packets are sent. The default value is 1s
  • -s: Sets the packet size

netstat

Displays the network connection status, running ports, and routing table information of the local host.

  • -a: Displays sockets of all connections
  • -t: displays the status of all TCP connections
  • -u: displays the status of all UDP connections
  • -n: Displays the port number
  • -p: displays the PID and name of a process
  • -l: displays the network connections in LISTEN state

All connection information is displayed

netstat -an

Displays information about all TCP and UDP connections being monitored

Query which service occupies a port

In addition to using netstat to check port usage, you can also use lsof -i: port to check port usage

SS

The ss command displays network status information, including TCP/UDP connections and ports. Compared with netstat, the ss command displays more information and higher query efficiency.

  • -n: displays the IP address without DNS resolution
  • -l: Displays all listening sockets
  • -p: displays the socket process
  • -t: displays only TCP sockets
  • -u: displays only UDP sockets
  • -s: displays statistics on socket usage

telnet

Using the Telnet command, you can check whether the port of the remote server is open. Format: Telnet parameter host name /IP

route

Using the route command, you can display and manage the routing table of the Linux operating system.

View the routing table

SSH

The SSH command is a client connection tool of the OpenSSH suite. You can use the SSH encryption protocol to securely log in to a remote server in Linux.

Format: SSH parameter User@host name/IP address Command executed remotely

-p: indicates the SSH login port. The default port number is 22

-v: debugging mode

SSH -p 22 [email protected] # Log in to the remote server and enter exit to exit SSH -p 22 [email protected] "free -m" # Log in to the remote server and run the commandCopy the code

tcpdump

The tcpdump command is a packet analysis tool that intercepts network data packets and filters protocols, hosts, and ports.

Tcpdump (dump the Traffic on a network) is a powerful network analysis command line tool that captures and analyzes traffic packets that pass through the system. It is commonly used as a network fault analysis tool and security tool.

Supports multiple options and filtering rules applicable to a wide range of scenarios.

Because it is a command-line tool, it is good for collecting packets for post-mortem analysis on remote servers or devices without a graphical interface.

It supports filtering by network layer, protocol, host, network or port, and provides logical statements such as AND, OR, or not to help you get rid of useless information.

Format: tcpdump [option] [filter expression]

Common options of tcpdump

-c: stops capturing packets after receiving the specified number of packets. -w: writes data packets to the specified file. -e: displays the header information of the link layer. The default value is network interface 0. Any indicates all interfaces. -nn: the NAMES of IP addresses and port numbers are not resolved. -tttt: outputs the timestamp of the default format processed by date in each line. -v: displays the detailed command execution process. -vv: displays the command execution process in more detail. -x: lists data packets in hexadecimal codes.Copy the code

Tcpdump commonly used filter expressions

Tcpdump host 210.27.48.1: captures all packets received and sent by the host tcpdump -nn DST port 80: captures all data passing through port 80. Tcpdump-nn TCP: TCP filteringCopy the code