Configure NAT mode network in VMWare


Why use NAT mode

I wrote this article because a friend has encountered some problems with the NAT network configuration in the virtual machine. My own working environment has also benefited from this optimization. Therefore, I would like to make a record here;

Problems encountered by friends: Nat mode is configured in the virtual machine, and the system in the virtual machine can ping with the host, but can’t Ping the Internet; the final discovery is that IPv6 is turned on;

My own problem: the company’s own working environment is placed in the virtual machine, and I use my own book. When I get home, I have to change the IP every time because of the problem of IP settings. After I go to the company, I have to change it again, which is more troublesome. Now after using the NAT mode configuration, this problem is solved;

Test environment:

  • VMware15
  • CentOS 6.8 64 bit
  • The image is centos-6.10-x86_ 64- minimal.iso

Let’s briefly talk about NAT mode. NAT mode enables virtual machines to share the host’s IP. Let me understand it colloquially. This way is to establish an intranet environment ( under the local intranet IP network (such as At this time, the local and local intranet communication uses, the gateway, intranet and extranet Network communication uses the IP of local host;

The advantage of this mode is to avoid the problem of IP address occupation when using bridge mode. For example, the company allocates a fixed IP to each person, and when they want to establish multiple virtual machines for testing, there will be no IP available;

It can also solve the problem of frequent IP changes because of the location of work is not fixed. At this time, although the IP of the local host will change, the Intranet environment under NAT mode of the local host is unchanged and can still communicate with the host. If the IP of the host computer is used in the external network, there is no problem;


Use DHCP mode

The steps to install CentOS are omitted here. I’ll write an article about installation later

Note: my test environment is a newly installed CentOS 6.8, and there are no other applications installed;

After installation, it is configured to use NAT mode (it can also be set during installation)

Configure NAT mode network in VMWare

Note: the default NAT mode of VMware is VMnet8 virtual network card

At this time, if the network of centos6 system in the virtual machine is directly set to DHCP to obtain IP, i.eBOOTPROTO=staticThen, it should be configured directly. You can ping the network of the local host and the virtual machine system, and then Ping the external network. Basically, there is no problem;

Use static mode

The following instructions are for configuring static IP. After all, dynamic access will lead to frequent changes in the environment configuration, and the experience is not good

Let me first talk about my local host network:

  • ip:
  • gateway:

We click on theedit-> Virtual Network Editor

As you can see, in NAT mode, the virtual network card is VMnet8. Click it to view NAT settings and DHCP settings, and record several key configuration parameters;

Configure NAT mode network in VMWare

Note: please do not change the above two configurations unless you know what you are doing

The first thing to note is the gateway in NAT settings. Here is:, please do not change it;

The second thing to note is in the DHCP settingsStarting IP addressandEnd IP addressPlease do not change the scope, and the following virtual machine system IP needs to be set in this range, mine is192.168.204.128~

Now, let’s start to configure the network of centos6 server in the virtual machine:

#I'll just list the key configurations here/etc/sysconfig/network-scripts/ifcfg-eth0
IPADDR= the topDHCPSetIPWithin the scopeGATEWAY= the gateway in, do not write wrongPREFIX=24
...#Restart the network10.0.0.1        //Test whether the network is connected with
ping        //Test connectivity with local host
ping    //Test Internet#Also, the local host can be testedNATIntranet192.168.204.2  //Test whether the two networks are connected
ping  //Test whether the two hosts are connected

It’s no accident. Everything is OK. If the Ping of the Intranet in the virtual machine is blocked from the external network, check whether the IPv6 is turned on. If the Ping fails to work on the host, check the NAT gateway settings;

If you have any questions, please comment;

This work adoptsCC agreementThe author and the link to this article must be indicated in the reprint

June wind

Recommended Today

Comparison and analysis of Py = > redis and python operation redis syntax

preface R: For redis cli P: Redis for Python get ready pip install redis pool = redis.ConnectionPool(host=’′, port=6379, db=1) redis = redis.Redis(connection_pool=pool) Redis. All commands I have omitted all the following commands. If there are conflicts with Python built-in functions, I will add redis Global command Dbsize (number of returned keys) R: dbsize P: print(redis.dbsize()) […]