Sunday, April 25, 2010

Port Forwarding to Virtual Machines :-D

Many a times we would install some server on a virtual machine and wondered how on earth could we show that to the outsite world, well here is a tutorial which shows just that.

Open Bash "Bourn again Shell"

Here you can see that this file is just read only even for root, first change that permission.

bala@ubuntu:~$ ls -l /etc/vmware/vmnet8/nat/nat.conf
-r--r--r-- 1 root root 1246 2010-04-25 11:16 /etc/vmware/vmnet8/nat/nat.conf

Here we are changing that permission.

bala@ubuntu:~$ chmod 644 /etc/vmware/vmnet8/nat/nat.conf
chmod: changing permissions of `/etc/vmware/vmnet8/nat/nat.conf': Operation not permitted

Changing the permission of a file required root privilege in this case.

bala@ubuntu:~$ sudo chmod 644 /etc/vmware/vmnet8/nat/nat.conf
[sudo] password for bala:
bala@ubuntu:~$ ls -l /etc/vmware/vmnet8/nat/nat.conf
-rw-r--r-- 1 root root 1246 2010-04-25 11:16 /etc/vmware/vmnet8/nat/nat.conf

Now that we have got write permission for root let us gedit it :-D

bala@ubuntu:~$ sudo gedit /etc/vmware/vmnet8/nat/nat.conf

I have just taken one small part of the file, as I am going to allow the port forwarding of host machine 80 to the virtual machine 80. In this case my Virtual machine's IP is and the apache server is running on port 80.

# WEB (make sure that if you are using named webhosting, names point to
# your host, not to guest... And if you are forwarding port other
# than 80 make sure that your server copes with mismatched port
# number in Host: header)
# lynx http://localhost:8888
#8888 =

80 =

After this save the file by pressing "CTRL + S" if you are using gedit, if you are using vi editor for saving
Press ESC key
Then press :
Then type wq
Then press enter.

After this let us change back the permission on the file back to its original value.

bala@ubuntu:~$ sudo chmod 444 /etc/vmware/vmnet8/nat/nat.conf

Now we need to restart the vmnet8 network so that this will start functioning as we expect.

This "" website helped me a lot with it.

Use the following command.

bala@ubuntu:~$ sudo /usr/lib/vmware/ restart 8
DHCP server on /dev/vmnet8 done
NAT service on /dev/vmnet8 done
Host-only networking on /dev/vmnet8 done
Host-only networking on /dev/vmnet8 (background) done
DHCP server on /dev/vmnet8 done
NAT service on /dev/vmnet8 done

Now try to access http://localhost via your browser and wola you are in your virtual machine now :-D hurray.

Now don't stop there if you need to access the same on your LAN then your host firewall should allow it. Add in a rule according to the firewall you use on your host machine. From now on if any one hits your host IP on port 80 they will be get the web-page hosted on your virtual machine.

No comments:

Post a Comment