1

I am trying to simulate a client behind a NAT using Virtual Box.

I have a host machine let's say with an IP address 130.0.0.1. I create a virtual machine (let's call it VM1) running Ubuntu 12.04 with two network interfaces.

eth0 - Bridged Adaptor (Let's say it gets an address 130.0.0.2)
eth1 - Host-only Adaptor (Let's say it gets an address 192.168.0.1)

In VM1, I clear any iptable rules using:

iptables -F 
iptables -t nat -F 
iptables --delete-chain 
iptables --table nat --delete-chain

I enable packet forwarding by kernel by using the command:

echo 1 > /proc/sys/net/ipv4/ip_forward

I create new rules using iptables:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE OR iptables --table nat --append POSTROUTING --out-interface eth0 -j MASQUERADE

iptables -A FORWARD -i eth1 -j ACCEPT OR iptables --append FORWARD --in-interface eth1 -j ACCEPT

I configure the eth1 interface of VM1 whose /etc/network/interface has the following entries:

auto lo
iface lo inet loopback 
auto eth1 
iface eth1 inet static 
address 192.168.0.1 
netmask 255.255.255.0

And I create another virtual Machine (let's call it VM2) running Ubuntu 12.04 (Host-only adaptor). I configure its interface by setting the following entries in the /etc/network/interface:

auto lo
iface lo inet loopback
address 192.168.0.2
netmask 255.255.255.0
gateway 192.168.0.1

So, according to this setting, VM2 should behave as a client behind a NAT (VM1) and I am trying to connect to the machines present on the network of host from VM2. When I:

ping 130.0.0.2 or
ping 192.168.0.1 

it works. But when I try to:

ping 130.0.0.1 or
any other machine on that network

I don't get any response back. Can anybody let me know what I am missing or doing incorrectly here?

0

You must log in to answer this question.

Browse other questions tagged .