Linux VMware uses DHCP to assign fixed IP to virtual machines and to enable NAT network Port forwarding

Source: Internet
Author: User
Tags mstsc

First introduce the environment:

1. The host computer's operating system is scientific Linux, kernel version 2.6.18, hostname spvm02,ip address 135.100.101.102, and VMware Workstation 8 deployed.

2. Guest (virtual machine) This side of the installed operating system is windows 7.

3. Guest uses the VMNET8 network card to achieve Internet access through the NAT protocol.


The feature that needs to be implemented is that other computers in the host network use Microsoft Remote Desktop to telnet to the guest desktop. So exploring how to implement NAT network port forwarding by configuring VMware Workstation is the core of this article.


The following two methods can achieve the functions we need, the second method is more direct, the need to solve the problem of friends can be directly down.


First of all, the ability of DHCP to assign a fixed IP to guest and allow an extranet computer to access the guest specified port by modifying the VMware network configuration.

This configuration can be done through the graphical interface in the Windows version of VMware Workstation, but in Linux we can only do this by modifying the configuration file at this time. The steps are as follows:


1. First use "PS-EF" to locate the DHCP and NAT service configuration file:


[Email protected] ~]# Ps-ef | grep dhcpd

Root 11080 1 0 09:58? 00:00:00/usr/bin/vmnet-dhcpd-s 6-cf /etc/vmware/vmnet8/dhcpd/dhcpd.conf -lf/etc/vmware/vmnet8/dhcpd/ Dhcpd.leases-pf/var/run/vmnet-dhcpd-vmnet8.pid Vmnet8

[Email protected] ~]# Ps-ef | grep natd

Root 11054 1 0 09:58? 00:00:00/usr/bin/vmnet-natd-s 6-m/etc/vmware/vmnet8/nat.mac-c/etc/vmware/vmnet8/nat/nat.conf


We can also find it by means of "cat/proc/11080/cmdline", not much to say here.

In short, we found the configuration files for both services: "/etc/vmware/vmnet8/dhcpd/dhcpd.conf" and "/etc/vmware/vmnet8/nat/nat.conf".


2. Modify the DHCP configuration file to implement VMware's ability to assign fixed IP to virtual machines:


[Email protected] ~]# vi/etc/vmware/vmnet8/dhcpd/dhcpd.conf
......
####### VMNET DHCP Configuration. End of "Do not MODIFY section" #######

Host SPVMWIN7A {
Hardware Ethernet 00:0c:29:f1:5d:46;
Fixed-address 192.168.187.200;
}

We add the above text at the end of the configuration file.

where "spvmwin7a" is a hostname, in fact, just fill it out, as long as the other host in the configuration file name is the same;

The MAC Address "00:0c:29:f1:5d:46" of the guest Nic can be obtained by using the Windows command "Ipconfig/all" on the guest command line;

The fixed IP address "192.168.187.200" is the IP address that you want to assign to this guest NIC.


3. Modify the NAT configuration file to enable port forwarding from host to guest:


[Email protected] ~]# vi/etc/vmware/vmnet8/nat/nat.conf
......
[INCOMINGTCP]

# Use these with Care-anyone can enter into your VM through these ...
# The format and example are as follows:
#<external Port number> = <vm ' s IP address>:<vm ' s port number>
#8080 = 172.16.3.128:80

9000 = 192.168.187.200:3389

We add this line of text in the [incomingtcp] section of the configuration file.

It represents a TCP request destined for the host 9000 port, forwarded to port 3389 of 192.168.187.200 (Guest).


Note: 3389 is the default listening port for Microsoft Remote Desktop Services.



4. Restart VMware's DHCP and NAT service:


We need to restart VMware's dhcpd and NATD processes before the changes take effect.

I've been through the Internet and official documents, and I haven't found a way to restart these two processes.

There are articles online saying "/usr/lib/vmware/net-services.sh Restart" to restart the network-related process, but probably because the VMware version is not the same, I have not found a similar script for half a day.

After consulting with your friends, you still use the KILL command and then manually run the two processes, the effect is no problem.
It was not until later that I tried out the corresponding command:

[Email protected] ~]#/usr/bin/vmware-networks--stop
Stopped bridged networking on vmnet0
Stopped DHCP Service on Vmnet8
Stopped NAT Service on Vmnet8
Disabled hostonly Virtual adapter on Vmnet8
Stopped all configured services on all networks

[Email protected] ~]#/usr/bin/vmware-networks--start
Started Bridge Networking on Vmnet0
Started NAT Service on Vmnet8
Enabled hostonly Virtual adapter on Vmnet8
Started DHCP Service on Vmnet8
Started Network Detection Service
Started all configured services on all networks

[Email protected] ~]#/usr/bin/vmware-networks--status
Bridge networking on Vmnet0 is running
DHCP Service on Vmnet8 is running
NAT Service on Vmnet8 is running
Hostonly virtual adapter on VMNET8 is enabled
Network Detection service is not running
All the services configured the networks is running


5. Verify the configuration:

First we come to Guest's command line, using "ipconfig/renew" to refresh the network connection, the IP address from "192.168.187.128" to "192.168.187.200", indicating that our changes to DHCP take effect.

Then we open the Windows "Remote Access" feature, repeat the method: Right-click on the "Computer" select "Properties", click on the left "remote settings", in the popup dialog box "Remote Desktop" to select Allow remote computer connection.

Then in the host network, find a Windows host, Start > Run Enter "mstsc" to try to connect "135.100.101.102:9000", if prompted to enter the credentials to log on to Windows, the port forwarding settings take effect.


The second method, in fact, in Linux port forwarding is a very easy thing.

We can simply set up a port mapping relationship to solve this problem, when used only need to execute a command in the host can be done:

Ssh-nf-l 135.100.101.102:3390:192.168.187.200:3389 localhost


As for the meaning of the order, here will not repeat, interested friends please refer to "Man ssh".



Here are some tips that you might use during the debugging process:


If you are not connected to the remote desktop of guest, first ping the host in the external network, ping guest in host, and then check Windows Firewall.

In the guest check whether the service is working properly, start > Run Enter "mstsc" to try to connect your own "192.168.187.200:3389", if "running a session" then the service is normal, A change of the end of the oral examination will know how the clue is not connected.



Reference documents:

1. "Port mapping for VMware under Linux" http://blog.chinaunix.net/uid-12290680-id-26867.html

2. <using VMware workstation-vmware Workstation 8> http://www.vmware.com/pdf/ws80-using.pdf

3. <bsd General Commands Manual-ssh (1) >


Linux VMware uses DHCP to assign fixed IP to virtual machines and to enable NAT network Port forwarding

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.