1. Check the network card settings
vim /etc/sysconfig/network-scripts/ifcfg-eth0
The ip address must be on the same network segment as the gateway.
If it is a virtual machine, make sure that the virtual machine ip address, gateway, and host ip are in the same network segment
2. Check the routing settings
If there is no problem in the first step, the virtual machine can ping the host, and the ping gateway can also be pinged. At this point, you can use the route -n command to view the routing settings of the system.
For example: the IP address of my eth0 is 192.168.85.10, and the gateway is 192.168.0.2. If I want to connect to any address on the external network, there should be a route set to:
Destination represents the destination address, 0.0.0.0 represents any address, Gateway represents the gateway, and Iface represents the network card used to reach the destination address.
3. Check if the firewall is turned off
Permanently turn off the firewall: service iptables off
Check status: service iptables status
4. Set up DNS server
vim /etc/resolv.conf
Add the following
nameserver8.8.8.8