override dns nameserver
17,042
Solution 1
Add a header to your resolvconf configuration file. Create or edit the file, "/etc/resolvconf/resolv.conf.d/head". Add your preference to it.
/etc/resolvconf/resolv.conf.d/head:
# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
search [yourpreference.com]
Restart your networking service, rebooting is the surest way to restart it.
Solution 2
See https://askubuntu.com/a/63163/267945 - much better solution:
If you want to override or append to the name servers suggested by the DHCP server, you can configure this in
/etc/dhcp/dhclient.conf
, eg:interface "eth0" { prepend domain-name-servers 10.0.0.2; }
Author by
Mr.
Updated on September 18, 2022Comments
-
Mr. over 1 year
i wish to set higher priority for my dns nameservers, or override the ones that are being set by the dhcp server. no matter which approach i took,
nslookup
never displays the right dns nameserver.please see the snippet below.
$ cat /etc/*release* | grep -i dist DISTRIB_ID=Ubuntu DISTRIB_RELEASE=14.04 DISTRIB_CODENAME=trusty DISTRIB_DESCRIPTION="Ubuntu 14.04 LTS"
resolvconf:
$ cat /etc/resolvconf/resolv.conf.d/base nameserver 208.67.222.222 nameserver 208.67.220.220 $ sudo resolvconf --enable-updates $ sudo resolvconf -u $ nslookup > server Default server: 127.0.1.1 Address: 127.0.1.1#53
dhcp:
$ tail -n 1 /etc/dhcp/dhclient.conf supersede domain-name-servers 208.67.222.222, 208.67.220.220; $ sudo service networking restart $ nslookup > server Default server: 127.0.1.1 Address: 127.0.1.1#53
how it can be done??
-
saiarcot895 almost 10 yearsThe DNS server
nslookup
is using is the one in your system, which is then using (or should be using) 208.67.222.222 and 208.67.220.220. See this about 127.0.1.1. -
Mr. almost 10 years@saiarcot895, how do i verify that this is indeed the case? do i have to monitor the communication packets?
-
Andrea Lazzarotto over 9 years«
nslookup
never displays the right dns nameserver» It displays your own computer, which you configured to use OpenDNS... If this is not right, what would be the right one? -
Sergiy Kolodyazhnyy about 9 yearsYou could have simply added your dns to
supersede domain-name-servers 208.67.222.222, 208.67.220.220;
in dhclient.conf -
Apologician over 6 yearsThis question is different from the flagged duplicated question. The duplicate question doesn't have any answers that work for the OP of that question. He checkmarked what he thought was the best answer, but commented at the same time that the answer doesn't work. This OP's question is about the name server resolve. He showed his attempt for using configuring his
/etc/resolvconf
package. The answer provides the crutial step he mentioned. His changes needs to be inhead
, notbase
. -
Apologician over 6 yearsThe accepted answer in this question will work for DNS resolutions whether they are using DHCP or static configurations.
-
-
Lars Viklund over 9 years@MrRoth The comment in the
head
file does not apply to the file itself, but the composite/etc/resolv.conf
that is generated by concatenating the fragments. -
argentum2f about 5 yearsThis one worked for me on kubuntu. All the other things I've tried did not. Not sure I understand the network config (services/etc) of my computer - but as long as this works for now I'm good.