0

Today, on my Ubuntu 22.04.5 computer, I discovered two unknown nameservers in /etc/resolv.conf (symlink to /run/systemd/resolve/resolv.conf):

nameserver fe80::e0eb:40ff:fe79:e364%36 # Does not belong nameserver 172.20.10.1 # Does not belong nameserver 192.168.1.1 # Correct nameserver search . 

As a result, all local hostnames on my intranet (e.g., myhost) were failing to resolve. Rerunning sudo systemd restart systemd-resolved.service did not change anything.

I finally tracked down the problem to my iPhone 8 which was connected by a USB cable to the computer. The iPhone was running a Personal Hotspot, and systemd was treating it as my primary nameserver, overriding 192.168.1.1.

How can I prevent this problem from happening in the future when my iPhone is connected to the computer? Is there some way to tell systemd to ignore the iPhone's hotspot? Thank you very much.

1 Answer 1

1

systemd-resolved was doing that because whatever you are using to configure your networks (NetworkManager? systemd-networkd? netplan? RasPi-style plain dhcpcd?) told it to do so.

What you asked for

To immediately restore your DNS settings to whatever they were before plugging in the iPhone, you can use a command like this:

resolvectl dns enx112233445566 "" 

where the 112233445566 represents the USB tethering MAC address of your iPhone.

To avoid this from happening in the future, you could tell your system that you have a private DNS domain that is only reachable via a particular network interface (or interfaces). Since it seems you have explicitly configured your private DNS names as Top-Level Domain names, you would have to do this, assuming that your normal network interface is eno1:

resolvectl domain eno1 "~." 

This makes eno1 be the preferred interface for all DNS requests.

Only if you had /etc/systemd/network/*.network file to set your DNS resolver IP address, you could make this fix persistent by adding this line to the end:

Domains=~. 

If you had instead set up your private DNS names using the *.home.arpa domain according to the latest recommendation of RFC 8375 (and used search home.arpa to avoid the need to type out the suffix), you could have used resolvectl domain eno1 "~home.arpa" / Domains=~home.arpa instead, allowing you to seamlessly switch to using the internet connection from your tethered iPhone whenever your regular network is down.

What you might actually want

Assuming that you are using NetworkManager which I think is still the default on Ubuntu's desktop/laptop configurations, you should first figure out the NetworkManager connection name of your iPhone tether connection.

You can do it by running nmcli c. It will output something like this:

NAME UUID TYPE DEVICE Wired connection 1 11223344-5566-7788-99aa-bbccddeeff00 ethernet enx112233445566 <...other connections here...> 

Here, enx112233445566 is the iPhone tether network interface (all USB network interfaces start with enx and use the MAC address, as the USB device path would be even more complex and might change if you happen to use a different USB port sometimes). The connection name here is Wired connection 1, which is NetworkManager's default autogenerated name for an ethernet-like connection.

To persistently prevent the iPhone connection from changing your DNS settings:

nmcli c mod "Wired connection 1" ipv4.ignore-auto-dns yes 

If you want to change the connection name to something more descriptive, you can do that too:

nmcli c mod "Wired connection 1" connection.id "iPhone" 
2
  • What an amazingly detailed answer. Thank you! Just one correction: in the NetworkManager advice, the DEVICE name for my iPhone over USB does not begin with "enx" -- it is eth0 (while the main wired interface is enp68s0). Commented Oct 30, 2024 at 10:40
  • Also, I had to set ipv6.ignore-auto-dns to "yes" as well to prevent the IPv6 address from being added to /etc/resolv.conf. Commented Oct 30, 2024 at 10:41

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.