Problem with router on VM

This is for discussing general topics about how to use VirtualBox.
Post Reply
mailo
Posts: 3
Joined: 13. Sep 2013, 18:06

Problem with router on VM

Post by mailo »

I want to create on one virtual machine (CateOS) a virtual router. Next, second virtual machine (CateOS too) should connect via this virtual router to the Internet.

This is my configuration:

1st (router):
- eth0 is bridget adapter with my physical wlan card (Broadcom 802.11n Network Adapter)
is configured by DHCP and it has already

ip: 192.168.1.108,
netmask: 255.255.255.0,
gateway: 192.168.1.1

- eth1 is VirtualBox Host-Only Ethernet Adapter (Promiscuous Mode:Allow All - but I think in my case it isn't important, is it?)
is configured manually and it has already:
ip: 192.168.0.1
netmask: 255.255.255.0
gateway: 192.168.0.1
dns servers: 8.8.8.8

I wrote in console as root:

Code: Select all

echo 1 > /proc/sys/net/ipv4/ip_forward 
iptables -A POSTROUTING -s 192.168.0.0/24 -j MASQUERADE -t nat
2nd VM:

- eth0 is VirtualBox Host-Only Ethernet Adapter (Promiscuous Mode: Allow all)
is configured manually and it has already:
ip: 192.168.0.2
netmask: 255.255.255.0
gateway: 192.168.0.1
dns servers: 8.8.8.8

From 2nd VM I can ping 192.168.0.1 but I can't ping any address from the Internet (Unknown host for google for example). It looks like router doesn't want to forward packages but I don't know why. I am beginner but the instruction for iptables looks good for me. Do you have any ideas? Of course I have the internet access on the virtual router. What maybe can be important that I use livecd version of CateOS (without installation) so I don't reboot it anytime.
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Problem with router on VM

Post by Perryg »

I would use the internal mode instead of host-only for the host and guest LAN (private side)
Router guest would would have one NAT or Bridged and one internal. 2nd guest would have internal.
mailo
Posts: 3
Joined: 13. Sep 2013, 18:06

Re: Problem with router on VM

Post by mailo »

Thank you for reply. Should I change something more? Because when I change only type to internal (with the same name "intnet") on both devices, the situation is the same (only ping 192.168.0.1 is working).
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: Problem with router on VM

Post by Perryg »

If you setup the guest/s properly they will be able to ping each other. Then if you setup your router properly they will be able to ping the Internet.
VirtualBox provides the emulated hardware but specific configurations are up to the end user. Normal network knowledge is all you need.
noteirak
Site Moderator
Posts: 5231
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: Problem with router on VM

Post by noteirak »

make sure iptables does not have a default DROP policy, and if it does, change accordingly.
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
mailo
Posts: 3
Joined: 13. Sep 2013, 18:06

Re: Problem with router on VM

Post by mailo »

Yea :) It works :) Thanks noteirak. You had right, something was wrong in the default configuration. iptables --flush solved the problem.
Post Reply