0

I recently discovered lando for local web development, which uses docker in the background. It works great so far, but I have to add every domain for each project manually to my hosts file

/etc/hosts:

127.0.0.1   myproject.local.host
127.0.0.1   bs.myproject.local.host
127.0.0.1   bs-admin.myproject.local.host

(the bs. and bs-admin. ones are for browsersync)

According to the lando docs, it is possible to have a wildcard domain instead of hard coding every domain. Unfortunately are those instructions for MacOS and I am on Arch Linux (Manjaro Gnome 41.3).
I tried to figure it out myself with the help of the page Arch Wiki: Dnsmasq and other online resources but I couldn't get it to work.

This is what I currently have:

  • installed Dnsmasq sudo pacman -S dnsmasq
  • added these lines to the /etc/dnsmasq.conf file (everything else in the file was/is commented out):
    listen-address=::1,127.0.0.1
    expand-hosts
    domain=local.host
    
  • restart local server sudo systemctl restart httpd and sudo systemctl restart dnsmasq
  • added this line to ~/.lando/config.yml
    domain: local.host
    
  • restart lando lando poweroff and lando start

However, it does not work:

❯ ping http://myproject.local.host:8000/          
ping: http://myproject.local.host:8000/: Name or service not known
❯ ping http://myproject.local.host      
ping: http://myproject.local.host: Name or service not known
❯ ping https://myproject.local.host      
ping: https://myproject.local.host: Name or service not known

Adding these lines to /etc/resolv.conf didn't help either:

nameserver 127.0.0.1

Update:

I'm still very confused how dnsmasq.conf (dnsmasq.d), etc/hosts, etc/resolv.conf and /etc/systemd/resolved.conf interact with each other. But after more reading and trial&error, this is were I am currently:

  • added this line to/etc/dnsmasq.conf :
    address=/local.host/127.0.0.1
    
  • no added lines to /etc/hosts These lines were in there from StevenBlack/hosts
    127.0.0.1 localhost
    127.0.0.1 localhost.localdomain
    127.0.0.1 local
    255.255.255.255 broadcasthost
    ::1 localhost
    ::1 ip6-localhost
    ::1 ip6-loopback
    fe80::1%lo0 localhost
    ff00::0 ip6-localnet
    ff00::0 ip6-mcastprefix
    ff02::1 ip6-allnodes
    ff02::2 ip6-allrouters
    ff02::3 ip6-allhosts
    0.0.0.0 0.0.0.0
    
  • added this line to /etc/resolv.conf :
    nameserver 127.0.0.1
    
  • ran sudo systemctl restart NetworkManager and sudo systemctl restart dnsmasq
  • added this line to ~/.lando/config.yml
    domain: local.host
    
  • ran lando poweroff and lando start

When I test it, I get this:

❯ nslookup foo.local.host localhost    
Server:     localhost
Address:    ::1#53

Name:   foo.local.host
Address: 127.0.0.1
❯ nslookup foo.local.test          
Server:     192.168.2.1
Address:    192.168.2.1#53

** server can't find foo.local.test: NXDOMAIN
❯ ping foo.local.host       
ping: foo.local.host: Name or service not known

lando start shows the top two urls in green and the bottom two in red:

APPSERVER URLS  https://localhost:49291                      
                http://localhost:49292                       
                http://myproject.local.host:8000/          
                https://myproject.local.host/    
3
  • You are missing the most important entry in dnsmasq.conf, the one from the guide. Is that intentional?
    – Daniel B
    Commented Apr 27, 2022 at 9:26
  • address=/local.host/127.0.0.1? I tried that before, but that did not work. I assumed the lines I have in the post you do something similar
    – jost21
    Commented Apr 27, 2022 at 11:39
  • What setting is missing/wrong that nslookup foo.local.host localhost works, but nslookup foo.local.host not?
    – jost21
    Commented Apr 27, 2022 at 12:58

2 Answers 2

0

The nslookup tool is a simple case: it always reads /etc/resolv.conf and directly talks to whatever DNS server is found in that file. However, if you have multiple nameserver lines in that file, it'll only use one of them, usually the first one.

It's important to keep in mind that additional nameservers in resolv.conf are not "merged". They're only used as fallbacks if the first nameserver is completely unreachable. But if the first server does answer "I don't know foo.local.test", that's the final result – neither nslookup nor any other program will keep trying other servers in case one of them knows the name.

If your resolv.conf lists the special dnsmasq instance, it should not also list your router, or any other DNS server – all your DNS queries should go through dnsmasq (which will forward them to the "real" server if needed).

Systemd-resolved is a separate topic. When it's active, most programs (except for dig/nslookup) will talk to it directly, bypassing the traditional /etc/resolv.conf mechanism. Systemd-resolved itself has two modes: either it reads resolv.conf, or it provides resolv.conf.

So if you're using e.g. systemd-resolved and NetworkManager, you should usually change your DNS servers via NetworkManager (connection profile) first, which will then propagate them to systemd-resolved. But if you want to edit resolv.conf manually, first use ls -l to make sure it's not a symlink to one of systemd-resolved managed files. If needed, remove it and replace with a regular file.


Also, these are the only useful lines from your /etc/hosts:

127.0.0.1 localhost
::1 localhost

The rest is entirely useless, even if it happens to come from Debian.

2
  • Sorry, it took my a while to write my answer and then saw your post only after I posted it. Thank you for the clarification, but I do not understand how I should change DNS servers via NetworkManager (connection profile)
    – jost21
    Commented Apr 27, 2022 at 14:24
  • The hosts file stuff comes from github.com/StevenBlack/hosts/blob/master/updateHostsFile.py (line 1181). I assumed it's there for a reason, so I left it
    – jost21
    Commented Apr 27, 2022 at 14:25
0

After lots of trial and error and reading online resources, I found a version that seems to work.

Disclaimer: I highly doubt that this is the correct way to do it and there are probably better ways. I also don't know whether all those steps are necessary or what kind of negative implications my settings will have on my system, that I haven't noticed yet.

Issues before

  • NetworkManager was overwriting /etc/resolv.conf, so whatever changes I made, where reverted by running sudo systemctl restart NetworkManager Arch Wiki:NetworkManager
  • Missing certs in firefox Lando Docs

Working version

  1. add this line to/etc/dnsmasq.conf :
    address=/local.host/127.0.0.1
    
  2. leave /etc/hosts as is
  3. create file /etc/NetworkManager/conf.d/dns.conf with content:
    [main]
    dns=none
    
  4. add nameserver 127.0.0.1 at the top of /etc/resolv.conf, that looks like this for me:
    nameserver 127.0.0.1
    nameserver 192.168.2.1
    nameserver fe80::1%enp0s20u2u4
    
  5. run
    systemctl restart dnsmasq
    systemctl restart NetworkManager
    
  6. add this line to ~/.lando/config.yml
    domain: local.host
    
  7. run
    lando poweroff
    lando rebuild -y
    
  8. run
    sudo trust anchor ~/.lando/certs/local.host.pem
    sudo trust anchor ~/.lando/certs/local.host.crt
    

Update

This solution is not persistent, the content of /etc/resolv.conf gets overwritten by the NetworkManager, e.g. after restarting It also causes problems with wifi connections for me.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .