Linux – How to set a search domain (and other resolv.conf parameters) in Ubuntu

dhcpdomain-name-systemlinuxnetworkmanagerUbuntu

I like Ubuntu's NetworkManager — it does a great job keeping track of all my WiFi parameters and passwords. However, when I actually plug in an Ethernet cable, the frustration begins.

When hooked up to my work LAN, I'd like to force a particular domain search path. But I can't just edit resolv.conf, since NetworkManager will always overwrite it. And I can't change the settings on the DHCP server.

As a total hack, I set up a script to run whenever the network is brought up. It looks at resolv.conf, and if it's the one from the work LAN, it overwrites it. However, this doesn't work well enough — it seems that periodically resolv.conf will get overwritten by something that doesn't trigger my script.

Is there a less hacky way to do this? Or even a more hacky way, provided that it actually works?

Best Answer

Assuming you are using Ubuntu and a connection named "Wired connection"

edit /etc/NetworkManager/system-connections/Wired connection and add the following:

[ipv4]
method=auto
dns-search=a1.domain.com;a2.domain.com;a3.domain.com;