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

Detailed tutorial on compiling and installing MySQL 5.7.24 on CentOS7

Table of contents Install Dependencies Install bo...

Management of xinetd-based services installed with RPM packages in Linux

Table of contents Preface 1. Startup management b...

Linux remote login implementation tutorial analysis

Linux is generally used as a server, and the serv...

Docker learning: the specific use of Container containers

Container is another core concept of Docker. Simp...

Thinking about grid design of web pages

<br />Original address: http://andymao.com/a...

MySQL can actually implement distributed locks

Preface In the previous article, I shared with yo...

Detailed explanation of Docker Swarm service orchestration commands

1. Introduction Docker has an orchestration tool ...

Take you to understand the event scheduler EVENT in MySQL

The event scheduler in MySQL, EVENT, is also call...

How to change the system language of centos7 to simplified Chinese

illustrate When you install the system yourself, ...

How to implement call, apply and bind in native js

1. Implement call step: Set the function as a pro...

Vue implements weather forecast function

This article shares the specific code of Vue to r...

Commonly used English fonts for web page creation

Arial Arial is a sans-serif TrueType font distribu...

How to use VirtualBox to build a local virtual machine environment on Mac

1. Big Data and Hadoop To study and learn about b...