Linux network settings
table of Contents
- Linux network settings
-
- 1. View network interface information
- Two, view the host name
- Three, view routing table entries
- Four, check the network connection netstat
- Five, get socket statistics information ss
- Six, test network connection ping
- Seven, trace data packet traceroute
- 8. Domain name resolution nslookup
- Nine, the method of setting network parameters
- 10. Set the network interface parameters ifconfig
- 11. Set the route record route
-
- 1. The route added to the specified network is recorded
- 2. Delete the routing record to the specified network segment
- 3. Add the default gateway record to the routing table
- 4. Delete the default gateway record in the routing table
- 5. Permanently add a route-need to restart the network card service to take effect
- 12. Network interface configuration file
- Thirteen, enable and disable network interface configuration
- 14. Domain name resolution configuration file
- 15. Local host mapping file
1. View network interface information
1. View all active network interface information
ifconfig
2. View the information of the specified network interface
ifconfig 网络接口
Painted in red mtu1500, where mtu refers to the maximum transmission unit, its number of bytes is 1500 bytes,
Inappropriate local MTU value
1. When the local MTU value> the network MTU value————> unpacking is required, which will result in a decrease in efficiency
2. When the local MTU value <network MTU value————> does not exert the maximum transmission capacity
3. When the local MTU value = the network MTU value ---> this is the ideal local MTU value
Two, view the host name
1. View or temporarily set the current hostname
hostname [主机名]————这是临时的,重启或者下次开机之后就会失效
2. Permanently set the host name
hostnamectl set-hostname [主机名]
or
vim /etc/hostname————必须要设置在第一行才有效,并且设置完成后需重启系统才生效
Three, view routing table entries
route [-n]
Four, check the network connection netstat
1. 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-monitoring service ports)
-n: Display the relevant host address, port and other information in the form of numbers.
-t: View information related to the TCP protocol.
-u: Display information related to 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.
Five, get socket statistics information ss
View the network connection of the system and obtain socket statistics
ss [选项]
Common options:
-t、-u、-n、-l、-p、-a、-r
Six, test network connection ping
Test network connectivity
ping [options] target host
Seven, trace data packet traceroute
Test the network nodes that pass from the current host to the destination host
traceroute 目标主机地址
8. Domain name resolution nslookup
Test DNS domain name resolution
nslookup 目标主机地址 [DNS服务器地址]
Nine, the method of setting network parameters
1. Temporary configuration-use commands to adjust network parameters
- 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 invalid
2. Fixed settings-modify network parameters through configuration files
- Modify configuration files 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
10. Set the network interface parameters ifconfig
1. Set the IP address and subnet mask of the network interface
ifconfig 网络接口 ip地址 [netmask 子网掩码]
ifconfig 网络接口 ip地址[/子网掩码长度]
2. Disable or reactivate the network card
ifconfig 网络接口 up
ifconfig 网络接口 down
3. Set up virtual network interface
inconfig 网络接口:序号 ip地址
11. Set the route record route
1. The route added to the specified network is recorded
toute add -net 网段地址 gw ip地址
2. Delete the routing record to the specified network segment
route del -net 网段地址
3. Add the default gateway record to the routing table
route add default gw ip地址
4. Delete the default gateway record in the routing table
route del default gw ip address
5. Permanently add a route-need to restart the network card service to take effect
method one,
vim /etc/sysconfig/static-routes
any net any gw 192.168.80.2
any net 192.168.3.0/24 gw 192.168.80.2
any host 192.168.100.100 gw 192.168.80.2
systemctl restart network
Method Two,
vim /etc/sysconfig/network-scripts/ifcfg-ens33
default via 192.168.80.2 dev ens33——————默认路由的另一种格式 0.0.0.0/0 192.168.14.254 dev ens33
10.211.6.0/24 via 192.168.80.2 dev ens33
192.168.100.100 via 192.168.14.254 dev ens33
systemctl restart network
12. Network interface configuration file
1. The location of the configuration file
vim /etc/sysconfig/network-scripts/ifcfg-ens33
TYPE=Ethernet—————— Set the network card type
BOOTPROTO=static———— The way to obtain the IP address, "static" obtains the IP address statically, and "dhcp" obtains the IP address dynamically
IPADDR=192.168.241.3————IP Address
NETMASK=255.255.255.0————Subnet mask
GATEWAY=192.168.241.2————Gateway address
ONBOOT=yes————Automatically activate
DEVICE=ens33——————Network card name
Thirteen, enable and disable network interface configuration
1. Several ways to restart the network card
systemctl restart network
service network restart
/etc/init.d/network restart
2. Disable and enable designated network card
ifdown ens33————禁用ens33网络接口
ifup ens33————开启ens33网络接口
14. Domain name resolution configuration file
vim /etc/resolv.conf
Save the IP address of the DNS server that the machine needs to use
15. Local host mapping file
1. /etc/hosts file
- Save the mapping record of host name and ip address
2. Comparison of hosts file and DNS server
- By default, the system first searches for the analysis record from the hosts file
- The hosts file is only valid for the current host
- The hosts file can reduce the DNS query process, thereby speeding up access