Skip to content

System.Net.Dns.GetHostAddresses() does not return all local ip addresses on Linux/.NET Core (it works in .NET Framework) #27534

Closed
dotnet/corefx
#41764

Description

A call to

System.Net.Dns.GetHostAddresses(System.Net.Dns.GetHostName())

returns only the first local IP address when running on Linux.

Tested with .NET Core 2.1.3

Here is the repro code:

using System;
using System.Net;
using System.IO;

namespace ConsoleDnsTest
{
    class Program
    {
        static void Main(string[] args)
        {
            string hostname = Dns.GetHostName();
            Console.WriteLine("My hostname is '{0}'", hostname);
            Console.WriteLine("My ip addresses are:");
            foreach (var address in Dns.GetHostAddresses(hostname))
                Console.WriteLine("\t{0}", address);
        }
    }
}

Here is the (wrong) output I get on my Linux Debian 9:

root@inim-test:~# dotnet ConsoleDnsTest.dll
My hostname is 'inim-test'
My ip addresses are:
	172.22.28.132
root@inim-test:~#

If I run the very same code under Mono, it works, and this is the correct output I get:

root@inim-test:~# mono ConsoleDnsTest.exe
My hostname is 'inim-test'
My ip addresses are:
	172.22.28.132
	172.22.28.133
	172.22.28.134
	172.22.28.138
	10.128.0.1
root@inim-test:~#

On Windows both .NET Core and .NET Framework versions work well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

area-System.Netbughelp wanted[up-for-grabs] Good issue for external contributorsos-linuxLinux OS (any supported distro)

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions