You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu 24.04多网络接口场景下DNS优先级配置最佳实践咨询

Ubuntu 24.04多网络接口场景下DNS优先级配置最佳实践咨询

Hey there, let's tackle this DNS priority issue you're facing with your dual-network setup on Ubuntu 24.04. I've dealt with similar corporate network scenarios before, so here's the most reliable approach to get this working smoothly without routing all your DNS traffic through your employer.

Why your current priority approach isn't working

First, let's clarify the core problem: Ubuntu's default DNS resolver (systemd-resolved) doesn't "fall back" to secondary DNS servers if the first one returns a "domain not found" response. It stops at the first server's answer. So when you try to resolve your employer's internal hostnames, your home WiFi's DNS will return an error, and the system won't check your employer's DNS after that.

Best Practice: Split DNS by Domain/Subnet

Instead of relying on generic priority, you should configure DNS routing rules—telling the system to use your employer's DNS only for their specific domains or subnets, and your home DNS for everything else. Here's how to do it:

Option 1: Configure via systemd-resolved directly

  1. First, confirm systemd-resolved is running:
    systemctl status systemd-resolved
    
  2. Identify your employer's ethernet interface name (use ip link show; it might look like enp0s20f0u1)
  3. Get your employer's DNS server address (check NetworkManager connection settings or run:
    nmcli con show "Your Employer Ethernet Connection Name" | grep ipv4.dns
    
  4. Create a custom resolved config file:
    sudo nano /etc/systemd/resolved.conf.d/company-dns.conf
    
    Paste this content (replace placeholders with your actual values):
    [Resolve]
    # Target domains/subnets that should use the employer's DNS
    Domains=~your-company-domain.com ~10.10.0.0/16
    # Employer's DNS server address
    DNS=10.0.0.1
    # Bind this rule to the employer's ethernet interface
    Interface=enp0s20f0u1
    
  5. Restart the service to apply changes:
    sudo systemctl restart systemd-resolved
    

Option 2: Use NetworkManager GUI (simpler for non-terminal users)

  1. Open NetworkManager, find your employer's ethernet connection, and click "Edit Connection"
  2. Go to the IPv4 Settings tab
  3. In the DNS section:
    • Add your employer's DNS server address
    • In "Search Domains", add your company's domain suffix (e.g., your-company-domain.com)
    • Check the box labeled "Use this connection's DNS servers for these domains only"
  4. Save the settings and reconnect to the ethernet connection

Verify the configuration works

  • Flush DNS caches to test fresh:

    sudo resolvectl flush-caches
    
  • Check if an internal hostname uses the correct DNS:

    resolvectl query internal-host.your-company-domain.com
    

    The output should show it's using your employer's DNS server.

  • Verify general traffic uses your home DNS:

    resolvectl query google.com
    

    This should use your home WiFi's DNS.

Important Notes

  • Don't manually edit /etc/resolv.conf—Ubuntu 24.04 defaults to a symlink to systemd-resolved managed files. If you've modified it before, restore the default link:
    sudo ln -sf /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
    
  • Ensure NetworkManager is set to hand off DNS management to systemd-resolved: In each connection's IPv4 settings, set "DNS" to "Automatic (DHCP) addresses only" (don't force custom DNS unless necessary).

备注:内容来源于stack exchange,提问作者Gordonei

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.17 08:43:12