1

I have a virtual Ubuntu on real Windows machine, where VirtualBox is a hypervisor.

Virtual machine network is connected to host using Host-only adapter. Thing is - I can't change it for various reasons, but I would like to be able to access virtual Ubuntu from outside.

I was trying to install my own DHCP server and point VirtualBox host-only adapter to that server, but it didn't work.

How can I forward for example port 22 to real world on Windows?

1
  • simply put. you cannot while using a Host-Only network connection. theres just no getting around it. you can use either Bridged or NAT (then you have to forward ports) but not with host-only. Oct 6, 2015 at 16:15

3 Answers 3

1

Host-only means just that... there is no connection to the outside world at all. If you truly cannot switch to another adapter type, there is no way to make this happen short of configuring your Windows box as a router (which seems way out of scope).

The best option (without knowledge of your reasons against changing) is to switch to a bridged adapter, which will allow full access from outside machines.

4
  • I really can't switch to other adapter type, but I can use linux instead of Windows
    – John Dow
    Oct 6, 2015 at 16:09
  • Changing the host type doesn't matter. the issue is the HostOnly adapter, and nothing else. Oct 6, 2015 at 20:02
  • Well, if I can access this IP on host machine, there should be a way to forward it to outside world
    – John Dow
    Oct 7, 2015 at 9:59
  • You would think that, but you are wrong. from the vbox documentation, HO adapters do not link to the hosts actual network adapter, and instead create a type of loopback adapter: "This can be used to create a network containing the host and a set of virtual machines, without the need for the host's physical network interface. Instead, a virtual network interface (similar to a loopback interface) is created on the host, providing connectivity among virtual machines and the host." from virtualbox.org/manual/ch06.html Oct 7, 2015 at 13:27
1

I know I'm necro-ing a question from four years ago, but I came across this and am glad I didn't become discouraged by Frank Thomas' post (if I was reading it the way he intended it, saying that there is no possible way to have a host-only VM connect to outside of the host machine). I was trying for a while to figure out how to create a totally isolated VM, aside from some functionality like remote-desktop and FTP (also Apache). I set up the host-only adapter with DHCP. The goal was to have the host machine (Windows) to receive connections on specific ports, and then forward those connections to the host-only adapter, and thus the isolated VM (Ubuntu-Linux). I found a reliable way to do this using netsh.

Say the public IP address of my host-machine was 47.74.47.74, and the private IP of my guest-machine was 192.168.47.74: On the guest, I set up Apache to listen to its default port (80), and XRDP(remote desktop) to listen to its default port (3389). I chose random ports to use for connections to my host. As long as you remember which ports you're using, and nothing else is using them, they can be whatever you want. I wanted connections to 47.74.47.74:12567 to be forwarded to the guest and display index.html from Apache, so I had port 12567 forward to the guest port 80 using (this needs to be in CMD, Windows command console):

netsh interface portproxy add v4tov4 listenport=12567 listenaddress=0.0.0.0 connectaddress=192.168.47.74 connectport=80 protocol=tcp

(Explanation: This adds a forwarding rule on a specific port to send to another place. "v4tov4" is in reference to receiving an IPV4 address, and forwarding to an IPV4 address. "listenaddress=0.0.0.0" means that it's listening to any IPV4 address coming through that port. You can limit it to connections from a specific IPV4 address if you wish. "connectaddress" and "connectport" is the guest-machine information.)

After forwarding port 12567 to my host in my router, this enabled me to access index.html on the guest from anywhere using a web browser. Likewise,

netsh interface portproxy add v4tov4 listenport=12568 listenaddress=0.0.0.0 connectaddress=192.168.47.74 connectport=3389 protocol=tcp

allows me to remote-desktop in and connect from anywhere using Windows Remote Desktop and connecting to 47.74.47.74:12568.

FTP involves forwarding quite a few more ports in this way, and setting up the FTP server using specific ports (you can't use a port range using netsh portproxy), but I'll only explain that if somebody wants me to.

1
  • Indeed the name "Host-only" is very misleading, and any answers which put too much faith in it will end up wrong. Any OS that can act as a router can easily forward packets between the real and VirtualBox interfaces, the only issue is that Windows has this feature deliberately crippled (although still included under the name of "Internet Connection Sharing"). Mar 3, 2020 at 15:36
0

The proper necro-answer would have been to define two virtual adapters for the VM. One should be NAT, the other host-only. Problem solved.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .