3

How do I switch DNS by command-line?

I mean like, changing between Google DNS or OpenDNS and whatever the system default is.

Owen_AR
  • 361
  • 1
    IF you look like 3 answers down you will find a CLI version on how to switch DNS server. – Alvar Nov 13 '13 at 11:34
  • 2
    From which only the answer given by Azendale is working since 12.04. None of the answers give us a safe method to switch DNS servers from one to the other. Therefore I believe this question here is not a dupe. – Takkat Nov 13 '13 at 11:42
  • @Takkat Maybe you mean switch back and forth between DNS servers? To "switch DNS servers from one to the other" once is not different from "change the DNS IP". There's no indication that the asker would want to switch back, so the other question seems sufficient. – Steven K Nov 16 '13 at 21:06

1 Answers1

1

Here's a little script to achieve that, replace the IPs with your DNS servers and add this script to your path

#!/bin/bash
if [ $1 == "1" ]; then
echo "nameserver 10.1.0.1" > /etc/resolv.conf 
fi
if [ $1 == "2" ]; then
echo "nameserver 10.1.0.2" > /etc/resolv.conf
fi
  • Would you mind providing instructions on 'adding this script to your path' and an example usage of the script for clarity? This is great, thanks! – earthmeLon May 03 '16 at 18:15