How to make the guest being the router/gateway for the host?

This is for discussing general topics about how to use VirtualBox.
Post Reply
Roll Valentin Kremlins
Posts: 1
Joined: 21. Dec 2012, 15:40

How to make the guest being the router/gateway for the host?

Post by Roll Valentin Kremlins »

Hi, all

Host: 64-bit Windows 7 Ultimate.
Guest: 64-bit Ubuntu 12.10

One of the simplest network VM configuration, for the most basic usecase, is seting up NAT-based networking so that the host OS provides Internet access to the guest OS, allowing him to browse the WEB, for example.
For that usecase, the VBox-embedded DHCP server comes in handy, giving the guest OS necessary information about network routing.

However, I would like the exact contrary:

I am already able to make the guest OS have Internet acces per himself (Using an USB WiFi adapter and USB passthrough).

I would like to make the guest OS share his Internet connectivity with the host OS:
- I would like to simulate a single Ethernet segment with only the host box and the guest box on it.
- The host OS will use a software 'TAP' device (for Ethernet frames), NOT a 'TUN' device (for IP packets), and the guest OS will use a corresponding emulated Ethernet network interface.
- I don't need VBox DHCP server.
- I will setup an authoritative DHCP server for IPv4 inside the guest OS, telling the default route, making the guest a real IPv4 router.
- The host OS will learn that there is a router on his virtual LAN segment whenever the virtual cable is plugged.

Could you help me, please, configure the VBox virtual machine to achieve this goal?

For final touch on host_OS-specific or guest_OS-specific network configuration, I can do it myself using WiresShark; ideas welcome though ;-)

I am looking forward to hearing from you all, and would like to thank you for the time invested.

I wish you all an Happy Xmas,
Valentin
BillG
Volunteer
Posts: 5105
Joined: 19. Sep 2009, 04:44
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows 10,7 and earlier
Location: Sydney, Australia

Re: How to make the guest being the router/gateway for the h

Post by BillG »

That should be possible. You could use the Host Only adapter to connect the host to the guest. Or, since you have a Windows host you could create a Microsoft loopback adapter in the host. Either of these will give you a network connection between host and guest to use as your "private" LAN behind the router in the vm.
Bill
noteirak
Site Moderator
Posts: 5229
Joined: 13. Jan 2012, 11:14
Primary OS: Debian other
VBox Version: OSE Debian
Guest OSses: Debian, Win 2k8, Win 7
Contact:

Re: How to make the guest being the router/gateway for the h

Post by noteirak »

only one way : set the NIC on the VM as Bridged, disable any DHCP on your internet router, configure you guest on a sub with the real router, and another subnet for the guest and the host.

If you want the host to be really disconnected from your router, create a host only itnerface as the guest-host network and disable TCP/IP on the host for the real NIC
Hyperbox - Virtual Infrastructure Manager - https://apps.kamax.lu/hyperbox/
Manage your VirtualBox infrastructure the free way!
MidGe
Posts: 1
Joined: 8. Dec 2011, 12:23
Primary OS: Ubuntu other
VBox Version: OSE Debian
Guest OSses: Linux, windows

Re: How to make the guest being the router/gateway for the h

Post by MidGe »

I think I managed to do what you want to do with a Linux Host, a Linux Guest and a USB NIC as second NIC.

What I did is use a USB NIC as my second NIC for the WAN connection and use the internal NIC as the LAN connection. Both network adapters are in Bridged mode.

1. Boot the host without the USB NIC attached. The internal NIC is connected to my switch.
2. Ensure that the /etc/network/interfaces file in the host does not contain an entry for the USB NIC. The host ought not to be able to access the net at this point.
3. Attach the USB NIC to the host (and to the modem/pppoe or whatever you use for internet connection). The host should still not be able to access the net.
4. Boot the guest (as router/gateway) and allow it to capture the USB NIC automatically if the guest /etc/network/intrefaces file contains the entries for the internal and the USB NIC.
5. The host should now be able to reach the net via the guest. Stopping the guest or the LAN NIC in the guest and the host cannot connect to the net any longer.

Where I am using a switch, it should work in the same way with direct cable/connection if you don't have a switch.

By the way, my reason to do this is that I am using a old computer instead of using a router. Altough the computer is old, it still has a fair bit of grunt, far too much for being just a router. In this way I am able to run more VMs in it and run them in serial if I want to play with Snort for instance, I can run some honeypots in other VMs on that host and whatever else a fertile mind can think of, without any resources wastage.

Hope this helps.

If more information is needed, simply reply on this thread as I will subscribe to it for a while anyway, and I will try to answer any further questions you may have.
Post Reply