5

is there a way i can change the DNS server on the command-line without having to change anything on the disk?

i recently booted into the rescue session and i got an IP address (using DHCP) but no DNS server. as my network config is usually done with the nm-applet in the desktop session and not in /etc/network/interfaces i would like to be able to provide a DNS server just for this rescue session and not write anything on disk.

this is usually possible by editing /run/resolvconf/resolv.conf. but resolvconf seems not to be running in the ubuntu 14.04 rescue session.

i was hoping there was something similar to the network configuration where i can configure an interface without having to edit a file:

# ifconfig eth0 192.168.2.5 netmask 255.255.255.0
# route add default gw 192.168.2.1

is there a way to do this for DNS in a rescue session on ubuntu 14.04?

7
  • Do you try to simple add dns server in nm-applet for connection? – 2707974 Oct 6 '15 at 7:05
  • i am in the rescue session - command line only - there is no nm-applet. – hiro protagonist Oct 6 '15 at 7:06
  • Then try to write dns to /etc/resolv.conf. Edit /etc/resolv.conf and add nameserver ip_address_of_dns – 2707974 Oct 6 '15 at 7:12
  • that is the best workaround i could come up with so far - but it changes the configuration on the disk... – hiro protagonist Oct 6 '15 at 7:14
  • 1
    nope. found a way! – hiro protagonist Oct 6 '15 at 13:44
5

i found a way to do this:

kill the dns service (there may be a more subtle way?)

# killall dnsmasq

restart the service using the desired upstream server:

# dnsmasq --server=192.168.2.1

on a newer ubuntu (one with systemd) this would be:

# systemd-resolve -i enp0s31f6 --set-dns=192.168.2.1  # --set-dnssec=true

check with:

# systemd-resolve --status
0

Navigate to this directory /etc/resolvconf/resolv.conf.d edit the head file using vi or vim with su privilege

sudo vi /etc/resolvconf/resolv.conf.d/head

add the following lines to the file

nameserver *DNS server IP*

save the file and use resolvconf utility to set the static DNS server address you entered by the following command

sudo resolvconf -u
2
  • thanks. but this requires writing on the disk. and in the rescue session resolvconf complains: Error: /run/resolvconf/interface either does not exist or is not a directory. removing the link /etc/resolv.conf and then writing directly into a file of that name seems simpler. – hiro protagonist Oct 6 '15 at 8:50
  • 1
    Moreover, that file stands clearly with a "# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN". – Pablo Bianchi Jul 14 '17 at 0:41
0

To get this to work, I added au.archive.ubuntu.com to the /etc/hosts file with an IP address I got from pinging it on my PC.

Then did apt update and it resolved.

1
  • this will then only resolve that particular domain. any other DNS request will remain unresolved. but i agree, apt will work in the rescue session (but nothing else that needs DNS). – hiro protagonist Aug 22 '18 at 6:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.