VMware + CentOS cannot ping the external network modification tutorial (including the experience of stepping on the pit)

environment

VMware + CentOS7 + Windows10

reason

Because I want to do big data experiments, I plan to use the traditional secret recipe "QQ mailbox" to realize the function of uploading files from Win system to Linux system (VMTool is a bit difficult to use), but when I open Firefox on the virtual machine, I find that the network is broken. Modify After a long time of network configuration, I finally figured out where the problem lies, and decided to write a post to record it. It really took a lot of time.

process

(Since I don't really remember what steps I have done, I try to reproduce all my settings as much as possible, hoping to help you. You can also follow me to reconfigure!)

1. Check the host IP

  • Use Win + R to open the "Run" window, and enter "cmd" to enter the command line.

  •  Enter ipconfig to view the host IP.

 [Note] Find "Wireless Local Area Network Adapter WLAN", not "Ethernet Adapter"!

The "IPv4 address", "subnet mask", and "default gateway" in it are very important information, which will be used later.

2. Modify the virtual machine settings

  • Enter the virtual machine, click the right mouse button to open the terminal, and use the following command to enter the root mode (convenient for subsequent operations).
su root

3. Modify firewall related settings

  • Turn off the firewall on the virtual machine side and disable booting.
systemctl stop firewalld.service
systemctl disable firewalld.service
  • Modify the firewall settings on the host side, use Win + R to open the "Run" window, enter "control" to enter the control panel, and select the "Firewall" option.

  •  Close the associated network. (I don't know which one will block the connection, so they are all closed...)

  •  Click "Advanced Settings", enter "Inbound Rules", and enable the three selected rules (domain, public, private).

 4. Modify the virtual machine network settings

  • Enter the virtual machine, click the "Virtual Machine" option, set the "Network Connection" in the "Network Adapter" to "NAT Mode", and confirm.

 [Knowledge Supplement] Here is a schematic diagram of the NAT connection made by other friends (see the link for the original text, and the infringement will be deleted). We do not choose bridging to avoid IP conflicts~

  • To modify the virtual machine network settings, click "Edit", select "Virtual Network Editor", and enter "Change Settings Options".

  • Give the administrator permission, select the NAT mode, and check the corresponding two items. Configure the subnet IP and subnet mask of the virtual machine according to the IP and subnet mask information of our host.

  •  Filling in the subnet IP number and subnet mask here will involve certain computer network knowledge.

First of all, the subnet mask is copied unchanged, so the subnet mask in the above box ② is also the same as the subnet mask of the host, here is "255.255.224.0".

Secondly, according to the subnet mask, we can know that the network number plus the subnet number are 19 digits in total, and the host number is 13 digits (because the IPv4 dotted decimal "255.255. The first two digits of the network number (the first 16 digits in binary) must be the same as those of the host, and the host number must be all 0 (the last 13 digits of the host number in binary are all 0, indicating that the network is not a host), but the overall network number must be It is different from the network where the host is located, and therefore there is only 3 digits (10.194. [000/001/010/011/100/101/110/111 + 00000].0), I chose 10.194.64.0, otherwise it will "Subnet mask does not match IP address" error occurs.

If your subnet mask is 255.255.255.0 then this is much easier! Copy the first two digits of the subnet IP directly, choose a value different from the host IPv4 value for the third digit, and keep the fourth digit as 0.

  • Modify NAT settings.

Enter the NAT settings and modify the gateway IP. The first three digits are the same as the subnet IP, and the fourth digit can be filled in freely. Here, select "2", and click "OK" after the modification is completed.

  • Click DNS settings, modify to the following servers (Telecom and Google).

  • Click DHCP Settings to modify the start and end IP addresses. In most cases, the first three digits are the same as the IP address, and the fourth digit can be 128 and 254. Click "OK" after the modification is completed. (The value selection here is for the simplicity of the tutorial. How to fill in the specific value requires some computer network knowledge. It can be seen that the third digit of my ending IP is different, so don’t think too much~)

  • After all modifications are completed, click "Apply" and "OK" on the bottom bar of "Virtual Network Editor" to save the modification. ("Apply" first, then "Modify", I blacked out "Apply" here because I didn't modify it when I wrote the tutorial, everyone should be clickable)

 5. Modify the virtual machine file configuration

  • Enter to view the content of the file (some friends may be scripts, which may vary depending on the version).
ls /etc/sysconfig/network-scripts/

It can be seen that there is a file named "ifcfg-eth0". Maybe some friends have a file suffix called ens33 or ens32. Ignore the difference and just remember this suffix. (If there are multiple ifcfg-xxx files, an error will be reported, check experience and use the "rm file name" command to delete redundant network card files)

Link: Centos7.x network card startup error (Failed to start LSB: Bring up/down networking)_centos7 failed to start lsb_publicstaticfinal's blog-CSDN blog asdsa asd asd asd asdasaasd sda https://blog.csdn.net/publicstaticfinal/article/ details/119762458

  • To view IP information, enter the command ip addr.
ip addr

 When you see the hardware address corresponding to eth0, remember this address (it is recommended to save it in the file transfer assistant, which will be used later)

If you have information such as virbr0 in your information, you can turn it off according to the following tutorial.

Link: linux closes the virbr0 network card_how to close virbr0_q735496541's blog-CSDN blog preface Recently, when using linux, it is required to close the virbr0 network card. I checked online that virbr0 is the network card used by the kvm virtual machine, after the libvirtd service is installed , automatically generated, the configuration file location of virbr0 /etc/libvirt/qemu/networks/default.xml, the configuration file location of libvirtd service /etc/libvirt/libvirtd.conf Introduction After searching for information on the Internet and experimenting by yourself, there are two methods It can solve the problem of virbr0 network card. After manually shutting down the virbr0 network card, turn the libvirtd service on and off automatically, and restart it. https://blog.csdn.net/q735496541/article/details/123051125?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-123051125-blog-109443460.235% 5Ev35%5Epc_relevant_increate_t0_download_v2_base&spm= 1001.2101.3001.4242.1&utm_relevant_index=3

  • Enter vim /etc/sysconfig/network-scripts/ifcfg-xxx to modify the file (xxx represents your suffix, here is eth0).
vim /etc/sysconfig/network-scripts/ifcfg-eth0

Make sure the mouse is in the virtual machine, click the "i" key on the keyboard to enter the insert mode and modify the content. 

Follow the above format, make sure BOOTPROTO is (dhcp or) static, IPv4_FAILURE_FATAL is no, ONBOOT is yes, NAME and DEVICE are both file extensions.

Add or modify NETMASK as the subnet mask of the subnet, HWADDR as the hardware address you just saved, IPADDR as the host IP in the subnet , you can also add the gateway information as the gateway address during configuration, that is, GATEWAY="10.194. 96.2".

How to determine the host IP?

It is an address in the range, otherwise an error will be reported. I chose 10.194.96.140 here.

After the modification, click the "Esc" key and enter ":wq" to save and exit.

  • Modify the DNS settings in the same way, enter vi /etc/resolv.conf to modify the DNS to the following servers, then save and exit.

  • Open the Control Panel again (Win + R, enter control), select "Change Adapter Settings" in "Network and Sharing Center".

  •  Select VMware Network Adapter VMnet8, right-click to enter the "Properties" panel.

  •  Double-click to select Internet Protocol Version 4.

  •  Select "Use the following IP address", the subnet mask and default gateway are the same as the original modified content, but the IP address here needs to ensure that the first three digits are the same, and the last digit is different from the virtual machine's IP and gateway and is not set in DHCP In the IP range, select 10.194.96.1 here.
  • Select "Use the following DNS" and still change to those two DNS servers.

Click "OK" to save and exit.

  • To be on the safe side, disable and then enable VMnet8. (some weird ways)

(enabled)

  • Enter the command ifconfig (ifconfig is not ipconfig, to be distinguished).

  • Enter ping www.baidu.com to check the situation.
ping www.baidu.com

 At this point, this tutorial is complete.

Solutions to some possible problems

  • 提示Error, some other host already uses address:

Links: https://www.cnblogs.com/staryea/p/8520468.html https://www.cnblogs.com/staryea/p/8520468.html

  •  Ifcfg-xxx file parameter description and settings:

Link: ping: www.baidu.com: Unknown name or service - short book 1. First determine whether the login identity is the root user, if not, it is best to switch to the root identity 2. Enter vi /etc/sysconfig/network- scripts/ifcfg-ens33,… https://www.jianshu.com/p/181794ea28ba

  • Linux closes the virbr0 network card:

Link: linux closes the virbr0 network card_how to close virbr0_q735496541's blog-CSDN blog preface Recently, when using linux, it is required to close the virbr0 network card. I checked online that virbr0 is the network card used by the kvm virtual machine. It is after the libvirtd service is installed. , automatically generated, the configuration file location of virbr0 /etc/libvirt/qemu/networks/default.xml, the configuration file location of libvirtd service /etc/libvirt/libvirtd.conf Introduction After searching for information on the Internet and experimenting by yourself, there are two methods It can solve the problem of virbr0 network card. After manually shutting down the virbr0 network card, turn the libvirtd service on and off automatically, and restart it. https://blog.csdn.net/q735496541/article/details/123051125?utm_medium=distribute.pc_relevant.none-task-blog-2~default~baidujs_baidulandingword~default-0-123051125-blog-109443460.235% 5Ev35%5Epc_relevant_increate_t0_download_v2_base&spm= 1001.2101.3001.4242.1&utm_relevant_index=3

  • Strange problem occurs:

        To reboot, use the reboot command.

  • Error, some other host[00:0C:29:...] already uses address:

        Check for IP conflicts.

Link: Linux configures a fixed IP address ifup-eth[4919]: Error, some other host[00:0C:29:...] already uses address_Yazhiye's Blog-CSDN Blog 1. Service network restart prompts that the IP address has already been used Occupied by another mac address 2. It is obviously caused by IP address conflict, so don’t change it randomly (I found many ifup-eth modifications on the Internet) 3. Change the IP address, or modify the same IP address 4. Service network restart succeeded... https://blog.csdn.net/yazhiye/article/details/105226974

  • Too many NICs:

Link: Centos7.x network card startup error (Failed to start LSB: Bring up/down networking)_centos7 failed to start lsb_publicstaticfinal's blog-CSDN blog asdsa asd asd asd asdasaasd sda https://blog.csdn.net/publicstaticfinal/article/ details/119762458

  •  Network restart error:

Links: https://www.cnblogs.com/zhizhao/p/9442487.html https://www.cnblogs.com/zhizhao/p/9442487.html

Finally, if this tutorial is helpful to you, please like and comment!

Guess you like

Origin blog.csdn.net/ayaishere_/article/details/130637302