VirtualBox

Ticket #10555 (new defect)

Opened 2 years ago

Last modified 2 years ago

NAT DnsHostResolver reverse order of dns results compared to host

Reported by: ceztko Owned by:
Priority: minor Component: network/NAT
Version: VirtualBox 4.1.14 Keywords: nat dnshostresolver dns
Cc: Guest type: Linux
Host type: Windows

Description

Because the host often needs to connect to a VPN with a local dns server, I enabled NAT DnsHostResolver (NAT DnsProxy wasn't enough) with the command:

VBoxManage.exe modifyvm <vmname> --natdnshostresolver1 on

It seemed to work correctly but I observed that DNS results order is reversed in a specific query I'm doing. Please note that the local dns server (192.168.101.20) is configured to answer in a specific order for this query (there's absolutely no round-robin, the result is always fixed). Host is Windows7 64-bit, guest is ubuntu 12.04 64 bit.

ping + nslookup in the host (correct, sidenote: dns server 192.168.101.20 is configured to serve to vpn users the public ip first for this specific host, and not the lan ip):

C:\Users\ceztko>ping hypervisor.rur.it-robotics.it

Pinging hypervisor.rur.it-robotics.it [95.240.170.248] with 32 bytes of data:
Control-C
^C
C:\Users\ceztko>nslookup
Default Server:  lanmaster.it-robotics.it
Address:  192.168.101.20

> hypervisor.rur.it-robotics.it
Server:  lanmaster.it-robotics.it
Address:  192.168.101.20

Name:    hypervisor.rur.it-robotics.it
Addresses:  95.240.170.248
          192.168.101.10

ping + nslookup in the guest (wrong, reversed):

ceztko@laptopbb:~$ ping hypervisor.rur.it-robotics.it
PING hypervisor.rur.it-robotics.it (192.168.101.10) 56(84) bytes of data.
^C64 bytes from 192.168.101.10: icmp_req=1 ttl=63 time=70.1 ms

--- hypervisor.rur.it-robotics.it ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 0ms
rtt min/avg/max/mdev = 70.124/70.124/70.124/0.000 ms
ceztko@laptopbb:~$ nslookup
> hypervisor.rur.it-robotics.it
Server:		10.0.2.3
Address:	10.0.2.3#53

Name:	hypervisor.rur.it-robotics.it
Address: 192.168.101.10
Name:	hypervisor.rur.it-robotics.it
Address: 95.240.170.248

Because, as stated in the manual, "the resolver mode will interpret the DNS requests and use the host's DNS API to query the information and return it to the guest", I'm expecting the guest to see the same order of the host for this query.

Attachments

gethostname.cpp Download (1.6 KB) - added by ceztko 2 years ago.
Test program for gethostname() in Windows
getaddrinfo.cpp Download (2.1 KB) - added by ceztko 2 years ago.
Test program for getaddrinfo() in Windows

Change History

Changed 2 years ago by ceztko

Test program for gethostname() in Windows

comment:1 Changed 2 years ago by ceztko

I found that the actual Dns Host Resolver, as found in src\VBox\Devices\Network\slirp\libalias\alias_dns.c, use gethostname() to resolve addresses in the host. I tested gethostname() with a quick c program in Windows7 and in fact I get different results from using, for example, ping or testing the dns server with nslookup. The self-compiling c program is attached (gethostname.cpp).

These are the results testing the gethostname() test program versus a ping:

C:\Users\ceztko\Desktop\gethostname\Debug>gethostname hypervisor.rur.it-robotics.it
Hostname: hypervisor.rur.it-robotics.it
IP Address: 192.168.101.10

C:\Users\ceztko\Desktop\gethostname\Debug>ping hypervisor.rur.it-robotics.it

Pinging hypervisor.rur.it-robotics.it [95.240.170.248] with 32 bytes of data:
Control-C

As of Microsoft documentation "the gethostbyname function has been deprecated by the introduction of the getaddrinfo function. Developers creating Windows Sockets 2 applications are urged to use the getaddrinfo function instead of gethostbyname.". I'll compose soon a similar test program with getaddrinfo().

comment:2 Changed 2 years ago by Hachiman

Thank you for reporting and investigation.

Changed 2 years ago by ceztko

Test program for getaddrinfo() in Windows

comment:3 Changed 2 years ago by ceztko

Ok, attached the test program for getaddrinfo(). As for the gethostname() previous one, it returns just the first entry (because it will the one actually used by client programs).

Resolution tests gethostname() vs getaddrinfo() vs ping

C:\Users\ceztko\Desktop\gethostname\Debug>gethostname.exe hypervisor.rur.it-roboti
cs.it
Hostname: hypervisor.rur.it-robotics.it
IP Address: 192.168.101.10

C:\Users\ceztko\Desktop\gethostname\Debug>getaddrinfo.exe hypervisor.rur.it-roboti
cs.it
Hostname: hypervisor.rur.it-robotics.it
IP Address: 95.240.170.248

C:\Users\ceztko\Desktop\gethostname\Debug>ping hypervisor.rur.it-robotics.it

Pinging rur.it-robotics.it [95.240.170.248] with 32 bytes of data:
Control-C

getaddrinfo() and ping are returning me the order of results I'm actually expecting. gethostname() is, at least in Windows 7 64 bit host, producing a wrong order or results. The obvious fix for me would be to migrate the deprecated gethostname() alias_dns.c to getaddrinfo(), possibly supporting correctly ipv6 addresses.

Note: See TracTickets for help on using tickets.

www.oracle.com
ContactPrivacy policyTerms of Use