I have set up LAMP stacks on both Ubuntu 20.04 and Debian 10 running Apache 2.4.

The VirtualHost Files are identical as follows :

<VirtualHost localhost:80>

    ServerAdmin webmaster@localhost
    ServerName subdomain.localhost
    ServerAlias www.subdomain.localhost
    DocumentRoot /var/www/localhost/subdomain

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined


I have dissabled the default site and enabled the localhost site on both machines.

On Ubuntu i can just visit subdomain.localhost (and www.subdomain.locahost) via my browser. On Debian, however, I have to add an entry to the /etc/hosts file for every subdomain I'd like to create/use.

  1. Why is that? Whats the difference between Debain and Ubuntu that causes that?

  2. Am I able to configure Debian in a way so that I do not need to add an entry for every subdomain for localhost?

1 Answer 1


Ubuntu is running the service systemd-resolved that maps localhost subdomains to your local IP address.

If you query the DNS using dig you will see that it gets the local IP address ( from a SERVER running on a localhost IP address (

$ dig www.subdomain.localhost
www.subdomain.localhost. 0  IN  A

The configuration file that sets up the DNS servers to use (resolv.conf) specifies to use this local DNS server:

$ cat /etc/resolv.conf 
# is the systemd-resolved stub resolver.
# run "systemd-resolve --status" to see details about the actual nameservers.

You can verify that the systemd-resolved service is running with

$ sudo service systemd-resolved status
● systemd-resolved.service - Network Name Resolution
     Loaded: loaded (/lib/systemd/system/systemd-resolved.service; enabled; vendor preset: enabled)
     Active: active (running) ...

This service is available on Debian: https://manpages.debian.org/stretch/systemd/systemd-resolved.service.8.en.html but it is not enabled by default. You should be able to start the service on Debian by following the instructions from this Server Fault question: Is that possible for debian users to connect to network through systemd-networkd?

  • Thank you for your detailed answer. Whilest configuring Debian i had to add my localhost IP to the resolv.conf file to makle it work and i had to leave the default IP in there, without the default one i could not connect to the internet. It kinda feels like a dirty hack.? Before : # Generated by NetworkManager nameserver 192.***.**.* After : # Generated by NetworkManager nameserver nameserver 192.***.**.* (The stars (*) are for privacy reasons)
    – McRaef
    Commented Mar 29, 2021 at 19:01
  • My instructions for enabling systemd-resolved were optimistically incomplete. It looks like you can follow the instructions at Is that possible for debian users to connect to network through systemd-networkd? for a more complete setup. Commented Mar 29, 2021 at 19:09
  • Thanks again, may good things happen to you.
    – McRaef
    Commented Mar 29, 2021 at 19:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.