Skip to content

WSL generates wrong /etc/hosts file when host system is not part of domain #12275

@jonasPoehler

Description

@jonasPoehler

Windows Version

Microsoft Windows [Version 10.0.22631.4460]

WSL Version

2.3.26.0

Are you using WSL 1 or WSL 2?

  • WSL 2
  • WSL 1

Kernel Version

5.15.167.4-1

Distro Version

Ubuntu 24.04

Other Software

No response

Repro Steps

I have a Windows device with the following local hostname (FQDN)

PS C:> [System.Net.Dns]::GetHostByName($env:computerName).HostName
DESKTOP-30N6MHG

Install a Ubuntu 24.04 (maybe even other distros) via wsl --import.

Expected Behavior

The /etc/hosts/ file should contain only one entry for the host, meaning the "regular" hostname:

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1       localhost
127.0.1.1       DESKTOP-30N6MHG
 
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Actual Behavior

When I install a new WSL-Ubuntu-Distro via wsl --import and then start the system, the /etc/hosts/ (generated by WSL) file looks like this:

# This file was automatically generated by WSL. To stop automatic generation of this file, add the following entry to /etc/wsl.conf:
# [network]
# generateHosts = false
127.0.0.1       localhost
127.0.1.1       DESKTOP-30N6MHG.        DESKTOP-30N6MHG
 
# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

As you can see, the entry with the hostname contains two entries: DESKTOP-30N6MHG. (yes, with a trailing dot) and DESKTOP-30N6MHG. This results in the FQDN inside WSL to be DESKTOP-30N6MHG., which some software (e.g. Postfix) cannot handle. Additionally according to the manpage of hosts, hostnames have to end in an alphanumeric character, which is probably why software cannot handle this behaviour.

Diagnostic Logs

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions