Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Networking & Security
  • Search

[SOLVED]systemd-networkd - local hostnames are not resolving

Having problems getting connected to the internet or running a server? Wondering about securing your box? Ask here.
Post Reply
Advanced search
13 posts • Page 1 of 1
Author
Message
o5gmmob8
l33t
l33t
Posts: 737
Joined: Fri Oct 17, 2003 9:17 pm

[SOLVED]systemd-networkd - local hostnames are not resolving

  • Quote

Post by o5gmmob8 » Fri Jan 23, 2026 2:06 pm

I am unable to figure out why my local names are not resolving on my systemd box. On an OpenRC system, they resolve fine - I removed all entries in /etc/hosts and they're still able to resolve.

I am running dnsmasq locally and want to use short names such as router, gateway, workstation, laptop, etc. to refer to a device.

My SystemD machine has 2 network configuration files to prioritize wired connectivity over wifi, but otherwise, it is stock:

Code: Select all

[Match]
Name=wlan0

[Network]
DHCP=yes
IgnoreCarrierLoss=3s

[DHCP]
RouteMetric=2048
When I run tcpdump -i any 'udp port 53', what I see is that only requests for FQDN or external domains are going to my upstream DNS server (provided by DHCP), but my local ones only go to SystemD where it seems to be a blackhole.

I tried adding:

Code: Select all

[DHCPv4]
UseNTP=Yes
UseDNS=Yes
and

Code: Select all

UseDomains=DHCPv4
under [Network]

but, nothing changed.
Last edited by o5gmmob8 on Thu Feb 26, 2026 1:25 am, edited 1 time in total.
Top
rab0171610
l33t
l33t
Posts: 721
Joined: Sat Dec 24, 2022 1:41 am

  • Quote

Post by rab0171610 » Fri Jan 23, 2026 5:06 pm

I don't use systemd-networkd. I use NetworkManager. It doesn't sound like a problem with the systemd-networkd configuration. I would check the resolver or the systemd-resolved configuration.
Top
o5gmmob8
l33t
l33t
Posts: 737
Joined: Fri Oct 17, 2003 9:17 pm

  • Quote

Post by o5gmmob8 » Fri Jan 23, 2026 6:29 pm

Hmm.

So, without

Code: Select all

[Network]
DHCP=yes
It was seemingly using Cloudflare and Google DNS which is good in most cases, but not what I want at home. With it added, it then respects my DHCP option and uses my local DNS, but it doesn't appear to send queries to the upstream DNS server if the query is not qualified.
Top
pingtoo
Advocate
Advocate
User avatar
Posts: 2184
Joined: Fri Sep 10, 2021 8:37 pm
Location: Richmond Hill, Canada

  • Quote

Post by pingtoo » Fri Jan 23, 2026 6:54 pm

o5gmmob8,

depend on your desire on the name resolution processes, there could be multiple conditions that influence the outcome.

systemd-networkd usually work together with systemd-resolved. but systemd-networkd and systemd-resolved are two different services it is possible disable systemd-resolved and use something else as resolver. For example system in its bare bone configuration use libc's implementation.

I suggest you think about it and look in to this as two separated issues, one is how you like your system's name resolution process. then look into how to configure your system deliver that configuration to meet your name resolution design.
Top
o5gmmob8
l33t
l33t
Posts: 737
Joined: Fri Oct 17, 2003 9:17 pm

  • Quote

Post by o5gmmob8 » Sat Jan 24, 2026 11:13 am

Ok, so I mirrored the configuration on my OpenRC system and it now works, phew.

This is what works:

/etc/resolv.conf

Code: Select all

nameserver $DNS_SERVER_IP
domain $LOCAL_DOMAIN # not actually required
/etc/nsswitch.conf

Code: Select all

hosts: files dns
The critical bit is the change in /etc/nsswitch.conf, without it, it doesn't work.

With that, I want to use my local DNS server when I am at home and when I am anywhere else, then use Cloudflare or Quad9.

How might I achieve that?

I believe the way it *USED* to work was that resolvconf would update /etc/resolv.conf with the DNS servers provided by DHCP.

EDIT:
I reverted my /etc/resolv.conf changes back to vanilla SystemD + domain $LOCAL_DOMAIN. Then, in

/etc/systemd/resolved.conf:

Code: Select all

[Resolve]
DNS=1.1.1.1 9.9.9.9
Domains=~.
Then, in /etc/systemd/network/10-home.network:

Code: Select all

[Match]
# Use your home interface name or SSID
Name=enp3s0 

[Network]
DHCP=yes
DNS=192.168.1.50  # Your local DNS server IP
Domains=home.arpa  # Your local search domain

[DHCPv4]
# This ensures DHCP doesn't overwrite your manual DNS settings
UseDNS=no
This works, but only if I add the "domain" entry in /etc/resolv.conf.
Top
pingtoo
Advocate
Advocate
User avatar
Posts: 2184
Joined: Fri Sep 10, 2021 8:37 pm
Location: Richmond Hill, Canada

  • Quote

Post by pingtoo » Sat Jan 24, 2026 3:51 pm

I am not sure what condition you are in right. But if it work for you then it is great.

Usually systemd-resolved and /etc/resolv.conf does not work together in common sense. Usually when systemd-resolved working it will modify /etc/resolv.conf to make it symbolic link to /run/systemd/resolve/stub-resolv.conf which only have one line "nameserver 127.0.0.53" which forward query to systemd-resolved.
Top
rab0171610
l33t
l33t
Posts: 721
Joined: Sat Dec 24, 2022 1:41 am

  • Quote

Post by rab0171610 » Sat Jan 24, 2026 5:13 pm

I do not understand either. Maybe you have an unusual type of network setup. Since you are using systemd, I would recommend reading the Arch Linux wiki pages for systemd-resolved and systemd-networkd to make sure you understand what they are and how they work. Even for Gentoo users, I recommend those just for reading because they are all-encompassing, informative and systemd specific.
https://wiki.archlinux.org/title/Systemd-networkd
https://wiki.archlinux.org/title/Systemd-resolved

I mentioned previously, I did not think your issue was with your systemd-networkd configuration but with systemd-resolved. Systemd-resolved provides network name resolution to the resolve NSS service. The configuration file /etc/nsswitch.conf is directly correlated to the setting up the resolver correctly. As pingtoo pointed out, usually in systemd /etc/resolv.conf is not edited directly but a symlink to /run/systemd/resolve/stub-resolv.conf :
https://wiki.gentoo.org/wiki/Resolv.conf#systemd

While you don't have to explain yourself, you did not give any insight to others as to your rationale and method. If it works for you, that is great. You did not detail any documentation or sources for the configuration changes and decisions you made so I think the word 'caution' should be noted here. I advise other users to read about systemd-resolved and systemd-networkd, do the research before copying or making any of the configuration changes you mentioned. Users should defer to the Gentoo wiki entry for Resolv.conf .
Top
o5gmmob8
l33t
l33t
Posts: 737
Joined: Fri Oct 17, 2003 9:17 pm

  • Quote

Post by o5gmmob8 » Mon Jan 26, 2026 11:52 am

Yes, I am just trying to understand how it should work or how it might actually be working. When I say I am editing /etc/resolv.conf, I meant that I am either removing the symlink and editing a file directly @ /etc/resolv.conf or editing the symlinked file that SystemD provides.

When updating /etc/nsswitch.conf to:

Code: Select all

#hosts:      mymachines resolve [!UNAVAIL=return] files myhostname dns
#hosts:      files resolve [!UNAVAIL=return] dns
hosts:      files dns
I suspect that the lines that I had commented out use an internal resolver that does not resolve hostnames and return a different error code that does not result in a call to dns.

Also, when updating /etc/nsswitch.conf, that only works when I modify /etc/resolv.conf to use my network's DNS server, not the SystemD ResolvD.

I doubt my network is any different from anyone elses, I'm just trying to understand how it should be configured (properly) to achieve the desired effect which is that if I want to resolve a hostname without specifying the domain name, it will resolve. Mainly, this is to save me keystrokes in the terminal.

Code: Select all

ping router
ping workstation
Top
rab0171610
l33t
l33t
Posts: 721
Joined: Sat Dec 24, 2022 1:41 am

  • Quote

Post by rab0171610 » Mon Jan 26, 2026 5:41 pm

o5gmmob8 wrote:Yes, I am just trying to understand how it should work or how it might actually be working. When I say I am editing /etc/resolv.conf, I meant that I am either removing the symlink and editing a file directly @ /etc/resolv.conf or editing the symlinked file that SystemD provides.

When updating /etc/nsswitch.conf to:

Code: Select all

#hosts:      mymachines resolve [!UNAVAIL=return] files myhostname dns
#hosts:      files resolve [!UNAVAIL=return] dns
hosts:      files dns
I suspect that the lines that I had commented out use an internal resolver that does not resolve hostnames and return a different error code that does not result in a call to dns.

Also, when updating /etc/nsswitch.conf, that only works when I modify /etc/resolv.conf to use my network's DNS server, not the SystemD ResolvD.
You do not have to use any resolver or even systemd-resolvd.
I use the DNS addresses of the VPN provider and do not use a resolver either. Since my router is configured to use these static DNS addresses, I let Network Manger handle the entries in resolv.conf. When getting the IP address from the router, the DNS addresses I have set there are relayed to Network Manger which in turn populates the resolv.conf. I only do it this way instead of manually in case I ever edit them on the router, they will update in resolv.conf accordingly.

So, If you have a static IP for an internal DNS server on your local network, then you can manually edit your resolv.conf and avoid the symlink. But now you understand what you are doing and why. And, you have now explained why you are doing it and why it works for you.
Top
o5gmmob8
l33t
l33t
Posts: 737
Joined: Fri Oct 17, 2003 9:17 pm

  • Quote

Post by o5gmmob8 » Wed Feb 25, 2026 10:39 pm

I used to use NetworkManager many moons ago for clients and it was simple, yet powerful - I ran many others too. I had hooks so I could have certain actions performed when on my home network and other actions when on other networks.

Recently, I 'decided' to drink the SystemD Koolaid and am bent on using SystemD for everything. Perhaps I feel like it will be an improvement once I get settled.

So, here I am, I am still banging my head against a wall trying to get my local names resolving. Basically, I want to type a short name like, pawn, to get to my server. I don't want to have to manage those names per device (/etc/hosts).
Top
salahx
Guru
Guru
Posts: 572
Joined: Sat Mar 12, 2005 6:39 am

  • Quote

Post by salahx » Thu Feb 26, 2026 1:19 am

You can do it with systemd-netowrkd and systemd-resolved. I'm assuming your local dnsmasq instance is the DNS server for your network, and that your computer is not a router for your LAN.

First, undo any changes in /etc/nsswitch.conf and /etc/systemd/resolved.conf. Recreate the /etc/resolve.conf symlink

dnsmasq will need to do ALL the DNS resolution for you network. Most routers have a DNS proxy, so if your router is 192,168.1.1, you need to add that as a "server=" in the dnsmaqs config file

Now there may be a problem: Both dnsmaqs and the systemd stub resolver can listen on localhost:53. Either make sure dnsmasq doesn't bind to bind to localhost, OR set "DNSStubListener=no" in /etc/systemd/resolved.conf

Now in /etc/systemd/network/10-home.network, it should look something like this:

Code: Select all

[Match]
Name=enp3s0 

[Network]
DHCP=yes
DNS= # This clears any previous DNS servers
DNS=192.168.1.50  # Your local DNS server IP
Domains=home.arpa  # Your local search domain 
UseDomains=yes

[DHCPv4]
# This ensures DHCP doesn't overwrite your manual DNS settings
UseDNS=no
You may need to restart systemd-networkd and/or use "networkctl reload" after the file is modified

If successful, you should see the search domain in /etc/resolve.conf.

systemd-resolved should pass all DNS trafffic from your machine to dnsmasq which will resolve any local hostnames and pass the rest to you router for resolution.

You can test it with "resolvectl query"

Note the systemd-netwoprkd is great for servers, vms, appliances, and containers I wouldn't recommend it for clients - NetworkManager is a better choice there (you can still use systemd-resolved, though).
Top
o5gmmob8
l33t
l33t
Posts: 737
Joined: Fri Oct 17, 2003 9:17 pm

  • Quote

Post by o5gmmob8 » Thu Feb 26, 2026 1:25 am

Thanks.

I think I sorted out my issue. I think the issue is that simple names like, pawn, rook, etc. were not being passed to the upstream DNS server, but complex names were: ie. google.com, facebook.com.

What I needed to do was:

Code: Select all

#cat /etc/systemd/resolved.conf
[Resolve]
ResolveUnicastSingleLabel=yes
The important bit is ResolveUnicastSingleLabel.

Now, I can type:

Code: Select all

ssh pawn
And, it resolves as I'd expect.

I have managed to get it passing traffic to my upstream DNS server, but the issue was that it didn't handle simple names.

EDIT:
I hear ya on NetworkManager, it is funny how I've tried many different things in the hopes of making life easier ... I used dhclient with hooks, NetworkManager with hooks, netifrc. I'm using systemd-resolved as I recently migrated from OpenRC to SystemD and well ... All in the name of saving a few keystrokes.
Top
flexibeast
l33t
l33t
Posts: 682
Joined: Mon Apr 04, 2022 4:15 am
Location: Naarm/Melbourne, Australia
Contact:
Contact flexibeast
Website

  • Quote

Post by flexibeast » Thu Feb 26, 2026 5:24 am

EDIT: Oh, sorry, hadn't refreshed the page, and so missed your most recent comment. Glad you've solved your issue. :)
o5gmmob8 wrote:So, here I am, I am still banging my head against a wall trying to get my local names resolving. Basically, I want to type a short name like, pawn, to get to my server. I don't want to have to manage those names per device (/etc/hosts).
i don't use systemd, but from what i can tell, configuring and using Avahi [Gentoo wiki] might be what you're looking for? That would allow you to address a machine via e.g. `pawn.local`. But i don't know how that would interacts with systemd-networkd, systemd-hostnamed, NetworkManager, etc., and whether the zeroconf [Wikipedia] functionality provided by Avahi should be provided by some systemd thing in the systemd context ....
https://wiki.gentoo.org/wiki/User:Flexibeast
My most recent wiki contributions
Top
Post Reply

13 posts • Page 1 of 1

Return to “Networking & Security”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic