Resolve Guest Nat IP Address on Host

Discussions related to using VirtualBox on Linux hosts.
yupthatguy
Posts: 73
Joined: 4. Jul 2015, 07:48

Resolve Guest Nat IP Address on Host

Post by yupthatguy »

Hi there,

I've been reading the manual, but I can't quite figure out the best method to solve a relatively common problem.
https://www.virtualbox.org/manual/UserM ... lver_proxy

I need the hostname & domain names of websites that I am developing inside the guest to be resolved by the host via the host's

Code: Select all

/etc/hosts
file.

I have an Ubuntu 20.04 desktop host and an Ubuntu Server guest running in Vbox6.1 with GA.

My NAT adapter assigns the default address 10.0.2.15, which cannot be resolved by the host (can't ping from host to guest).

By default my guest server and domains are assigned to 10.0.2.15, so this has prevented me from resolving guest hostname/domains.
https://10.0.2.15:10000 and domain name test.example.com cannot be reach via browser by host machine.

I want you use my host resolver &

Code: Select all

/etc/hosts
so that I can manage all of my domains, like so:

Code: Select all

10.0.2.15    test.example.com   <- current setting
10.0.2.15    website1.com
10.0.2.15    website2.com
After reading the manual, I thought this command should have solved the problem, but no luck:
VBoxManage modifyvm MY-vm-name --natdnshostresolver1 on

I also tried VBoxManage setextradata My-vm-name "VBoxInternal/Devices/{pcnet,e1000}/0/LUN#0/AttachedDriver/Config/HostResolverMappings/ \
resolve-virtualmin-vbox-address/192.168.58.1" 192.168.47.47 (broke the machine :? )

Any tips? Thx
yupthatguy
Posts: 73
Joined: 4. Jul 2015, 07:48

Re: Resolve Guest Nat IP Address on Host

Post by yupthatguy »

Here is log file from a clean attempt to use

Code: Select all

 VBoxManage modifyvm MY-vm-name --natdnshostresolver1 on
Instead of using the hosts resolver, it seems to simply block everything
Attachments
VBox.zip
(37.13 KiB) Downloaded 8 times
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Resolve Guest Nat IP Address on Host

Post by mpack »

By definition, NAT devices do not respond to unsolicited messages. You can't communicate with it from a host. And 10.x addresses are not routable.

You need to be using "bridged" or "host only" if you want the host to be able to initiate comms with the guest OS. Or you can set up port forwarding, but that would be complicated and only work for certain specific protocols such as remote desktop.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Resolve Guest Nat IP Address on Host

Post by scottgus1 »

yupthatguy wrote: 

Code: Select all

VBoxManage modifyvm MY-vm-name --natdnshostresolver1 on
https://www.virtualbox.org/manual/ch09.html#changenat :
9.8.6. Using the Host's Resolver as a DNS Proxy in NAT Mode
For resolving network names, the DHCP server of the NAT engine offers a list of registered DNS servers of the host. If for some reason you need to hide this DNS server list and use the host's resolver settings, thereby forcing the Oracle VM VirtualBox NAT engine to intercept DNS requests and forward them to host's resolver
yupthatguy wrote:I need the hostname & domain names of websites that I am developing inside the guest to be resolved by the host
I think you've accidentally got the concept backwards. The command controls how the guest resolves names from the host, not the host resolve names from the guest.
yupthatguy wrote:By default my guest server and domains are assigned to 10.0.2.15
This is expected, because you're using NAT. See Virtualbox Networks: In Pictures: NAT. Essentially, NAT puts a "router" between the host and the guest. As Mpack points out, a router does not let the WAN side (which in Virtualbox is the host) talk to the LAN side (which in Virtualbox is the guest), unless the LAN side asks for the communication first, or there is a port opened in the router's Port Forwarding rules.

Mpack's recommendation of Bridged or Host-Only would be much easier.
yupthatguy
Posts: 73
Joined: 4. Jul 2015, 07:48

Re: Resolve Guest Nat IP Address on Host

Post by yupthatguy »

@mpack & @scottgus1 You both were/are right and accurate sorry for my misunderstanding. After hours of searching I finally found a tutorial that shows how to achieve my goal of setting vbox for local web development.

https://www.wpdiaries.com/virtualbox-fo ... velopment/

Clear, straightforward, I recommend this for any web developer setting up a vbox dev environment.

I am staying with the NAT & Host-Only adapter combo.

My only questions at this point is this:

Virtualmin still sets up shop on 10.0.2.15, which mpack points can't resolved by the host. If I set-up Ubuntu Desktop on the server would I be able to visit https://10.0.2.15:10000 on firefox can I see my control panel? If not, can I create a custom NAT adapter with an IP like 192.169.63.X and then set-up Virtualmin / view control panel inside the box?

Virtumalmin has a feature allows me to additional ips and hostnames for them. I am assuming that I will be able to add the ip of the host-only adapter 192.168.62.1 a hostname, then edit my -host- machine's /etc/hosts file and view the website in my host machine browser. will a need a dns server?
mpack
Site Moderator
Posts: 39156
Joined: 4. Sep 2008, 17:09
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Mostly XP

Re: Resolve Guest Nat IP Address on Host

Post by mpack »

yupthatguy wrote: I am staying with the NAT & Host-Only adapter combo.

My only questions at this point is this:

Virtualmin still sets up shop on 10.0.2.15, which mpack points can't resolved by the host. If I set-up Ubuntu Desktop on the server would I be able to visit https://10.0.2.15:10000 on firefox can I see my control panel?
You have now connected the VM to two separate networks: the NAT network (using 10.x addresses) and the host-only network (using 192.168.xx.yy addresses). As previously mentioned, devices behind a NAT interface will not see unsolicited messages, so messages sent to the 10.x address will not arrive. Instead you need to send them to the 192.168.xx.yy host-only network address.

Please explain why you want to use NAT+hostonly instead of bridged? I'm sure you have a good reason, but this makes things complicated - and we can't offer good advice if we don't understand the requirements.

p.s. Please do not reference external authorities. The only authority we care about here is the user manual, and our own tutorials in the HOWTO area. That's because we know that the information originally came from (or was parsed by) a recognized expert, and is kept up-to-date by us.
yupthatguy
Posts: 73
Joined: 4. Jul 2015, 07:48

Re: Resolve Guest Nat IP Address on Host

Post by yupthatguy »

My ultimate goal is to establish an ubuntu 20.04 desktop host and ubuntu 20.04 server guest development environment with Virtualmin control panel.

I use a UFW killswitch with a wireguard vpn. Therefore, when using a bridged network adapter, in months past, trying to get internet connections for my vbox server in locations other than my home has required, significant wasted time fiddling with the firewall settings because depending on which network I am on, the gateways change. I would rather focus on development not firewall.

So now, that I am switching from debian to ubuntu server, I want to put my vbox connectivity issues to bed once and for all (or at least for a few years).

@mpack thanks again for your reply. Your advice about 10.X addresses not being routeable saved me a lot of time by not fiddling with ubuntu desktop inside the vbox. After, my last post, I finally "cracked" it about 95%, maybe you guys can help with the last 5%.

Instead, I focused on getting internet access for the static ip inside the ubuntu vbox server. This is my .yaml file, so if others find this post

Code: Select all

network:
  version: 2
  renderer: networkd
  ethernets:
        enp0s3:
            addresses: ['192.168.61.47/24']
            gateway4: 192.168.61.1
            nameservers:
                addresses: [127.0.0.1, 192.168.61.1, 8.8.8.8]

I also configured a vboxnet0 with ip address 192.168.61.1 (this is the gateway in the yaml above)

in UFW I added:

Code: Select all

ufw allow allow in|out on vboxnet0

And, on my Ubuntu host I ran, these commands:

Code: Select all

sudo iptables -A FORWARD -o wg0 -i vboxnet5 -s 192.168.61.0/24 -m conntrack --ctstate NEW -j ACCEPT

sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

sudo iptables -t nat -F POSTROUTING

sudo iptables -t nat -A POSTROUTING -o wg0 -j MASQUERADE
I got them from an ubuntu man page about shared connections. This works... I get internet inside the box, I get host-guest communication, I have the option of ssh over NAT.

The only problem is that I don't know how to make the shared connection permanent.

I am guessing that I have to tinker with the /etc/ufw/before.rules and/or ip tables... I but don't how to do either... any tips you guys provide would be helpful.

thanks
yupthatguy
Posts: 73
Joined: 4. Jul 2015, 07:48

Re: Resolve Guest Nat IP Address on Host

Post by yupthatguy »

Update: I just installed my control panel. Sure enough.. I can access the control panel from the host, using the IP address from the guest. However I cannot access it using its domain name test.example.com which is currently in my host machine's /etc/hosts file

192.168.61.47 test.example.com

Does host my host or guest need a dns server to be configured?
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Resolve Guest Nat IP Address on Host

Post by scottgus1 »

I'm not entirely sure where you've gone. From this:
yupthatguy wrote:I also configured a vboxnet0 with ip address 192.168.61.1 (this is the gateway in the yaml above)
I deduce you are now using the Host-Only network for network access to the VM, and you are trying to jam internet into the Host-Only as well.

With a Host-Only connection there would have been no need to communicate through the NAT "router" into the VM, as Host-Only has no firewall or port forwarding requirements; it's just a basic network connection.

FWIW Virtualbox NAT gives the VM internet, because NAT provides a gateway to the VM.

By default, Host-Only does not provide a gateway, because Host-Only is designed for communication to the host only, not the internet, which is beyond the host.

It appears that you have gone beyond the design of Host-Only, which is not necessarily a bad thing, but it may be beyond what we are aware how to do, and may be considered beyond the scope of the forum, though a forum guru might be interested to look in and advise outside of the usual Virtualbox manual descriptions.

Regarding the IP address vs domain name question, the general rule is: If you can ping as little as one direction across the network, then the network is working, and further difficulties are caused by setup glitches in the various OS's. In other words: the Virtualbox host-Only network is working, because you can communicate by IP address. So you now have to set up the usual thing in the host OS and the VM OS so they broadcast their domain names onto the network so other OS's can pick those broadcasts up and know what name goes with what IP address. Virtualbox does not provide this setup. it's a host OS & VM OS thing.
yupthatguy
Posts: 73
Joined: 4. Jul 2015, 07:48

Re: Resolve Guest Nat IP Address on Host

Post by yupthatguy »

I deduce you are now using the Host-Only network for network access to the VM, and you are trying to jam internet into the Host-Only as well.
I've done exactly this... no longer need a NAT adapter. I can put my 4 commands into bash script and re-establish outside internet access for the host only adapter, but I think it be more useful to myself and others that may read this post to know the actual way of permanently joining /sharing host-only adapter with host's primary network interface using ip MASQUERADE. So who are these gurus you refer to?

So you now have to set up the usual thing in the host OS and the VM OS so they broadcast their domain names onto the network so other OS's can pick those broadcasts up and know what name goes with what IP address. Virtualbox does not provide this setup. it's a host OS & VM OS thing.

"The usual thing"... is a bit vague. would you mind pointing me in the direction of a specific tool? dns server (yes/no) other options. Once I know the tool, I can figure things out from there. Thanks in advance.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Resolve Guest Nat IP Address on Host

Post by scottgus1 »

yupthatguy wrote:who are these gurus you refer to?
They'll be along. I don't want to name names in case they are tied up elsewhere.
yupthatguy wrote:"The usual thing"... is a bit vague.
That's because I don't know what Linux calls it. I vaguely think Windows calls it NetBIOS or WINS. But roughly, once two Windows PCs are networked, they quickly end up knowing each other's network names due to some Windows service and can access each other by \\networkname instead of \\ip.add.re.ss. Figure out what Linux service does the same thing. 'Tis web-search time....
yupthatguy
Posts: 73
Joined: 4. Jul 2015, 07:48

Re: Resolve Guest Nat IP Address on Host

Post by yupthatguy »

@scottgus1 thanks for point in the right direction... I need a linux equivalent of WINS or NetBios... should be easy enough to find. In the meanwhile I wrote a detailed description of my current predicament for askubuntu.com is it bad etiquette to post a link to my question in this forum? Or should copy/paste the content here.?

Here's the link:
https://askubuntu.com/questions/1387393 ... guest-to-h
let me know if it is better to copy/paste.
scottgus1
Site Moderator
Posts: 20965
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: Resolve Guest Nat IP Address on Host

Post by scottgus1 »

Go ahead, this could be useful to folks in the future, possibly for those who can't get Bridged to work with Wi-Fi.
yupthatguy
Posts: 73
Joined: 4. Jul 2015, 07:48

Re: Resolve Guest Nat IP Address on Host

Post by yupthatguy »

I cracked the ip masquerade problem. It was so easy.. I wanted smack myself across the head. I have one last piece to this puzzle to solve and I will post a complete User Guide to configuring host-only adapters with internet access for local vbox web development.

In any case any gurus are hanging around this is the beast that I trying to tame:
https://serverfault.com/questions/10904 ... esuloution
yupthatguy
Posts: 73
Joined: 4. Jul 2015, 07:48

Re: Resolve Guest Nat IP Address on Host

Post by yupthatguy »

@scottgus1

Coming full-circle to the start of this post series...
VBoxManage modifyvm Virtualmin --natdnshostresolver1 on

Is there a host-only version of this command? something like "VBoxManage modifyvm Virtualmin --hostonlydnshostresolver1 on" ?

I ran a dig request on my guest's domain name example.com and it brought up my prod server's DNS server which is understandable since I use ip masquerade to send internet traffic from the guest to my host primary network interface. Hence the reason /etc/hosts is ignored.
Post Reply