View network configuration
Maximum mtu packet transfer rate
View network interface information ifconfig
- View all active network interface information
- Execute ifconfig command
- View specified network interface information
ifconfig network interface
[root@localhost ~]# ifconfig ens33 ens33 flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.4.11 netmask 255.255.255.0 broadcast 192.168.4.255 inet6 fe80.9106:d38b:670d:1a89 prefixlen 64 scopeid 0x20<link> ether 00:0c:29:3a:81:cc txqueuelen 1000(Ethernet) ..//Omit some contents
View host name hostname
- hostname command
- View or set the current hostname
hostname[host name]((Provisional)
- Example
[root@localhost ~]# hostname localhost.localdomain
View the route table entry route
route command
View or set routing table information in the host
route [-n]
Example
[root@localhost ~]# route -n Kernel IP routing table Destination Gateway Genmask Flags Metric Ref Use lface 0.0.0.0 192.168.4.1 0.0.0.0 UG 100 0 0 ens33 192.168.4.0 0.0.0.0 255.255.255.0 U 100 0 0 ens33
View network connectivity netstat
- netstat command
- View the network connection status, routing table, interface statistics and other information of the system
netstat [option]
- Common options
- -a,-n,-p,-t,-u,-r
[root@localhost~]# netstat -anpt | grep ":80" tcp60 0 :::80 :::* LISTEN 20563/httpd
Get socket statistics ss
- ss command
- Check the network connection of the system and obtain socket statistics
ss [option]
- Common options
- -t,-u,-n,-l,-p,-a,-r
[root@localhost ~]# ss -t state established Recv-Q Send-Q Local Address:Port Peer Address:Port 0 96 192.168.8.10:ssh 192.168.8.1:55213
Test network connection
Test network connection ping
- ping command
- Test network connectivity
ping[option]Target host
- Example
[root@localhost ~]# ping 192.168.4.110 PING 192.168.4.110 (192.168.4.110)56(84) bytes of data. 64 bytes from 192.168.4.110: icmp_seq=2 ttl=128 time=0.274 ms ^C Press Ctrl+C abort test ---192.168.4.110 ping statistics--- 2 packets transmitted, 2 received,0% packet loss, time 1162ms rtt min/avg/max/mdev = 0.274/0.484/0.694/0.210 ms
Trace packet traceroute
- traceroute command
- Test the network nodes passing from the current host to the destination host
traceroute Destination host address
- Example
[root@localhost ~]# traceroute 192.168.7.7 traceroute to 192.168.7.7 (192.168.7.7),30 hops max, 40 byte packets 1 (192.168.4.1)7.740 ms 15.581 ms 15.881 ms 2 (192.168.7.7)19.652 ms 19.995 ms 19.942 ms
Domain name resolution nslookup
- nslookup command
- Test DNS domain name resolution
nslookup Destination host address [DNS server address]
- Example
[root@localhost ~]# nslookup www.google.com Server: 202.106.0.20 DNS server address Address: 202.106.0.20#53 Non-authoritative answer: Name: www.l.google.com Analytic IP address Address:173.194.127.51
Using the network configuration command
How to set network parameters
-
Temporary configuration - use commands to adjust network parameters
- It is simple and fast, and can directly modify the network parameters in operation
- Generally, it is only suitable for use in the process of debugging the network
- After the system is restarted, the modifications will be invalid
-
Fixed settings - modify network parameters through the configuration file
- Modify the configuration file of various network parameters
- It is suitable for setting fixed parameters on the server
- It will not take effect until the network service is overloaded or restarted
Set network interface parameter ifconfig
- Set the IP address and subnet mask of the network interface
ifconfig network interface ip address [netmask Subnet mask] ifconfig network interface ip address [/Subnet mask length]
- Disable or reactivate the network card
ifconfig network interface up ifconfig network interface down
- Set virtual network interface
ifconfig network interface:Serial number IP address
Set route record
- The routing record added to the specified network segment
route add -net Network segment address gw IP address
- Delete the routing record to the specified network segment
route del -net Network segment address
- Adds 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 command
- Set host name
hostname Host name
Example
[root@localhost ~]# hostnamelocalhost.localdomain [root@localhost ~]# hostname www.bdqncom [root@localhost ~]# hostname www.bdqn.com [root@localhost ~]# bash enables a new Shell session [root@www ~]#
Modify network profile
Network interface profile
- /Under / etc / sysconfig / network scripts /
- ifcfg-ens33: configuration file of the first Ethernet card
[root@localhost ~]# ls /etc/sysconfig/network-scripts/ifcfg-* /etc/sysconfig/network-scripts/ifcfg-ens33 /etc/sysconfig/network-scripts/ifcfg-lo
Network interface profile
- /Under / etc / sysconfig / network scripts /
- ifcfg-ens33: configuration file of the first Ethernet card
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 TYPE=Ethernet BOOTPROTO=static DEVICE=ens33 ONBOOT=yes IPADDR=192.168.4.11 NETMASK=255.255.255.0 GATEWAY=192.168.4.100
Enable and disable network interface configuration
- Restart network service
[root@localhost ~]# systemctl restart network
- Disable and enable network interface
[root@localhost ~]# ifdown ens33 [root@localhost ~]# ifup ens33
Domain name resolution profile
- /etc/resolv.conf file
- Save the IP address of the DNS server that this machine needs to use
[root@localhost ~]# vi /etc/resolv.conf search localdomain nameserver 202.106.0.20 nameserver 202.106.148.1
Note: CentOS 7 needs to be installed in NetworkManager Set dns=none in the main section of the conf file and restart the NetworkManager service, or use the nmcti command newly added by CentOS7 to set it
Local host mapping file
- /etc/hosts file
- Save the mapping record of host name and IP address
[root@localhost ~]# cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4. 119.75.218.70 www.baidu.com
- Comparison between hosts file and DNS server
- By default, the system first looks for the parsing 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 access
summary
- View network configuration
- ifconfig,hostname,route,netstat,ss
- Test network connection
- ping,traceroute,nslookup,dig
- Set network address parameters
- Temporary configuration, permanent configuration