VMware Communities
farsinsen
Contributor
Contributor

Is it possible to create/update an entry in the hosts file on Windows with the ip of the host?

Hi,

I'm wondering if there is any way to create and/or update an entry in the hosts file of the guest OS with the ip of the host each time the guest is booted/resumed (only relevant on Windows for me but I guess other could make use of this hint for other OS'es).

I'm working as a web developer and run Windows in Fusion to be able to test websites through Apache running on the host (my Mac). The work takes place at various locations (with differenc access points) which means that the ip of the host changes. Instead of looking up the IP of the host and typing that into the addresse bar of the browser in the guest OS a static entry in the hosts file would be great.

Anyone know if it's somehow possible?

Tags (3)
0 Kudos
4 Replies
rcardona2k
Immortal
Immortal

Since you're switching networks, I'm assuming you use NAT networking for the VM. In this case, I've always found host services are available via the static address of the NAT TCP/IP gateway as shown by ipconfig. I know I can mount Windows Sharing and access OS X apache using this address. If you set up a named alias in /etc/hosts in the guest as the NAT TCP/IP is a static address and this will work.

0 Kudos
farsinsen
Contributor
Contributor

Hi,

Thanks for your reply.

Just to make it clear - yes I am using NAT networking for my VM's.

Im sorry, but (if you are suggesting a solution) I don't understand it Smiley Wink English not being my native tongue might be the issue, so please bear with me.

As both the host and the guest optains a new ip when I change to another network, I don't see how you'll be able to expect any of the IP's being static. Can you please elaborate a bit on your suggestion?

- Peter

0 Kudos
rcardona2k
Immortal
Immortal

Just to make it clear - yes I am using NAT networking for my VM's.

As both the host and the guest optains a new ip when I change to another network, I don't see how you'll be able to expect any of the IP's being static. Can you please elaborate a bit on your suggestion?

One of these statements does not match the other. For a VM configured with NAT, it's DHCP-assigned address from VMware does NOT change between networks, for instance my XP machine has this address on several wired and Wifi networks. I can release and renew and I get back the same address:

>ipconfig

Windows IP Configuration

Ethernet adapter Local Area Connection:

Connection-specific DNS Suffix . : localdomain

IP Address. . . . . . . . . . . . : 172.16.208.128

Subnet Mask . . . . . . . . . . . : 255.255.255.0

Default Gateway . . . . . . . . . : 172.16.208.2

With this information, I can access OS X services such as apache using the Default Gateway address of 172.16.208.2. If I wanted to use a named alias I would open c:\windows\system32\drivers\etc\hosts and add a line like:

172.16.208.2 mac

Then in a guest web browser, my host's web server is http://mac/

farsinsen
Contributor
Contributor

Ahh. Thanks for clarifying that!

I never thought of accessing the host by the ip of the 'Default Gateway' - I've always used the 'public' IP of the host (the one provided to it by whatever access point I was on).

This is a really nice trick - thanks for pointing out the solution!

0 Kudos