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

mysql5.7.20 installation and configuration method graphic tutorial (mac)

MySQL 5.7.20 installation and configuration metho...

Detailed explanation of the difference between Vue life cycle

Life cycle classification Each component of vue i...

How to get the size of a Linux system directory using the du command

Anyone who has used the Linux system should know ...

Prometheus monitors MySQL using grafana display

Table of contents Prometheus monitors MySQL throu...

Analysis and solutions to problems encountered in the use of label tags

I used the label tag when I was doing something re...

Provides helpful suggestions for improving website design

<br />Scientifically Design Your Website: 23...

How to use docker to deploy spring boot and connect to skywalking

Table of contents 1. Overview 1. Introduction to ...

HTML form application includes the use of check boxes and radio buttons

Including the use of check boxes and radio buttons...

Nginx prohibits direct access via IP and redirects to a custom 500 page

Directly to the configuration file server { liste...

Web page creation for beginners: Learn to use HTML's hyperlink A tag

The hyperlink a tag represents a link point and i...

Detailed tutorial on installing PHP and Nginx on Centos7

As the application of centos on the server side b...

Zookeeper stand-alone environment and cluster environment construction

1. Single machine environment construction# 1.1 D...