3

I would like to create the following network:

Internet ---- Host machine ---- VM1 ---(local network)-- VM2

with VM1 acting as a NAT router. VM1 and VM2 run Ubuntu via VirtualBox.

To achieve this, I created a local network 192.168.46.x for VM1 (192.168.46.101) & VM2 (192.168.46.102). I also set the value in /proc/sys/net/ipv4/ip_forward to 1 (for VM1). In addition to that, I attached VM1 to NAT.

With this configuration, I can ping VM1 from VM2 and vice versa, and I can also ping google.com from VM1.

I thought that for being able to ping google.com from VM2, I would have just to add the following entry to VM2's routing table:

Dest      Gateway         Netmask        Iface
0.0.0.0   192.168.46.101  255.255.255.0  enp0s3

(where enp0s3 is the only network interface of VM2).

But still, VM2 gets "unknown host google.com" when pinging.

Could you help me figure out why?

ifconfig for VM1, ifconfig for VM2, route -n for VM1, route -n for VM2

manuch100
  • 71
  • 1
  • 1
  • 6

1 Answers1

4

I was actually missing some entries to iptables, added as follows:

# iptables -t nat -A POSTROUTING -o enp0s3 -j MASQUERADE
# iptables -A FORWARD -i enp0s8 -o enp0s3 -m state --state RELATED,ESTABLISHED -j ACCEPT
# iptables -A FORWARD -i enp0s8 -o enp0s3 -j ACCEPT

with enp0s8 the interface to the outer world, and enp0s3 the interface to the Internal network.

Requests to the Internet from VM2 are now working... :)

manuch100
  • 71
  • 1
  • 1
  • 6