2

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

</VirtualHost>

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

3

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 (127.0.0.1) from a SERVER running on a localhost IP address (127.0.0.53):

$ dig www.subdomain.localhost
...
www.subdomain.localhost. 0  IN  A   127.0.0.1
...
;; SERVER: 127.0.0.53#53(127.0.0.53)

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

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

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?

3
  • 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 127.0.0.53 nameserver 192.***.**.* (The stars (*) are for privacy reasons) 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. Commented Mar 29, 2021 at 19:18

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.