My board has two network interfaces. Both of them are use DHCP to get IP address and DNS. The default route is ordered by metric, but DNS server received by dhcpcd is inverse. My default route table:

Destination     Gateway         Genmask  Flags Metric  Ref    Use Iface    UG       5      0         0       eth0    UG       10     0         0       eth2


domain lan
nameserver ---- (eth2)
nameserver ---- (eth2)
nameserver    ---- (eth0)

eth0 is ethnernet, eth2 is 4G.

I want to have default route and DNS server in the same order, is there have any option to configure?

  • 1
    Just FYI to address a common mistake: If one DNS server responds "the thing you asked about does not exist", a normal resolver will not go asking for a second opinion from alternate DNS servers. Standard resolvers assume that all configured DNS servers have the same knowledge and so asking for second opinions would be pointless. If you want queries for a particular domain go to one DNS server and the rest to another, you will need a resolver that can specifically do that. If you're asking just because your interfaces have very different latency/speed, please mention it in the question.
    – telcoM
    Commented Jan 11, 2023 at 17:38
  • One interface is ethernet, another is 4G. DNS server received from 4G can only use for 4G interface, but my first default route is for ethernet interface (order by metric), so, when DNS request sent, it out from ethernet and then cannot get any response. When first DNS request timeout (5s), auto try another. Each time access a domain name, I have to endure a 5-second timeout.
    – thammer
    Commented Jan 12, 2023 at 6:05
  • 1
    Sorry for bad alignment, I fix it. metric is 5 and 10.
    – thammer
    Commented Jan 12, 2023 at 8:27

1 Answer 1


Hmm... according to whois, is part of network segment, which belongs to China Mobile.

If you use a distribution that is based on Debian or Ubuntu, you could install the resolvconf package and modify the /etc/resolvconf/interface-order file to say you specifically want the records for eth0 first, then the records for eth2.

If you don't have resolvconf available, you might want to examine the hook script(s) used by dhcpcd and modify them to order the DNS server addresses as you wish. The hook script is configured with the script keyword in dhcpcd.conf; if not specified, the default is usually something like /usr/lib/dhcpcd/dhcpcd-run-hooks (check your man dhcpcd.conf for possible distribution-specific modifications).

Alternatively, you could work around the problem by adding a custom route for the nameservers that don't automatically get routed the right way. Since nameserver is also your default gateway, it must be in your local network segment and so the correct interface is automatically preferred for it. But for the 211.136.. nameservers, adding a route like

ip route add via dev eth2

should stop attempts to reach them through the wrong interface. Note that the IP address after the via keyword is the gateway address specified by DHCP on eth2, so you'll probably want to create/modify a dhcpcd hook script to create that route when configuring eth2, using the gateway address specified by the DHCP service instead of hardcoding it.

  • I modified "/lib/dhcpcd/dhcpcd-hooks/20-resolv.conf" solve this problem. Thank you for reply!
    – thammer
    Commented Jan 13, 2023 at 9:33

You must log in to answer this question.

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