change DNS server in a non-persistent way (on the command-line) [rescue mode]

7,841

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
Share:
7,841

Related videos on Youtube

hiro protagonist
Author by

hiro protagonist

Updated on September 18, 2022

Comments

  • hiro protagonist
    hiro protagonist over 1 year

    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?

    • 2707974
      2707974 over 8 years
      Do you try to simple add dns server in nm-applet for connection?
    • hiro protagonist
      hiro protagonist over 8 years
      i am in the rescue session - command line only - there is no nm-applet.
    • 2707974
      2707974 over 8 years
      Then try to write dns to /etc/resolv.conf. Edit /etc/resolv.conf and add nameserver ip_address_of_dns
    • hiro protagonist
      hiro protagonist over 8 years
      that is the best workaround i could come up with so far - but it changes the configuration on the disk...
    • 2707974
      2707974 over 8 years
      You must to change something if you wont dns to work :)
    • hiro protagonist
      hiro protagonist over 8 years
      nope. found a way!
    • 2707974
      2707974 over 8 years
      Great, I must remember. Up vote from me.
  • Pablo Bianchi
    Pablo Bianchi almost 7 years
    Moreover, that file stands clearly with a "# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTEN".
  • hiro protagonist
    hiro protagonist over 5 years
    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).