Solve the problem that the CentOS7 virtual machine cannot access the Internet and set up the CentOS7 virtual machine to use a static IP to access the Internet

Solve the problem that the CentOS7 virtual machine cannot access the Internet and set up the CentOS7 virtual machine to use a static IP to access the Internet

I was playing with CentOS in a VMware virtual machine recently, and after installing it I found that I couldn't access the Internet. After a lot of hard work, I finally found a solution to the problem. The final effect is that whether pinging the internal network IP or the external network IP, it can be pinged normally. Four-step method:

The first step is to go to the /etc/sysconfig/network-scripts directory and check if there is a file like ifcfg-XXX in the directory:

If you cannot see files starting with ifcfg- (except ifcfg-lo), it means that the network card device is not correctly identified. It may be that the CentOS image version you downloaded is inconsistent with the CentOS version you selected when installing CentOS. For example, the CentOS image is 64-bit, but it is installed as 32-bit. this. . Reinstall it, at least I didn't find a good way

Next, proceed to the second step:

In VMware, click "Edit" - "Virtual Network Editor" in sequence. As shown below, I chose NAT mode:

In order to use a static IP, do not check the option "Use local DHCP service to assign IP to virtual machine". Then configure the subnet IP. The subnet IP and the host IP must not be in the same address range. Otherwise, even if the virtual machine can access the Internet, the network will be slow and unstable. The IP segment of my host is 192.168.115.xxx, so I configured 192.168.10.xxx to avoid the IP segment of the host. Anyway, as long as the third digit of the IP is between 0 and 254 and not 115, it will be fine. Nat mode is equivalent to configuring a sub-router. Friends who have set up multiple levels of routing should have some experience with this. Please configure a subnet IP reasonably based on the IP of your own machine.

In this interface, click "NAT Settings" to check the gateway of the virtual machine. This gateway will be used in the third step. My gateway here is 192.168.10.2.

Step 3:

Edit the file /etc/sysconfig/network-scripts/ifcfg-eno16777736 with root privileges. The effect is as follows:

TYPE=Ethernet
BOOTPROTO=static #Set static IP
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
NAME=eno16777736
UUID=4f40dedc-031b-4b72-ad4d-ef4721947439
DEVICE=eno16777736
ONBOOT=yes #If it is no, change it to yes, which means the network card device will start automatically. PEERDNS=yes
PEERROUTES=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_PRIVACY=no

 
GATEWAY=192.168.10.2 #The gateway address here is the gateway address obtained in the second step IPADDR=192.168.10.150 #Configure IP. In the second step, the IP has been set in the range of 192.168.10.xxx. I just set it to 150, as long as it is not the same as the gateway NETMASK=255.255.255.0 #Subnet mask DNS1=202.96.128.86 #DNS server 1, fill in the DNS server address available on your network DNS2=223.5.5.5 #DNS server 2

I have marked the key parameters with colored shading, and keep the others as default. After confirming that everything is correct, save and exit.

Step 4: Restart the network card service, execute service network restart, and then you can finally access the Internet:

Ping Baidu's domain name

Open the browser and find that the webpage opens in seconds.

Finally, I won’t post the diagram of the communication effect between the virtual machine and the intranet IP, which goes without saying. My personal expression is not very good, please bear with me, I hope it can help you.

2019/09/17 Addendum: If the host cannot ping the virtual machine, you can set the IP of the network connection VMware Virtual Ethernet Adapter for VMnet8 in the host to the same network segment as the virtual machine IP, and leave the default gateway blank:

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

You may also be interested in:
  • CentOS7 network configuration under VMware virtual machine (host wireless Internet access)
  • Solution to the problem of not being able to access the Internet when installing centos7 with VmWare
  • CentOS 7 cannot access the Internet after modifying the network card

<<:  Detailed explanation of MySQL row locks when encountering composite primary keys and multi-column indexes

>>:  Element sample code to implement dynamic table

Recommend

How to manage multiple projects on CentOS SVN server

One demand Generally speaking, a company has mult...

Solve the problem of docker pull being reset

This article introduces how to solve the problem ...

Five practical tips for web form design

1. Mobile selection of form text input: In the te...

How to modify the group to which a user belongs in Linux

Modify the group to which a user belongs in Linux...

JavaScript Advanced Closures Explained

Table of contents 1. The concept of closure Addit...

Detailed steps for building Portainer visual interface with Docker

In order to solve the problem mentioned last time...

CSS code to distinguish ie8/ie9/ie10/ie11 chrome firefox

Website compatibility debugging is really annoyin...

Detailed explanation of the use of redux in native WeChat applet development

premise In complex scenarios, a lot of data needs...

Share 9 Linux Shell Scripting Tips for Practice and Interviews

Precautions 1) Add interpreter at the beginning: ...

MySql 5.7.21 free installation version configuration method under win10

1. Unzip to the location where you want to instal...

Detailed explanation of Vue component reuse and expansion

Table of contents Overview Is the extension neces...

Analysis of Linux Zabbix custom monitoring and alarm implementation process

Target Display one of the data in the iostat comm...

MySQL triggers: creating multiple triggers operation example analysis

This article uses an example to describe the crea...