Thursday, September 12, 2013

Host-Only Network External Connectivity

There are cases when we need to allow machines in a host-only network (created in VMware, for example) to connect to the Internet.

It can be achieved by creating a bridging machine that has 2 interfaces. One in the host-only network, the other one in the network we need to connect to.
The following is a sample set up (using VMware)for a case when our host-only network uses 192.168.124.* subnet.
1. Set up network adapters as follows
NameTypeExternal ConnectionHost ConnectionDHCPSubnet Address
VMnet0BridgedAuto-bridging---
VMnet1Host-only-Connected-192.168.124.0


2. Set up a bridging machine with 2 adapters - Bridged and Custom(VMnet1)

3. Set up machines in the host-only network with 1 adapter in the host-only network

4. Install OS - Linux Ubuntu 11.04 in our tests (from distribution ubuntu-11.04-alternate-i386.iso You can pick it up at http://old-releases.ubuntu.com/releases/natty/)
When prompted by OS installer, set up the first IP for the Bridging machine as 192.168.124.25 - for example. We assume that the IP in the external network will be provided by a DHCP server.

5. Login to the Bridging Machine
Execute

sudo sysctl -w net.ipv4.ip_forward=1
sudo iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

6. Login to host-only machines.
Execute

sudo route add defaut gw 192.168.124.25 eth0
sudo route delete default gw 192.168.124.1
NOTE – deleting the gateway created by default is needed for the correct routing.
sudo vi /etc/resolv.conf
Modify or enter nameserver as follows (in my case – my router’s IP): nameserver 192.168.1.1

7. Restart network

sudo /etc/init.d/networking restart 
Your host only machines should see the external network.









No comments:

Post a Comment