1. If the gateway does not have an ip address, you can perform the following operations
Below is the gateway without ip address
Do the following
# 注意ens33是网关名称,看自己网关名称
sudo vi /etc/sysconfig/network-scripts/ifcfg-ens33
Modify or add the value inside, and set the ip to a fixed IP (the network segment with the same address as the host)
BOOTPROTO=static # 原来是 dhcp 修改成 static
IPADDR=202.141.191.22 # 静态IP
GATEWAY=202.141.191.1 # 默认网关
NETMASK=255.255.255.0 # 子网掩码
DNS1=114.114.114.114 # DNS 配置
DNS2=8.8.8.8 #DNS 配置
ONBOOT=yes # 原来是 no 修改成 yes
Restart the network
systemctl restart network
View the contents of the sudo vi /etc/resolv.conf file
2. Mutual ping (host ping through centos, centosping through host), but cannot connect to the external network
Check the DNS of the corresponding network segment of the host
Add this DNS address to the ifcfg-ens file
sudo vi /etc/sysconfig/network-scripts/ifcfg-ens33
DNS3=202.141.180.1
restart service
systemctl restart network
View the contents of the sudo vi /etc/resolv.conf file, and you will find an additional address
If it still doesn't work, ua, you can try
Add the route-ens33 file in the /etc/sysconfig/network-scripts/ directory (ens33 is the name of the gateway)
The content inside is 202.141.191.22/24 via 202.141.191.1 dev ens33
The format is: (ip address via gateway (gateway) dev gateway)