Basic overview of Linux network settings

Linux network settings

View network settings

View network interface information

View all active network interface information

ifconfig

Insert picture description here

View specified network interface information

ifconfig 网络接口

Insert picture description here

View hostname

View or temporarily set the current hostname

hostname [主机名]

Permanently set the hostname

hostnamectl set-hostname [主机名]
vi hostname //设置完成后需要重启系统才生效

View routing table entry route

View or set the routing table information in the host
route [-n]
Insert picture description here

View network connection status netstat

View the system's network connection status, routing table, interface statistics and other information

netstat [选项]

Common options:

-a: Display all active network connection information in the host (including monitoring and non-listening service ports)
-n: Display the relevant host address, port and other information in the form of numbers
-t: View TCP-related information
-u: Display information related to the UDP protocol
-p: display the process number and process name information associated with the network connection (this option requires root privileges)
-r: display the routing table information
-l: display the network connection and port information in the monitoring state
Insert picture description here

Get socket statistics information ss

View the network connection of the system and obtain socket statistics

ss [选项]

Common options:

-t: Display the sockets of the TCP protocol
-u: Display the sockets of the UDP protocol
-n: Do not resolve the name of the service, such as "22" The port will not be displayed as "ssh"
-l: Only display the port in the listening state
-p: Display the process of listening port (Requires sudo on Ubuntu)
-a: For TCP protocol, it includes both the listening port and the established connection
-r: Interpret IP as domain name and port number as protocol name
Insert picture description here

Test network connection

ping command

Test network connectivity

ping [选项] 目标主机

Insert picture description here

Traceroute

Test the network nodes that pass from the current host to the destination host

traceroute 目标主机地址

Insert picture description here

Domain name resolution nslookup

Test DNS domain name resolution

nslookup 目标主机地址 [DNS服务器地址]

Use network configuration commands

Set the network interface parameters ifconfig

Set the IP address and subnet mask of the network interface

ifconfig 网络接口 IP地址 [netmask 子网掩码/子网掩码长度]

Disable or reactivate the network card

ifconfig 网络接口 up
ifconfig 网络接口 down

Set up a virtual network interface

ifconfig 网络接口:序号 IP地址

Insert picture description here

Set routing record route

Route records added to the specified network segment

route add  -net  网段地址  gw  IP地址

Delete routing records to the specified network segment

route  del  -net  网段地址

Add a default gateway record to the routing table

route  add  default  gw  IP地址

Delete the default gateway record in the routing table

route del  default  gw  IP地址

Modify the network configuration file

Modify hostname hostname

Set hostname

hostname 主机名
bash:启用新的shell会话

Network interface profile


ifcfg-ens33 in the /etc/sysconfig/network-scripts/ directory : the configuration file of the first Ethernet card

Insert picture description here

Enable and disable network interface configuration

Restart network network service

systemctl restart network

Disable and enable network interface

ifdown ens33
ifup ens33

Hostname profile

Modify the host name through the /etc/hostname file

vi /etc/hostname
仅识别第一行作为主机名,并且重启后生效

Modify the host name through hostnamectl

hostnamectl set-hostname www.bdqn.com
bash

Domain name resolution configuration file

/etc/resolv.conf文件
保存本机需要使用的DNS服务器的IP地址

Insert picture description here

Local host mapping file

/etc/hosts 文件
保存主机名与IP地址的映射记录

Insert picture description here

Comparison of hosts file and DNS server

By default, the system first finds the resolution record from the hosts file. The
hosts file is only valid for the current host. The
hosts file can reduce the DNS query process and speed up the access speed.

Guess you like

Origin blog.csdn.net/m0_53497201/article/details/114243041