VirtualBox bridged network and NAT port forwarding at the same time

Discussions about using Linux guests in VirtualBox.
Post Reply
jayChandler
Posts: 4
Joined: 5. Oct 2017, 19:21

VirtualBox bridged network and NAT port forwarding at the same time

Post by jayChandler »

My Host OS is Windows 10 and i am running an Ubuntu Server 16-04 Guest VM. On my guest VM i have enabled Network Bridge and its working fine. I get a proper IP from the DHCP and both boxes can ping each other.

But now i have some services running on my HOST which want to make accessible via port forwarding to my VM.

I have added a second network adapter in NAT mode and added a rule

Host Ip: Blank
Host Port: 9042
Guest Ip: Blank
Guest Port: 9042

I want to redirect my HOSTS 127.0.0.1:9042 to my VMS 127.0.0.1:9042

This is the output from the log

NAT: Set redirect TCP 0.0.0.0:9042 -> 0.0.0.0:9042

I rebooted the VM several times but when i do

netstat -nap | grep 9042
The output is empty

Also trying

telnet 127.0.0.1 9042 ends up in Conection refused

What am i doing wrong here ? Is this not possible ?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: VirtualBox bridged network and NAT port forwarding at the same time

Post by Perryg »

If you are using bridged then you are not using vbox NAT and vbox NAT port forwarding only works in vbox NAT.
jayChandler
Posts: 4
Joined: 5. Oct 2017, 19:21

Re: VirtualBox bridged network and NAT port forwarding at the same time

Post by jayChandler »

And how can i acomplish what i want ?
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: VirtualBox bridged network and NAT port forwarding at the same time

Post by Perryg »

Switch from bridged to NAT or add a second adapter in the guest set to NAT.
jayChandler
Posts: 4
Joined: 5. Oct 2017, 19:21

Re: VirtualBox bridged network and NAT port forwarding at the same time

Post by jayChandler »

Thats exactly what i have done!

I have added a second adapter with NAT

Primary Adapter is Bridged
Secondary is NAT

But forwarding does not work
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: VirtualBox bridged network and NAT port forwarding at the same time

Post by Perryg »

Odd. Try temporarily disabling the adapter set to bridged and see what happens. If it still fails make sure you do not have a firewall issue that is blocking the port.
jayChandler
Posts: 4
Joined: 5. Oct 2017, 19:21

Re: VirtualBox bridged network and NAT port forwarding at the same time

Post by jayChandler »

Just not working

This are my settings! See my attachments

Anything wrong with my rules ?
Attachments
Adapter 2
Adapter 2
adapter2.PNG (98.06 KiB) Viewed 5286 times
Adapter 1
Adapter 1
adapter1.PNG (50.86 KiB) Viewed 5286 times
Perryg
Site Moderator
Posts: 34369
Joined: 6. Sep 2008, 22:55
Primary OS: Linux other
VBox Version: OSE self-compiled
Guest OSses: *NIX

Re: VirtualBox bridged network and NAT port forwarding at the same time

Post by Perryg »

What you provide does not really show an error but that is just the tip of the iceberg. Like I said you need to make sure the host is not blocking this with its firewall. Also I admit I am slightly confused with your first post when you say you want to make services on the host available to the guest.
But now i have some services running on my HOST which want to make accessible via port forwarding to my VM
This is not the way it normally works if I take this statement literally.
mpack
Site Moderator
Posts: 39134
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: VirtualBox+Oracle ExtPack
Guest OSses: Mostly XP

Re: VirtualBox bridged network and NAT port forwarding at the same time

Post by mpack »

It seems to be that this entire question is misplaced. If the VM is bridged to the physical network then it's a peer on the same network as the host, i.e. it's just two (or more) PCs networked together. Share services across that network the same way you'd do it if VMs were not involved.

As Perry has said, port forwarding is only applicable to NAT. NAT blocks every port by default, and forwarding is a way of creating exceptions to that. But if the VM is using bridged then it already receives everything on every port.
Post Reply