Possible to use VM's network connection/settings on local host?

This is for discussing general topics about how to use VirtualBox.
Post Reply
JohnnyT
Posts: 2
Joined: 19. Aug 2023, 02:29

Possible to use VM's network connection/settings on local host?

Post by JohnnyT »

Local: Win 10
Virtual: Linux

Hi, I'm new to this and was wondering whether it is possible to share the network connection and settings from my Linux VM back to my local PC? I would like to play around with the network emulation and traffic control in Linux and have that apply to my home network - is this at all possible? I'd also like to share the connection to my gaming console and use Wireshark. I can currently do it with a linux based router, hoping I can do it through a VM instead and test out other routers as well.

I am a noob at this, I've searched for guides but have had no luck so if it is at all possible I'd really appreciate a link to a guide or step by step instructions on how to achieve this.

What I have tried so far after some googling, is set up my VM to have 2 network cards. Adapter 1 as NAT and Adapter 2 as Host only adapter. What I noticed is my VM has 2 networks, one with a 10.* IP and another on 192.168.56.* range. My PC is connected to my router and has internet via wifi, when I have shared my PC's connection with my console in the past, I have had to bridge the ethernet and wifi connection together in the network connections control panel with my gaming console connected to my PC via ethernet. I tried bridging the wifi with the VM's host only ethernet adapter but it gave me no internet. Not sure if it is possible to bridge those two and my actual ethernet adapter which my gaming console is connected to?

Is what I want to achieve possible at all?
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Possible to use VM's network connection/settings on local host?

Post by scottgus1 »

First, it will be best to familiarize yourself with the Virtualbox networking types and what they're supposed to do: Virtualbox Networks: In Pictures
It will hopefully help explain why your VM's network adapters are getting the IP addresses they're getting, and why trying to Bridge your Wi-Fi adapter and Host Only network may not have worked.

Second, from this:
JohnnyT wrote: 19. Aug 2023, 02:47 I would like to play around with the network emulation and traffic control in Linux and have that apply to my home network
I gather that you want to have the VM filter the internet traffic to your house network. If this is a correct interpretation, then it is possible for a VM to filter a physical network's traffic.

If you tried this using an extra physical PC as the filtering device, your extra PC would need two network adapters.

If you have a separate modem in one device and a Wi-fi router in a second device, you would connect the modem to the first of the filter PC's network adapters, and the router, set up as a Wi-Fi access point and switch, to the second filter PC network adapter. The software on the filter PC would serve as a router for the second adapter and hand out DHCP-served IP addresses, and the Wi-Fi devices and LAN devices in the house would connect to the Wi-Fi access point router.

BTW if your modem and router were in one package, you would need another Wi-Fi router. You'd disable the Wi-Fi on the modem router, feed it to the filter PC's first adapter as above, then have the new second Wi-Fi router set up as a Wi-Fi access point and switch connected to the second Filter PC network adapter, as above.

The basic premise is:
Internet > Modem > filter PC (providing router services) > network switch with Wi-Fi access point, or Wi-Fi router configured as access point > Wi-Fi & Lan devices.

Doing this with a VM is only a hint more complicated. The VM's host PC needs the two physical network adapters. The VM is Bridged to both of them. The host is configured to only be able to access network traffic on the second adapter. The first adapter is configured to only allow Virtualbox Bridging, so the host OS cannot get network traffic through it, only the VM.

Internet > Modem > first network adapter only Bridged to VM > VM router & filter services > second adapter bridged to VM and host OS > network switch / Wi-fi access point-configured router > Wi-Fi & Lan devices.

The host can only get traffic from the second adapter so it only gets filtered internet along with the rest of the LAN.

There's going to be questions on how to do this, please feel free to ask them. Also, if this does not sound like what you were trying to do, please draw a picture of what you were wanting to do and we'll see if Virtualbox can do it.
JohnnyT
Posts: 2
Joined: 19. Aug 2023, 02:29

Re: Possible to use VM's network connection/settings on local host?

Post by JohnnyT »

Thanks for your response. This sounds a little too difficult for me and I only have one PC with one network card anyway so it seems like it will be impossible to achieve what I want to do with the VM. I guess my other option would be to see if I can bridge the Wi-Fi and ethernet adapter off a Linux bootable USB and share that connection to my gaming console.

When I get a new PC I'll make sure to get a second NIC and revisit your instructions. Appreciate the help.
Post Reply