How to make persistent changes to /etc/resolv.conf Ubuntu 18.10
Solution 1
I am reproducing section "1.11.2. Configure /etc/resolv.conf file" from my answer Part-I Preinstallation: How to install Oracle 18c (Enterprise Edition) on Ubuntu 18.04?
To display what network interfaces are available in the system, issue the following command:
$ ip link show
Figure-39: The WiFi network adapter wlp5s0 is active, up and running.
Network configuration file /etc/netplan/.yaml
should be checked for configuration details. To display the contents of the file, issue the following command:
$ cat /etc/netplan/01-network-manager-all.yaml
Figure-40: Network Manager file 01-network-manager-all.yaml is not configured yet.
Find out whether /etc/resolv.conf
is a static file or symlink
by the following command:
$ ls -l /etc/resolv.conf
Figure-41: File /etc/resolv.conf is a symlink pointing to stub file 'stub-resolv.conf'.
In fact, @igor, the symlink what you removed from other post was really the link to stub file stub-resolv.conf
.
After severed the symlink between /etc/resolv.conf
and stub-resolv.conf
which carried the nameserver 127.0.0.53
, /etc/resolv.conf
was left alone and it was you who made /etc/resolv.conf
as a static file!
The fact is, @Igor, you were not really offered any solution by that act of severance.
Now, display contents of /etc/resolv.conf
by the command:
$ cat /etc/resolv.conf
Figure-42: The contents of symlink '/etc/resolv.conf' having 127.0.0.53 as nameserver.
The dns shown by /etc/resolv.conf
, is 127.0.0.53
but not the default nameserver configured for dhcp
.
Issue the following command to find out the default dns server:
$ systemd-resolve --status wlp5s0
Figure-43: The default DNS server for WiFi network adapter is 192.168.43.1.
Display contents of /run/systemd/resolve/resolv.conf
, by the command:
$ cat /run/systemd/resolve/resolv.conf
Figure-44: The contents of '/run/systemd/resolve/resolv.conf' indicating default nameserver.
From figure-44, you can observe that /run/systemd/resolve/resolv.conf
is the one which really is carrying the default name server 192.168.43.1
.
Issue the following command to change the symlink /etc/resolv.conf
to point default dns server 192.168.43.1
instead of 127.0.0.53
.
$ sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
$ ls -l /etc/resolv.conf
Figure-45: File /etc/resolv.conf is a symlink pointing to default nameserver.
After setting up sysmlink as shown in figure-45, you must make sure that your Wi-Fi is connected, up and running, by issuing the following command:
$ nmcli device
Figure-45-a: Wi-Fi network interface adapter 'wlp5s0' is connected, up and running.
Conclusion:
Under the circumstances, the symlink is the not only best answer you got but also a decent and acceptable solution.
Solution 2
First... remove your edits from
/etc/network/interfaces
.Next, we delete your static
/etc/resolv.conf
file and replace it with the original symlink...
In terminal
...
cd /etc
# change directory
sudo rm -i resolv.conf
# delete static file
sudo ln -s /run/resolvconf/resolv.conf /etc/resolv.conf
# recreate symlink
Now DO NOT manually edit this file!
- Finally, set your DNS servers here...
Set DNS Automatic
to OFF. Enter comma-separated DNS IP addresses.
Solution 3
td;dr
/etc/resolv.conf
should not be edited by users
> cat /etc/resolv.conf # Ubutnu 18
# This file is managed by man:systemd-resolved(8). Do not edit.
#
# This is a dynamic resolv.conf file for connecting local clients to the
# internal DNS stub resolver of systemd-resolved. This file lists all
# configured search domains.
#
# Run "systemd-resolve --status" to see details about the uplink DNS servers
# currently in use.
Network Manger has changed to "netplan" in Ubuntu 18
netplan's tool for managing DNS is systemd-resolve
* on the fly configuration *
1. check
sudo systemd-resolve --status eth0
eth0 is your interface
if there were no DNS servers, set it
2. set
sudo systemd-resolve --interface eth0 --set-dns 1.1.1.1
(you can add more using multiple --set-dns option)
* for persistent configuration *
Take look at ...
cat /etc/netplan/*.yaml
And example of a yaml
file
network:
version: 2
renderer: networkd
ethernets:
ens3:
dhcp4: no
addresses:
- 192.168.121.199/24
gateway4: 192.168.121.1
nameservers:
addresses: [8.8.8.8, 8.8.4.4]
See more
1. how-to-set-dns-nameservers-on-ubuntu-18-04
2. netplan
Also you can install "resolveconf" which is simpler
plus none of these are best, if your are managing a Server.
For Server take look at FreeBSD tool: relayd
or PowerDNS tool: dnsdist
Related videos on Youtube
Igor
Updated on September 18, 2022Comments
-
Igor over 1 year
My resolv.conf file has 'nameserver 127.0.0.53'.
I need to replace it with different value or add another nameserver.I erased symlink, replaced it with file. Now it is managed by Network Manager,
but 127.0.0.53 is restored upon reboot.I need to keep changes, I made.
If I configure network interface in 'interfaces' file,
it becomes 'UNMANAGED' in Network Manager. It's configuration has no effect, though.This question is related HERE.
Guys, If it is not so much trouble, will you, please, read.
Before I perform any 'ping' or 'host', I have to get through that LOGIN procedure.
My main problem is there. What I am trying to do here is to create a kind of work around.
Adding ANY nameserver except 127.0.0.53 or 0.0.0.0 into resolv.conf makes that thing working.
Network DNS is 192.168.11.1. I inserted 192.168.0.1 and it worked. You name it - it goes. But changing settings in Network Manager has no effect at all.@heynnema, I did those settings in IPV4 tab before I rose the question, but unfortunately, they did not work.
/etc/network/interfaces file is intact,
UBUNTU 18.10 is clean installed.
I edited the file for the sake of creating a router in DEBIAN, and I saw how it worked. I do not want it to be the same way here.@Marmayogi my DNS is 192.168.11.1, the same one is in /run/systemd/resolve/resolv.conf. I was surprised to see it there.
Yes, @Marmayogi, my goal is to get that screen.
On UNITY 18.04 this file does not exist, but it does not change much./etc/netplan/01-network-manager-all.yaml # Let NetworkManager manage all devices on this system network: version: 2 renderer: NetworkManager
ip link show 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000 link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 2: enp5s0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc fq_codel state DOWN mode DEFAULT group default qlen 1000 link/ether bc:ae:c5:35:85:e6 brd ff:ff:ff:ff:ff:ff 3: wlp3s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DORMANT group default qlen 1000 link/ether 48:5d:60:c5:91:0b brd ff:ff:ff:ff:ff:ff
systemd-resolve --status wlp3s0 Link 3 (wlp3s0) Current Scopes: DNS LLMNR setting: yes MulticastDNS setting: no DNSOverTLS setting: no DNSSEC setting: no DNSSEC supported: no Current DNS Server: 192.168.11.1 DNS Servers: 192.168.11.1 DNS Domain: ~. crew.local
Yes @Marmayogi, this is the only thing I want working for now. This solution seems aukward to me, though. There was a symlink, as you can see in other post. I removed it, hoping that I would get things working for me.
@Marmayogi, you did a Great job, creating that step by step instruction.
Your solution is GENIUS, not decent!
I tested. Login successful, internet works.
@heynnema,
/run/resolvconf/resolv.conf
does not exist on UBUNTU 18.10.
What would you advise in this situation?System is installed clean from ISO, downloaded from UBUNTU.COM.
-
Boris Hamanov about 5 years@Igor Did you remove your edits from
/etc/network/interfaces
? Did you enter the values that I've circled in RED? Edit your question and show me a screenshot of the IPv4 tab so I can see your settings. -
Igor about 5 yearsIt looks like the image has been blocked. I will try to find a way to open. I did edit 'interfaces' file and saw the results. But it is original now. OS is clean installed.
-
Igor about 5 yearsis there any way to inform UBUNTU team about this situation? It is sertainly not normal.
-
Marmayogi about 5 yearsThis is how things are @Igor. During my attempt to
install Oracle 18c
, I had faced plenty of problems with 127.0.0.53 and finally solved using this simple symlink solution. Even Centos 7, you will find similar issues. However, what exactly is to complain with Ubuntu team? What is in your mind? -
Igor about 5 yearsLast UBUNTU I tried was 15. It worked well. I tested it on this network as well - no problems. Debian 8.6 & 9.8 work fine. They have different way of networking handling. I am pretty sure, that when I install the system, I must be able to use networking from the box, but not looking for the problem solution. Do you agree, @Marmayogi? Whatever people say of Microsoft, but nobody would ever have this kind of issue.
-
Igor about 5 yearsthis happened to work better
sudo ln -sf /run/systemd/resolve/resolv.conf /etc/resolv.conf
. There is no need to change network configuration manually. I have it already working. -
Boris Hamanov about 5 years@Igor but you may have a problem if you're going to use VPN.
-
Boris Hamanov about 5 yearsTwo points... the
systemd-resolve --status
command already showed the correct DNS server, your original symlink usedstub-resolv.conf
, and re-symlinking to/run/systemd/resolve/resolv.conf
also showed the correct DNS server... the problem with your symlink is that you may have problems with VPN and DNS leaks. Best to use the symlink in my answer. -
Igor about 5 yearsThank you @heynnema, I did not know that. In case I have a problem, I will go your way.
-
Igor about 5 yearsOk, I will do that. Thank you. It is not so convenient, though. Actually when setting up VPN it is necessary to alter network configuration. This is not my case now. I needed to get UBUNTU on the internet. Another thing is I do not have
/run/resolvconf/resolv.conf
file on my system. It is UBUNTU 18.10 -
Erik Bennett over 2 yearsMy machine is headless. How do I turn this off from the shell? Thanks! (the setting in the second circle of your image)
-
Boris Hamanov over 2 years@ErikBennett Please start a new question for that. Thanks.