Liuux network settings and basic services

View network interface information ifconfig

ifconfig   #View all active network interface information

ifconfig -a   #View all active network interface information

ifconfig ens33   #View the specified network interface information

Disable or reactivate the network card

[root@localhost ~]# ifconfig ens33:1down     #Disable network card
[root@localhost ~]# ifdown ens33 (same effect)

[root@localhost ~]# ifconfig ens33 up     #Enable network card
[root@localhost ~]# ifup ens33 (same effect)

Temporary configuration routing

Temporarily add the routing record of the specified network segment
route add -net Network segment/Short format subnet mask gw default gateway 

Temporarily delete the routing record of the specified network segment
route del -net Network segment/Short format subnet mask

Reload network profile

Restart the network service to re read the configuration file
[root@localhost ~]# systemctl restart network

Three network connection modes of virtual machine

  • Bridging: it is equivalent to a virtual host in the network, sharing a network with my host. Machines in the same network can ping virtual machines to each other
  • Host only: only real machines and virtual machines can communicate with each other, or virtual machines can communicate with each other. Internet access is not allowed
  • NAT: it can access the Internet. Virtual machines can communicate with each other. Real machines and virtual machines can communicate with each other. Machines on the network cannot ping virtual machines

Set network interface parameters 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

Hostname hostname

◾ View or set the current hostname

hostname[host name]

◾ Examples

[root@localhost~]#hostname
 localhost.localdomain

◾ Modify hostname hostname

Set host name

hostname Host name

◾ Examples

[root@localhost ~]# hostname
 localhost.localdomain
[root@localhost~]# hostname www.bdqncom
[root@localhost~]# hostname
 www.bdqn.com
[root@localhost ~]# bash   #Enable a new Shell session
[root@www~]#

◾ Permanently modify the host name

  • Method 1
    vim /etc/hostname # enter

    Reboot or init6 reboot

  • Method 2:
    hostnamectl set-hostname xxx
    The text is automatically changed to xxx

View the route table entry route

First line:
Destination : target
Gateway : Display gateway
Genmask : Subnet mask
Flags : Flag bit (what kind of route is the flag)
Metric : Number of hops
Iface : Interface
 Second line:
default Represents the default route
U: Representative activity G: Default route
ens37: 37 mouth
 Third line:
link-local Virtual network card
  • route -n: view the route table numerically

  • ip route or ip route show: view the route table

  • Add route

 - route add : Add route
 - net  : Set a target network segment 192.168.2.0
 - netmask  : Subnet mask 255.255.255.0 
 - gw  : Next hop gateway 192.168.1.1

  • Delete route
 - route del -net ip Segment subnet mask

  • Add routes connected to hosts add routes connected to hosts
route add -host IP address gw next hop gateway  

Ugh stands for host routing

  • Add default route
route add default gw  ip address

  • Delete default route
route del default gw ipdiz 

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 Look at all the States
-l  see listen Listening 
-n Display in numbers (parse services into numbers)
-p Process PID  
-u see udp Link port
-t see tcp Link port

Examples

[root@localhost~]# netstat -anpt |grep ": 80"
 tcp60 0::80*LISTEN 20563/httpd

Get socket statistics ss

  • It can display something similar to netstat.
    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.

Test network connection ping

  • ping IP address: detect network communication. By default, it is always ping and ctrl+c exits
  • ping -c 2 ip or domain name: specify the number of pings. 2 you can modify the value here
  • Time of ping ing specified IP address: 2

    ping -i 0.5 IP address: specify the time interval of each ping as 0.5s
64 bytes byte 
ttl=0 Discard this bag when you need it  
The packet will be discarded when it is reduced to 0
 Prevent data packets from being forwarded in a wireless loop in the network, so as to save network resources
time=0.303ms   Generally, it is at the millisecond level. If it is in tens or hundreds of milliseconds, it is necessary to consider whether there is blocking in the network

Use the traceroute command to track the routing path of packets

Use the traceroute command to test which network nodes have passed from the current host to the destination host, and display the connection status (response time) of each intermediate node. For unresponsive nodes, the connection status will be displayed as "*".
For example, it can be seen from the following operation results that a router 192.168.4.1 needs to be crossed between the local machine and the target host 192.168.7.7.

[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.740ms 15.581 ms 15.881 ms
 2 (192.168.7.7) 19.652 ms 19.995 ms 19.942 ms

traceroute command can more accurately locate the fault point (break point) of network connection than ping command
Therefore, the line speed will be slightly slower than the ping command. In the process of network testing and troubleshooting, the ping command is usually used first
Test the network connection with the destination host. If the network connection is found to be faulty, use the traceroute command to track and check
See which intermediate node is faulty.

Use the nslookup command to test DNS domain name resolution

When the domain name resolution is abnormal, you will not be able to use the form of domain name to access Web sites and e-commerce in the network
Mail system and other services. The nslookup command is a special tool for testing domain name resolution. When using it, you only need to specify
The resolved target domain name can be used as a parameter. For example, after executing the "nslookup www.google.com" command,
The nslookup program will submit a query request to the website www.google.com What is the corresponding IP address of COM.

[root@localhost~]# nslookup www.google.com
 Server:202.106.0.20         // DNS server used
 Address:202.106.0.20#53

 Non-authoritative answer:   //The following is the feedback result of DNS resolution
 Name:www.google.com
 Address:173.194.127.51    
 ......                      //Omit some contents

If you can successfully feed back the IP address of the domain name to be queried, it means that there is no problem with domain name resolution. Otherwise, you need to judge the cause of the fault according to the actual feedback. For example, if the message "no servers could be reached" appears, it indicates that you cannot connect to the specified DNS server; If the message "can't find xxx.yyy.zzz:NXDOMAIN" appears, it indicates that the domain name to be queried does not exist.

[root@localhost~]# nslookup www.google.com
;; connection timed out; trying next origin
;; connection timed out; no servers could be reached

Three methods of setting network card

Method 1:

  • Manual increase

Method 2

  • ifconfig ens33 IP address subnet mask: temporarily change the IP address

Method 3

  • VIM / etc / sysconfig / network scripts / ifcfg-ens33: set the network card configuration file and permanently change the ip address
    Effective after restart (no error means success)

Experimental steps

Add network VMnet2


Add a network card

restart
systemctl restart network
Enter network card configuration file



Restart without error is successful


Go to the real machine to see if the ip address of vm2 is correct
Open the command prompt and view it with ipconfig

ping pass, the experiment is successful

Added by Arkane on Wed, 09 Feb 2022 03:11:14 +0200