Home >Operation and Maintenance >CentOS >What to do if the virtual machine centos cannot ping?

What to do if the virtual machine centos cannot ping?

藏色散人
藏色散人Original
2020-03-13 11:10:484893browse

What to do if the virtual machine centos cannot ping?

What should I do if the virtual machine centos cannot ping?

For friends who use the Windows operating system (ignored by Mac users), you may need to use a Linux system to learn some technologies. Naturally, you need to use a virtual machine to install Linux. Of course, many mainstream The tutorials on the learning website will provide virtual machine environment images configured by the teacher.

Recommended: "centos usage tutorial"

However, many students still have network problems with the virtual machine when using it according to the configuration of the tutorial.

Solve the problems related to virtual machine CentOS7 network ping failure (easy to understand)

Step 1: Change the network environment in the virtual machine to NAT mode (Modification method: Click on the two small computers in the lower right corner of the virtual machine--> Settings)

Step 2: Use root permissions, enter vi /etc/hosts and change the contents inside Change the address to your own defined address;

The address you defined admin (Explanation: The first three digits of your custom address must be consistent with the gateway, and the last digit cannot be 1,2,255)

127.0.0.1    localhost

ps. Gateway query method:

①Windows, VMNET8 in the ipconfig under cmd has an ipv4 address, the gateway is the last digit of this address and changed to 2

②Edit in the virtual machine ( In the virtual machine network editor (upper left corner), click VMNET8, and then click NAT settings. You can see your gateway and subnet mask

Step 3:

vi /etc/sysconfig /network Change the HOSTNAME inside to admin or other names

(The admin changed here needs to be consistent with the name you defined in the second step)

Step 4:

cd /etc/sysconfig/network-scripts
vi ifcfg-eth0

Modify several parameters:

①HWADDR

Enter ip addr in the terminal and press Enter. We can see that there is ens33. The address after link/ether below is the MAC address. Copy it and paste it into HWADDR.

       ②ONBOOT=yes(若没有请自己添加)
       ③IPADDR(改为你自定义的地址)就是第二步中的地址
       ④NETMASK(改为你虚拟机的子网掩码)第二步中介绍了 
       ⑤GATEWAY(改为你虚拟机的网关)第二步中介绍了
       ⑥DNS1=8.8.8.8  DNS2=114.114.114.114

The fifth step: cat /etc/resolv.conf

nameserver 8.8.8.8
nameserver 114.114.114.114

under root, don’t modify it, otherwise just modify it with vi.

Step 6: Turn off the firewall (only applicable to CentOS 7)

    systemctl stop firewalld
    systemctl disable firewalld

Step 7: Reboot or init 6 to restart

Step 8: Test after restarting, Open the terminal, ifconfig can see that the IP address has been modified successfully, and then ping www.baidu.com can ping successfully.

solve.

Recommended video tutorial for learning Linux: //m.sbmmt.com/course/list/33.html

The above is the detailed content of What to do if the virtual machine centos cannot ping?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn