NatNetwork's DHCP engine doesn't read/get host's DNS settings to pass them to the guest.

Discussions related to using VirtualBox on Mac OS X hosts.
Post Reply
Farhad
Posts: 2
Joined: 6. Jun 2023, 22:05

NatNetwork's DHCP engine doesn't read/get host's DNS settings to pass them to the guest.

Post by Farhad »

When I set the VM to be on the `NatNetwork`, Neither my host DNS list nor my home router's DNS list is provided to the guest via DHCP.

- VirtualBox: 7.0.9 r157689
- Host: macOS Ventura Version 13.4 (22F66)
- Host Network adapter: Ethernet
- Guest: Parrot OS (Debian-based. I have also tested this with Ubuntu, Debian, Fedora, CentOS 7, and Kali Linuxes)

Below is the DHCP configuration after it got created. You can see there's no `6/legacy:` in it.

Code: Select all

❯ VBoxManage list dhcpservers
NetworkName:    NatNetwork
Dhcpd IP:       10.0.2.3
LowerIPAddress: 10.0.2.4
UpperIPAddress: 10.0.2.254
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.0.2.1
Groups:               None
Individual Configs:   None
Below is what I get in the guest OS and the content of the `/etc/resolv.conf` is empty.

Code: Select all

$nslookup [a website. It turned out I can’t pos url links that are external to this domain.]
;; communications error to ::1#53: connection refused
;; communications error to ::1#53: connection refused
;; communications error to ::1#53: connection refused
;; communications error to 127.0.0.1#53: connection refused
;; no servers could be reached
I can ping IP addresses though like below.

Code: Select all

$ping 1.1.1.1
PING 1.1.1.1 (1.1.1.1) 56(84) bytes of data.
64 bytes from 1.1.1.1: icmp_seq=1 ttl=56 time=3.15 ms
64 bytes from 1.1.1.1: icmp_seq=2 ttl=56 time=3.16 ms
This is the result guest OS requesting DHCP in which there's no DNS settings:

Code: Select all

$sudo nmap --script broadcast-dhcp-discover
Pre-scan script results:
| broadcast-dhcp-discover: 
|   Response 1 of 1: 
|     Interface: enp0s3
|     IP Offered: 10.0.2.10
|     Server Identifier: 10.0.2.3
|     DHCP Message Type: DHCPOFFER
|     Subnet Mask: 255.255.255.0
|     Router: 10.0.2.1
|_    IP Address Lease Time: 10m00s
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 10.38 seconds
When I modify the DHCP on the host via `VBoxManage dhcpserver modify --network NatNetwork --set-opt 6 1.1.1.1,8.8.8.8` and restarting it via `vboxmanage dhcpserver restart --netname NatNetwork`, then the DNS settings will show up in its configuratio, DHCP engine passes the values to the guest, and works as expected. Here are the results:

Code: Select all

❯ VBoxManage list dhcpservers
NetworkName:    NatNetwork
Dhcpd IP:       10.0.2.3
LowerIPAddress: 10.0.2.4
UpperIPAddress: 10.0.2.254
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.0.2.1
        6/legacy: 1.1.1.1,8.8.8.8
Groups:               None
Individual Configs:   None

Code: Select all

$cat /etc/resolv.conf 
# Generated by NetworkManager
nameserver 1.1.1.1
nameserver 8.8.8.8

Code: Select all

$sudo nmap --script broadcast-dhcp-discover
Pre-scan script results:
| broadcast-dhcp-discover: 
|   Response 1 of 1: 
|     Interface: enp0s3
|     IP Offered: 10.0.2.10
|     Server Identifier: 10.0.2.3
|     DHCP Message Type: DHCPOFFER
|     Subnet Mask: 255.255.255.0
|     Router: 10.0.2.1
|     Domain Name Server: 1.1.1.1, 8.8.8.8
|_    IP Address Lease Time: 10m00s
WARNING: No targets were specified, so 0 hosts scanned.
Nmap done: 0 IP addresses (0 hosts up) scanned in 10.34 seconds
Also, in the Bridged mode, the guest receives all the DNS list I have registered on my home router.

I have attached my VM logs for both cases (DHCP with `--set-opt` and without it) to this post.

I have also created this ticket #21714.

Thank you for your attention to this matter.
Attachments
VM-logs.zip
(92.44 KiB) Downloaded 273 times
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: NatNetwork's DHCP engine doesn't read/get host's DNS settings to pass them to the guest.

Post by scottgus1 »

Farhad wrote: 6. Jun 2023, 23:40 When I set the VM to be on the `NatNetwork`, Neither my host DNS list nor my home router's DNS list is provided to the guest via DHCP.
Looks like you figured out a way to get this to work? I haven't dug into DNS vs NAT & NAT Network, but I remember there's something about it here: https://www.virtualbox.org/manual/ch09.html#changenat It may help, or you may be all set.
Farhad wrote: 6. Jun 2023, 23:40 in the Bridged mode, the guest receives all the DNS list I have registered on my home router.
This'll be because Bridged goes around your host's network stack to get a direct connection to the house router.

See Virtualbox Networks: In Pictures
Farhad
Posts: 2
Joined: 6. Jun 2023, 22:05

Re: NatNetwork's DHCP engine doesn't read/get host's DNS settings to pass them to the guest.

Post by Farhad »

Looks like you figured out a way to get this to work?
Maybe; sort of. There are some workarounds I have figured, namely manually editing the `/etc/resolv.conf` file, adding the additional DNS address by editing the connection interface in the guest OS, and the one that is via virtualbox's CLI which I mentioned in my post. Funny thing is that, when I use my computer on my work network at the office, Virtualbox does set the DNS. However, it's still not what I have set it on my host, it gets the gateway's IP address as the DNS server which at the end it works but still it's not what I have set it on the my host machine.
I haven't dug into DNS vs NAT & NAT Network, but I remember there's something about it here: `manual/ch09.html#changenat` It may help, or you may be all set.
To be honest I couldn't figure out which part of the manual you referring to. Would you please tell me which section you mean?
scottgus1
Site Moderator
Posts: 20945
Joined: 30. Dec 2009, 20:14
Primary OS: MS Windows 10
VBox Version: PUEL
Guest OSses: Windows, Linux

Re: NatNetwork's DHCP engine doesn't read/get host's DNS settings to pass them to the guest.

Post by scottgus1 »

Farhad wrote: 7. Jun 2023, 00:53 Would you please tell me which section you mean?
It's a link that opens to the manual section on fine-tuning NAT. Most of it is over my head. :D
caramba
Posts: 20
Joined: 9. Jan 2014, 20:58

Re: NatNetwork's DHCP engine doesn't read/get host's DNS settings to pass them to the guest.

Post by caramba »

On my Windows 11 host in VB 7.0.12 I had linux guest NAT adaptor DNS resolution problems that "suddenly" started happening.

ping 8.8.8.8 worked
nslookup www.google.com failed (as did all other DNS lookups)

To resolve the problem i did the following:

1. shut down the linux guest VM "PROBLEM VM" completely
2. waited for a bit
3. on Windows host opened a command window and entered
- cd ""C:\program files\oracle\virtualbox"
- vboxmanage modifyvm "PROBLEM VM" --nat-dns-host-resolver1=off
- vboxmanage modifyvm "PROBLEM VM" --nat-dns-host-resolver1=on

Started PROBLEM VM via VB as normal

Now nslookup www.google.com works
Post Reply