Theory-(Linux network) Linux network settings


Preface

1. View and test the network

1. View network configuration

(1) ifconfig command

View all active network interface information

  • Execute ifconfig command to
    Insert picture description here
    view specified network interface information
    Insert picture description here

(2) route command

View or set the routing table information in the host
Insert picture description here

(3) netstat command

View the system's network connection status, routing table, interface statistics and other information.
Insert picture description here
It is an effective tool for understanding network status and troubleshooting network service failures. The following are several options commonly used in the netstat command:

  • -a: display all active network connection information in the host (including monitoring and non-monitoring service ports) ##common
  • -n: Display related host address, port and other information in the form of numbers ##commonly used
  • -r: Display routing information
  • -l: Display network connection and port information in the listening state
  • -t: Display TCP protocol related information ##Common
  • -u: display information related to UDP protocol ##common
  • -p: Display the process number and process name information associated with the network connection ('This option requires root privileges') ##commonly used

Insert picture description here
Usually the "-anpt" combination option is used to display all the TCP connection information in the current system in digital form, as well as the corresponding process information. Using the "grep" command in combination with the pipeline command, you can also filter out the required characteristic records in the results.
For example, check whether there is a service program that monitors the "TCP 22" port (standard Web service) in the machine: the
output information includes the PID number and process name
Insert picture description here

(4) ss command

Check the system's network connection and obtain socket statistics.
Insert picture description here
In addition to netstat, the ss command can also check the network connection. It is the abbreviation of Socket Statistics and is mainly used to obtain socket statistics. It can display output similar to the netstat command. But the advantage of ss is that it can display more and more detailed information about TCP and connection status, and is faster and more efficient than netstat. To use the ss command, first confirm that the iproute package has been installed, and you can install it through yum. The following are common options:

  • -h: Get more help through options
  • -V: Display the software version number
  • -t: Display sockets of TCP protocol
  • -u: Display sockets of UDP protocol
  • -n: Do not resolve the service name, such as "22" port will not be displayed as "sshd"
  • -l: Only display ports in the listening state
  • -p: Display the process of listening port
  • -a: For the TCP protocol, it contains both the listening port and the established connection
  • -r: interpret IP as domain name and port as protocol name
    Insert picture description here

2. Test the network connection

(1) ping command

Test network connectivity
Insert picture description here

(2) traceroute command

Track the routing path of data packets to
test the network nodes passing through from the current host to the destination host
Insert picture description here

(3) nslookup command

Test DNS domain name resolution
Insert picture description here

2. Set the network address parameters

In a Linux host, there are two basic methods to manually modify the network configuration :
Temporary configuration-Use commands to adjust network parameters
(usually used for maintenance)

  • Simple, fast, can directly modify the network parameters in operation
  • Generally only suitable for use in the process of debugging the network
  • After the system restarts, the changes made will be directly invalid

Fixed settings-modify network parameters through configuration files

  • Modify the configuration file of various network parameters
  • Suitable for use when setting fixed parameters for the server
  • Need to reload the network service or restart to take effect

1. Use network configuration commands

(1) ifconfig-set network interface parameters

Insert picture description here

(2) route command-set routing records

Insert picture description here

(3) hostname command-modify the host name

Insert picture description here

2. Modify the network configuration file

(1) Network interface configuration file

Insert picture description here
The default location of the configuration file of the network interface is "/etc/sysconfig/network-scripts/", and the file name format is "ifcfg-xxx", where xxx is the name of the network interface. The configuration file of the loopback interface lo is "ifcfg-lo".
E.g:
Insert picture description hereInsert picture description here

(2) Enable and disable network interface configuration

Insert picture description here

(3) Host name configuration file

Insert picture description here

(4) Domain name resolution configuration file

Insert picture description here

(5) Local host mapping file

Insert picture description here

Guess you like

Origin blog.csdn.net/ZG_66/article/details/107618135