1. Set the network to bridge mode
2. View the required information on the host machine
We need three data here: IPv4 address, subnet mask, and default gateway.
(Recommended tutorial: centos usage tutorial)
3. Edit the configuration file
The final name may be different. If it is different, change it yourself.
vi /etc/sysconfig/network-scripts/ifcfg-ens33
Modify your own configuration file according to the following reference configuration file
TYPE="Ethernet" PROXY_METHOD="none" BROWSER_ONLY="no" #设置静态ip BOOTPROTO="static" DEFROUTE="yes" IPV4_FAILURE_FATAL="no" IPV6INIT="yes" IPV6_AUTOCONF="yes" IPV6_DEFROUTE="yes" IPV6_FAILURE_FATAL="no" IPV6_ADDR_GEN_MODE="stable-privacy" NAME="ens33" UUID="1f3f4a9a-858d-47f6-b1f5-287ac6457216" DEVICE="ens33" ONBOOT="yes" #输入你想设置的ip地址 IPADDR="192.168.0.202" PREFIX="24" #设置网关 GATEWAY="192.168.0.1" #子网掩码 NETMASK=255.255.255.0 DNS1="8.8.8.8" IPV6_PRIVACY="no"
Note:
The IPADDR value must be in the same network segment as the IPv4 address in step 2;
GATEWAY is the default gateway in step 2;
NETMASK is the subnet mask in step 2
4. Restart the network
systemctl restart network.service
Related video tutorials Recommended: linux video tutorial
The above is the detailed content of Centos system cannot ping Baidu. For more information, please follow other related articles on the PHP Chinese website!