Linux View network configuration, test network connection

View network interface information----------------------ifconfig

  • View all active network interface information
    • Execute ifconfig command
  • View specified network interface information
    • ifconfig + interface

Example:

ifconfig ens33

Insert picture description here

  • inet: IP address, such as (192.168.1.188)
  • netmask: subnet mask, such as (255.255.255.0)
  • broadcast: broadcast address, such as (192.168.1.255)
  • ether: MAC address, such as (00:0c: 29:e8:a2:cf)
    In addition to this, you can also learn the number of data packets sent and received through the network interface through "TX", "RX" and other information. Traffic and more attributes.

View routing table entries----------------------route

  • View or set the routing table information in the host (the information is displayed in digital form)
    • route -n

The difference between route and route -n
Insert picture description here
Insert picture description here

Check the network connection ---------------------- netstat

  • View the system's network connection status, routing table, interface statistics and other information
    • netstat [options]
  • Common options
    • -a: Display all active network connection information in the host (including monitoring and non-monitoring service ports).
    • -n: Display related host address, port and other information in digital form.
    • -r: Display routing table information.
    • -I: Display the network connection and port information in the Listening state.
    • -t: View TCP (Transmission Control Protocol, Transmission Control Protocol) related information.
    • -a: Display all active network connection information in the host (including monitoring and non-monitoring service ports).
    • -p: Display the process number and process name information associated with the network connection (this option requires root privileges).

In addition to netstat, the ss command can also view the network connection. It is the abbreviation of Socket Statistics, which 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 it is faster and more efficient than netstat. To use the ss command, first make sure that the iproute package has been installed, you can install it through yum.

  • -h: --help Use this option to get more help.
  • -V: --version displays the version number of the software.
  • -t: --tcp displays sockets of TCP protocol.
  • -u: --udp displays the sockets of the UDP protocol.
  • -n: --numeric does not resolve the name of the service, such as "22" port will not be displayed as "ssh".
  • -1: --listening Only display ports that are in the listening state.
  • -p: --processes displays the processes listening on the port.
  • -a: --all For TCP protocol, it includes both the listening port and the established connection.
  • -r: --resolve interprets IP as domain name and port number as protocol name.

The output of the ss command can provide socket information of TCP and UDP, as well as persistent connections established by various services.
Familiarity with this command helps to better discover and solve system performance problems.

Trace data packet---------------------- traceroute

  • Test the network nodes that pass from the current host to the destination host
    • Traceroute target host address

Example:

traceroute 192.168.1.190

Insert picture description here

Domain name resolution ---------------------- nslookup

  • Test DNS domain name resolution
    • nslookup target host address

Example:

nslookup www.baidu.com

Insert picture description here

Set network interface parameters----------------------ifconfig

  • Set the IP address and subnet mask of the network interface
    • ifconfig network interface ip address

Example:

ifconfig ens33:2 190.0.0.10
ifconfig ens33:3 190.0.0.110 netmask 255.255.255.0

Insert picture description here
Insert picture description here

  • Disable or reactivate the network card
    • ifconfig network interface up /ifup network interface--------------##Activate the network card
    • ifconfig network interface down /ifdown network interface--------------##Disable network card

Example:
Insert picture description here

Set routing record----------------------route

  • Route records added to the specified network segment
    • route add -net network segment address gw IP address
  • Delete routing records to the specified network segment
    • route del -net network segment address
  • Add a default gateway record to the routing table
    • route add default gw IP address
  • Delete the default gateway record in the routing table
    • route del default gw IP address

Modify hostname----------------------hostname

hostname host name (one-time)
hostnamectl set-hostname host name (permanent modification)

Guess you like

Origin blog.csdn.net/weixin_48190875/article/details/107618786