Configuring Ubuntu vmware guest NAT

97,425

Solution 1

First of all, yes, you won't be able to use a bridged network connection because all of the guests will have the same hostname, so you'll have to go with NAT.

You got part of the configuration right, however, your problem should be in the default gateway that you assigned to the guest. The default gateway, when using NAT, is not the IP of the host, it's the IP of a "virtual switch" that's connected to the NAT network. (The host VMnet8 adapter is merely another device connected to the network, to allow the host to communicate with the VM.) This virtual switch we're talking about gets the .2 IP in the subnet. So in your case, your /etc/network/interfaces should read:

auto eth0
iface eth0 inet static
     address 172.241.0.101
     netmask 255.255.0.0
     gateway 172.241.0.2

This should grant your guest VM access to the internet (through 172.241.0.2), and also communicate with your host (172.241.0.100). So try it out and let me know if it works.

If it doesn't work (highly unlikely), then you need to find out what the IP of the virtual switch is. What you can do is let the VM get an IP through DHCP (i.e. change it to iface eth0 inet dhcp like you had it before), and then do route -n. This should show you the default gateway it's using. Use that IP in your static configuration.


To be able to ping the guest VM using its hostname Workshop, here's what you can do. You need to add an entry in the hosts file in Windows, which is located in C:\Windows\System32\drivers\etc\hosts. Edit that file to include the following line in the end:

To edit that file under Windows however, you need to open it as an administrator in Notepad or Wordpad...and sometimes it doesn't even let you save it, so you'll need to take a copy of the file somewhere, edit it, remove the .txt extension if it got one, and go back and replace the original one, and "confirm" it...oh how I love Linux. But anyways, here's the line you need to add:

172.241.0.101    Workshop

Once this is done, you should be able to ping Workshop successfully from your Windows host.

Though of course, to be able to deploy this in your workshop, you'll need to edit the hosts file in every single Windows host, unless you're also cloning the Windows machines.

Tip: since you're going to assign a static IP to your guest, make sure that the "NAT network" in VMplayer on all of your Windows hosts are using the subnet 172.241.0.0/16, because I think VMware randomly assigns a subnet to its virtual networks (VMnet1, 2, and so on), so VMnet8 might not be using the same subnet on another Windows host. If they're not, you'll need to manually give VMnet8 a subnet using the Virtual Network Editor in VMware.


EDIT

Okay. After the comments, here's what you need to do:

  1. Configure your (Windows) host machine to "obtain IP address automatically" on the VMnet8 adapter. It should get the IP 192.168.186.1.

  2. Configure your (Ubuntu) guest machine to a static IP in the range 192.168.186.3 - 192.168.186.127. Let's use 192.168.186.3. Also, configure the default gateway and dns server to be 192.168.186.2 So your /etc/network/interfaces should be:

    auto eth0
    iface eth0 inet static
         address 192.168.186.3
         netmask 255.255.255.0
         gateway 192.168.186.2
         dns-nameservers 192.168.186.2
    
  3. Test local connectivity by pinging 192.168.186.1 and 192.168.186.2 from the guest machine. You should also be able to ping from the host to the guest.

  4. Test internet connectivity in the guest machine by pinging google.com, or browsing the internet.

  5. Add the line 192.168.186.3 Workshop to your hosts file in the Windows host machine.

  6. Test ping Workshop from the Windows host machine.

If you want to use IPs from an altogether different network/pool other than 192.168.186.0/24, you'll need to go to Edit > Virtual Network Editor in VMware, find VMnet8, and change its DHCP settings at the very bottom to whatever network you want, and change the static IPs accordingly (the default gateway will always be the second usable IP, x.x.x.2).

enter image description here

Solution 2

I was having similar issue, using VMWare Player running on Windows 7 with Ubuntu guests. But I was able to connect from host to guest and guest to host, however the problem was I was not able to connect to internet from the guest. After reading @Alaa answer I had to just make one more tweak to add the DNS server name to the interfaces file (dns-nameservers 192.168.150.2) and then everything fell in line.

Here is my configuration that worked.

VMWare interface configuration on host:

Ethernet adapter VMware Network Adapter VMnet8: (Client)

Connection-specific DNS Suffix  . : 
Description . . . . . . . . . . . : VMware Virtual Ethernet Adapter for VMnet8
Physical Address. . . . . . . . . : 00-50-56-C0-00-08
DHCP Enabled. . . . . . . . . . . : No
Autoconfiguration Enabled . . . . : Yes
Link-local IPv6 Address . . . . . : fe80::9c13:cbf2:1dc:259f%42(Preferred) 

IPv4 Address. . . . . . . . . . . : 192.168.150.1(Preferred) 
Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . : 
DHCPv6 IAID . . . . . . . . . . . : 704663638
DHCPv6 Client DUID. . . . . . . . : 00-01-00-01-19-06-50-32-88-53-2E-7A-D3-8E
DNS Servers . . . . . . . . . . . : fec0:0:0:ffff::1%1
                                    fec0:0:0:ffff::2%1
                                    fec0:0:0:ffff::3%1
NetBIOS over Tcpip. . . . . . . . : Enabled 

Guest Ubuntu's interface changes:

auto eth0
iface eth0 inet static
address 192.168.150.10
netmask 255.255.255.0
gateway 192.168.150.2
dns-nameservers 192.168.150.2

192.168.150.2 is the VMWare's proxy that would forward guests traffic to the host.

Share:
97,425

Related videos on Youtube

malenkiy_scot
Author by

malenkiy_scot

Trench programmer. Here you can upvote my answers This is how you spell continuous.

Updated on September 18, 2022

Comments

  • malenkiy_scot
    malenkiy_scot over 1 year

    I have a Windows host that runs guest Ubuntu VM via vmplayer. That virtual machine will be cloned, distributed among several people (running Windows hosts) and used for conducting a programming workshop. I am trying - and so far failing - to setup networking to satisfy the following requirements:

    1. The guest has to have access to the internet
    2. All the clones should have the same hostname (let's say Workshop to be concrete)
    3. The host system must be able to access its respective guest via that name (e.g. ping Workshop would ping the guest that is running on that host and not any other clone)

    What I've tried so far:

    • "Installed" a NAT network adapter for the guest
    • Tried to connect the guest via DHCP, in /etc/network/interfaces:

      auto eth0
      iface eth0 inet dhcp
         hostname Workshop
      

    That works as far as connecting to the internet is concerned. However, I am unable to connect to the guest from the host at all. (E.g. ping Workshop does not work; if I use the address returned by ifconfig it does not work either from the host).

    • I then tried assigning a static address to the guest:

      auto eth0
      iface eth0 inet static
           address 172.241.0.101
           netmask 255.255.0.0
           gateway 172.241.0.100
      

    (172.241.0.100 is the address assigned statically to the host by VMWare Network VMNet8 Adapter - that's the NAT adapter above). Now, I can ping 172.241.0.101 and telnet to it from the host. I can also ping and telnet from the guest to 172.241.0.100 (the host), but that's about it - there is no connection to the wider network. (I also can't access the guest via its hostname, but that's not crucial here since if push comes to shove I can use its address directly - as long as it is the same for everybody - and not the name).

    Now, I think I can use the bridged network connection option with DHCP and that will give me what I need in case of one VM (I did not try it in this case, but I remember doing it previously). However, in case of several VM's with the same hostname and their hosts connected to the same network that will be problematic, won't it?

    Your solutions and other advice will be much appreciated.

  • malenkiy_scot
    malenkiy_scot almost 11 years
    172.241.0.2 does not work. It does not answer to a ping either (as a matter of fact, running nmap -sP 172.241.0.0/24 returns only two live hosts - .100 and .101). When configured with dhcp an entirely different address is returned by route -n : 192.168.186.2
  • Alaa Ali
    Alaa Ali almost 11 years
    Oh, I assumed that you were using the network 172.241.0.0/16 because it was the one the DHCP was using. Come to think of it though, that's actually a public IP [O.o]. Is there a reason you were assigning the host and guest IPs in the 172.241.0.0 network? Anyways, look at my edited answer.
  • malenkiy_scot
    malenkiy_scot almost 11 years
    No, it's not what DHCP is using, but that's how VMNet8 adater is configured. The DHCP address is obtained via a VMWare DHCP service. I've no idea where it gets its address pool from. I do not think the 172.241 address is public, though. When I establish a connection between the host and the guest and run CPORTS it shows that 10.63.41.41 (that's the host's address on the LAN) is connected to itself on different ports - which makes sense since this is NAT (or probably actually PAT). I actually thought along the same lines as you did regarding the gateway - that it has a different address.
  • Alaa Ali
    Alaa Ali almost 11 years
    Yup, as mentioned in my answer, the DHCP service and its pool are configurable from the Virtual Network Editor (I've added a screenshot to my answer). The gateway, DHCP and DNS server are all the same virtual device, x.x.x.2. And yes, like you said, it of course uses overloading (PAT) over your host's IP; you shouldn't be seeing the guest's IP in the wider network. Also, 172.241.0.0/16 is a public IP range =). 172.16.0.0 - 172.31.255.255 is the private range in class B addresses. But it doesn't really matter, it shouldn't affect anything.
  • Alaa Ali
    Alaa Ali almost 11 years
    Also, you can visit this page if you want to read more about NAT in VMware, it's a good read.
  • malenkiy_scot
    malenkiy_scot almost 11 years
    Looks like the adapter settings were screwed up. Possibly I played with them at some time. Registry search for 192.168.186 revealed the location where the adapter takes its address pool from: HKEY_LOCAL_MACHINE\SOFTWARE\VMware, Inc.\VMnetLib\VMnetConfig\vmnet8\IPSubnetAddress I followed your instructions and it worked. Thanks!
  • Alaa Ali
    Alaa Ali almost 11 years
    Oh, okay, I didn't know it was not installed by default. The screenshot is mainly for people who might visit the question in the future and wouldn't know what I'm talking about. I'm not sure what you meant by your 'overkill' statement, but I hope you didn't take it in an offensive way; I'm sure you are well capable of understanding my explanation without the screenshot. Anyways, good luck with your workshop!
  • user288609
    user288609 over 9 years
    Hello, I meet the same problem as yours. Would you to explain more on how you solve the problem. The first thing is that where to get the information of "Ethernet adapter VMware Network Adapter VMnet8: (Client)". Do you mean you need to update your changes in /etc/network/interfaces In addition, for the address like "netmask", "gateway", do them vary with different machine? Or I can use the same as you posted.