Solve the problem that the centos virtual machine cannot connect to the network in the mac m1 environment

question

Unable to connect to the network after installing the virtual machine on the mac. Can't download software and can't pingwww.baidu.com

ideas and solutions

First, I installed a centos7 virtual machine with VMware. The host environment is mac m1. The virtual machine is in NAT mode and a static IP has been set. Can ping the host

1. DNS is not enabled

Because I ping different baidu, I first wondered if it was because I turned off DNS, so I tried to ping ip directly

ping 114.114.114.114

It is found that the ping still fails, so it is not a DNS problem.

2. The network card is not turned on

The ens160 here is the name of your network card. The name of the network card may be different in different environments. You need to modify it according to your own network card name.

You can know by looking /etc/sysconfig/network-scriptsunder the pathifcfg-ensxxx

vim /etc/sysconfig/network-scripts/ifcfg-ens160

Turn on network card options

ONBOOT=yes

restart the network card

service network restart

But I found here that my network card is turned on, so this is not the problem

3. Check the gateway configuration

Another possible reason is that the network cannot be connected due to the incorrect gateway settings in the virtual machine.

1. Then check the gateway address and execute the following command on the machine

cat /Library/Preferences/VMware Fusion/vmnet8/nat.conf

The ip here is the gateway, you can see that I am here 192.168.244.2
insert image description here
2. Check the gateway settings in the virtual machine

 vim /etc/sysconfig/network-scripts/ifcfg-ens160

Check and find that the ip set by the gateway is 192.168.244.1, which is obviously wrong, so it is adjusted to the ip queried above

GATEWAY=192.168.244.1
DNS1=192.168.244.1

The complete modified network card configuration file is attached for your reference

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static #dhcp
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes # no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
IPV6_PRIVACY=no
NAME=ens160
UUID=c5581a60-f0fa-47a7-be3f-8c48592bec15
DEVICE=ens160
ONBOOT=yes
IPADDR=192.168.244.15
GATEWAY=192.168.244.2
NETMASK=255.255.255.0
DNS1=192.168.244.2
DNS2=114.114.114.114

3. Restart the network card service

service network restart

4. Execute the ping command again to test the network connection

ping www.baidu.com

success! problem solved
insert image description here

Guess you like

Origin blog.csdn.net/qq_24950043/article/details/124413491