3

My Ubuntu is the guest OS running on a windows host. NAT is used and port forwarding has been added. All access to host on port 3000 should be forwarded to guest on the same port.

But that port can be only accessed on guest machine but not accessible from host machine.

With bridged network setting, there is no trouble. But my concern is that when I work offline(no internet connection) with my host machine, I can't access the guest via that port number any more. I've tried to disable the connection on host, then can't connect the port 3000.

What might be wrong with my installation and default NAT configuration(v4.3.20)?

  • similar issue is when having nested VM running on Windows, that is VM ubuntu running VM ubuntu - normal portforwarding suddenly does not work – serup Feb 15 '17 at 17:21
2

Another method is continue use one NAT adapter but use "127.0.0.1" as the port forwarding host IP. The port forwarding rule will be something like (you might add one for UDP also)

Protocol : TCP, Host IP : 127.0.0.1, Host port : 3000, Guest IP : "guest ip", Guest port : 3000

Then you can use 127.0.0.1:3000 to access the guest.

The loopback interface IP 127.0.0.1 is always online even the physical network is disconnect.

  • My trouble is when I use NAT, port 3000 is not accessible from host. access from guest machine to the same port has no issue. – canoe Dec 4 '14 at 5:36
  • 2
    You can verify VirtualBox port forwarding function by check output of "netstat -an -p tcp". If you see "127.0.0.1:3000 0.0.0.0:0", then it is setup correctly. If it is the case, you might want to check Ubuntu firewall setting if it allow incoming port 3000 from network interface. Access from guest machine itself often use loopback interface that is always allow. – Eric Leung Dec 4 '14 at 13:32
  • 1
    OK. Adapter 1 is enabled and attached to 'NAT', the name field is grayed out and empty. Is this correct? now the guest OS has no connection to internet. – canoe Dec 4 '14 at 13:57
  • When selected "NAT", the name field grayed out and empty is correct. When click advanced, is the cable connected ? What entry in Port Forwarding ? – Eric Leung Dec 4 '14 at 14:55
  • Cable is connected. When TCP/HostIP, GuestIP unset/ HostPort=GuestPort=3000/ doesn't work. When HostIP is changed to 127.0.0.1. It still doesn't work. No internet connection from guest and port 3000 is not shown on host machine, but can be seen on guest. – canoe Dec 6 '14 at 4:47
1

No wonder this doesn't work! Create port forwarding on the Host Only Adapter? How? As soon as I select Host Only Adapter, the Port Forwarding button is disabled. The same with the ambiguous instructions to use localhost. Nothing works. And nothing appropriate shows up in netstat either. (Then again, considering the host OS is Windows, should I be surprised?)

  • This should be a comment -- but you are totally correct. – HDave Apr 13 '18 at 15:23
0

You have to add 2 adapters inorder to that. 1 adapter for NAT & another one for Host. With the Host Only Adapter your Host and Guest OS can communicate. With NAT the Guest connects to the internet.

1)Set 1 Host Only Adapter & 1 NAT adapter
2)Enable Virtual Box Network Adapter in your Host Machine.
3)Ping both Host and the Guest and ensure both are connected. 
4)Now Create Port Forwarding on the Host Only Adapter.

Now it will work

  • I am blocked at step 3). and can't ping the gateway 10.0.2.2 on the guest - "the destination host is unreachable". – canoe Dec 2 '14 at 10:07
  • Ping the Host Only Adapter's IP address not the NAT's one. What are the IP addresses that are configured to NAT & Host Only adapter? And your Host's Virtual Box Adapter's IP address – Anbu Dec 2 '14 at 10:08
  • NAT CIDR:10.0.2.0/24, Host-Only adapter: 172.16.2.1/255.240.0.0, host's virtual box ip: 192.168.1.101/255.255.255.0. The ping from guest to host-only adapter and virtual box host returns network unreachable. – canoe Dec 2 '14 at 11:01
  • you have to change the IP address of the Host Only's Adapter in Guest OS. Change it to 192.168.1.50 / 255.255.255.0 . Then Ping the both. I will work – Anbu Dec 2 '14 at 11:19
  • Changed. Then I reboot the guest linux. Something wired happens. Now guest eth0 has only an IPv6 ip, the previous v4 ip is gone. Guest IPs - eth0: fe80::a00:27ff:fe94:e29a/64, lo:127.0.0.1, lxcbr0: 10.0.3.1/24 virbr0: 192.168.122.1/24. – canoe Dec 2 '14 at 11:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.