Give guest a specific DNS server over DHCP

This is for discussing general topics about how to use VirtualBox.
Post Reply
Optaget
Posts: 3
Joined: 4. May 2022, 17:26

Give guest a specific DNS server over DHCP

Post by Optaget »

Hi!

The DNS server of my host cannot be reached by the guest. Instead I want VirtualBox to tell the guest over DHCP that it should use the DNS server 8.8.8.8.

How do I do that?

With the default network type "NAT" it does not seem to be possible to setup the DHCP server in any way.

I managed to setup a DHCP server using the network type "NAT-Network" using commands like:
VBoxManage natnetwork add --netname MYNET --network "10.20.14.0/24" --enable
VBoxManage dhcpserver add --netname MYNET --ip 10.20.14.3 --netmask 255.255.255.0 --lowerip 10.20.14.200 --upperip 10.20.14.250 --enable
VBoxManage dhcpserver modify --netname MYNET --set-opt 6 8.8.8.8
VBoxManage modifyvm MYVM --nic1 natnetwork --nat-network1 MYNET
After this "VBoxManage list dhcpservers" gives something like:
NetworkName:    MYNET
Dhcpd IP:       10.20.14.3
LowerIPAddress: 10.20.14.200
UpperIPAddress: 10.20.14.250
NetworkMask:    255.255.255.0
Enabled:        Yes
Global Configuration:
    minLeaseTime:     default
    defaultLeaseTime: default
    maxLeaseTime:     default
    Forced options:   None
    Suppressed opts.: None
        1/legacy: 255.255.255.0
        6/legacy: 8.8.8.8
Groups:               None
Individual Configs:   None
But when I start the VM VirtualBox seems to override the DNS server to what the host has configured! And after this, "VBoxManage list dhcpservers" gives something like:
NetworkName:    MYNET
Dhcpd IP:       10.20.14.3
LowerIPAddress: 10.20.14.200
UpperIPAddress: 10.20.14.250
NetworkMask:    255.255.255.0
Enabled:        Yes
Global Configuration:
    minLeaseTime:     default
    defaultLeaseTime: default
    maxLeaseTime:     default
    Forced options:   None
    Suppressed opts.: None
        1/legacy: 255.255.255.0
        3/legacy: 10.20.14.1
        6/legacy: 127.0.0.2
       15/legacy: my.domain.com
Groups:               None
Individual Configs:   None
Where 127.0.0.2 is the DNS server configured on the host.

I use both Windows guest and Windows host.
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Give guest a specific DNS server over DHCP

Post by fth0 »

I don't know why it happens that way, but have the following ideas:

1. Please provide a zip file with the contents of C:\Users\<username>\.VirtualBox, where the VirtualBox global network configuration and log files are located.

2. For possibly alternative strategies, take a look at 9.8.5. Enabling DNS Proxy in NAT Mode and 9.8.6. Using the Host's Resolver as a DNS Proxy in NAT Mode.
Optaget
Posts: 3
Joined: 4. May 2022, 17:26

Re: Give guest a specific DNS server over DHCP

Post by Optaget »

Thanks for the reply!

I have attached the content of the folder (slightly modified for privacy reasons) both before and after the VM is started.

The DNS severs of the host are 192.168.1.254 and 100.64.0.1.

I am aware of the other DNS options you mention. Unfortunately they do not work for me due to a wired DNS setup I have and due to https://www.virtualbox.org/ticket/20977
Attachments
logs.zip
(29.07 KiB) Downloaded 3 times
fth0
Volunteer
Posts: 5668
Joined: 14. Feb 2019, 03:06
Primary OS: Mac OS X other
VBox Version: PUEL
Guest OSses: Linux, Windows 10, ...
Location: Germany

Re: Give guest a specific DNS server over DHCP

Post by fth0 »

The log files confirm what you've already discovered, and AFAIU the VirtualBox source code, you cannot override the DNS server address(es) using "--set-opt 6".
Post Reply