none
IPAdressInformation sample question RRS feed

  • Question

  • Hi,

    I've just installed net core 2.0.0 on my debian based linux distro.

    I was experimenting with System.Net samples and little poc's. And gathering nci information I got unexpected results:

    https://msdn.microsoft.com/es-es/library/system.net.networkinformation.ipaddressinformation(v=vs.110).aspx

    I've two wireless NCI, wlan0 and wlan1.

    Each of both are connected to different routers.

    Here some system info raw output:

    <<

    shaiker@s2ph:~/develop/net$ dotnet --version
    2.0.0

    shaiker@s2ph:~/develop/net$ sudo ifconfig wlan1
    wlan1: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 10.100.123.203  netmask 255.252.0.0  broadcast 10.103.255.255
            inet6 fe80::275e:8b24:4525:6b12  prefixlen 64  scopeid 0x20<link>
            ether 00:c0:ca:82:85:66  txqueuelen 1000  (Ethernet)
            RX packets 94  bytes 6310 (6.1 KiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 30  bytes 2964 (2.8 KiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    shaiker@s2ph:~/develop/net$ sudo ifconfig wlan0
    wlan0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
            inet 192.168.1.106  netmask 255.255.255.0  broadcast 192.168.1.255
            inet6 fe80::a6db:30ff:fe96:1f23  prefixlen 64  scopeid 0x20<link>
            ether a4:db:30:96:1f:23  txqueuelen 1000  (Ethernet)
            RX packets 96134  bytes 113701402 (108.4 MiB)
            RX errors 0  dropped 0  overruns 0  frame 0
            TX packets 57004  bytes 6760071 (6.4 MiB)
            TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

    shaiker@s2ph:~/develop/net$ sudo route -n
    Kernel IP routing table
    Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
    0.0.0.0         192.168.1.1     0.0.0.0         UG    600    0        0 wlan0
    0.0.0.0         10.100.0.1      0.0.0.0         UG    601    0        0 wlan1
    10.100.0.0      0.0.0.0         255.252.0.0     U     600    0        0 wlan1
    192.168.1.0     0.0.0.0         255.255.255.0   U     600    0        0 wlan0

    >>

    Then I've used vs code (with proper extensions) to run the sample:

    publicstaticvoid DisplayDnsAddresses() { NetworkInterface[] adapters = NetworkInterface.GetAllNetworkInterfaces(); foreach (NetworkInterface adapter in adapters) { IPInterfaceProperties adapterProperties = adapter.GetIPProperties(); IPAddressCollection dnsServers = adapterProperties.DnsAddresses; if (dnsServers.Count > 0) { Console.WriteLine(adapter.Description); foreach (IPAddress dns in dnsServers) { Console.WriteLine(" DNS Servers ............................. : {0}", dns.ToString()); } Console.WriteLine(); } } }

    And I got an unexpected output, in my opinion:

    <<

    lo
      DNS Servers ............................. : 192.168.1.1
      DNS Servers ............................. : XX.XX.XX.XX
      DNS Servers ............................. : YY.YY.YY.YY
    eth0
      DNS Servers ............................. : 192.168.1.1
      DNS Servers ............................. : XX.XX.XX.XX
      DNS Servers ............................. : YY.YY.YY.YY
    wlan0
      DNS Servers ............................. : 192.168.1.1
      DNS Servers ............................. : XX.XX.XX.XX
      DNS Servers ............................. : YY.YY.YY.YY
    wlan1
      DNS Servers ............................. : 192.168.1.1
      DNS Servers ............................. : XX.XX.XX.XX
      DNS Servers ............................. : YY.YY.YY.YY

    >>

    (XX.XX.XX.XX and YY.YY.YY.YY display correctly my dns1 and dns2 according my wlan0 config)

    It seems to me the output is not correct.

    What I'm missing?

    Regards,


    • Edited by Dani LH Tuesday, August 15, 2017 9:42 PM privacy
    Tuesday, August 15, 2017 9:16 AM

Answers

  • The result does look correct to me as the DNS preference for any NIC on the same machine should not be different.

    Since the DNS resolution does not care what interface the DNS server is on, you can consider them mixed for all network interface. (And follow the same resolution sequence of "hosts file" -> local DNS cache -> first replying DNS server response)


    • Edited by cheong00Editor Wednesday, August 16, 2017 1:44 AM
    • Marked as answer by Dani LH Wednesday, August 16, 2017 8:54 AM
    Wednesday, August 16, 2017 1:44 AM
    Answerer

All replies

  • The result does look correct to me as the DNS preference for any NIC on the same machine should not be different.

    Since the DNS resolution does not care what interface the DNS server is on, you can consider them mixed for all network interface. (And follow the same resolution sequence of "hosts file" -> local DNS cache -> first replying DNS server response)


    • Edited by cheong00Editor Wednesday, August 16, 2017 1:44 AM
    • Marked as answer by Dani LH Wednesday, August 16, 2017 8:54 AM
    Wednesday, August 16, 2017 1:44 AM
    Answerer
  • Hi Cheong00,

    Thanks for your response and good explanation.

    Some time ago, I did apply in my system a solution described here (well, more or less, I had to change couple of  things according my system details):

     - Define a solution to route some traffic to wlan0 and wlan1 selectively, I've followed the threat here:
        https://serverfault.com/questions/423882/configure-a-dns-server-per-nic-interface-eth0-eth1

    Seem to work correctly. I effectively use wlan0 and wlan1 as expected.

    Then, later on time, (now) I've begin to use net.core in linux, just for fun, and while exploring this class I got a bit surprised by the output, I was expecting to see at least on wlan1 different values. And this  was my bad assumption. As I understand a bit better the dns sequence you've briefly described me on your response.
    :-)


    • Edited by Dani LH Wednesday, August 16, 2017 8:58 AM concise
    Wednesday, August 16, 2017 8:54 AM