0

I use Pi-Hole on my Raspberry Pi 2. It's very easy to change the Pi-Hole DNS using the Web Interface Settings.

But how can I change my Pi-Hole DNS via command in my raspberry pi console? (Raspbian)

I am looking for something like this:

root@raspberrypi:/home/pi# pihole changedns my.new.dns.server

1

I understand that Pi-hole uses dnsmasq to implement blacklisting, so the first thing I'd try is to edit /etc/dnsmasq.conf and reload the configuration with either

killall -s SIGHUP dnsmasq

or

service dnsmasq restart

If that works, you should find a way to edit the config file from a script. This is typically done with sed or awk. Something like:

sudo sed "s/server=.*/server=my.new.dns.server/g" /etc/dnsmasq.conf
1

Follow the instruction:

1.Add the DNS server to host:

sudo echo "nameserver my.new.dns.server" | sudo tee /etc/resolv.conf 

2.Add the new DNS server to the dnsmasq config file:

sudo sed "s/server=.*/server=my.new.dns.server/g" /etc/dnsmasq.confq  

3.Restart dnsmasq service:

sudo systemctl reload dnsmasq 

or test this one:

sudo service dnsmasq restart

You can also use this little command to it:

sudo echo "nameserver my.new.dns.server" | sudo tee /etc/resolv.conf && sudo sed "s/server=.*/server=my.new.dns.server/g" /etc/dnsmasq.confq  && sudo systemctl reload dnsmasq  

There is also another way which pihole clients DNS is your host and you just need to change the hosts DNS server.
For example (the host ip is 192.168.1.100):

sudo sed "s/server=.*/server=192.168.1.100/g" /etc/dnsmasq.confq   

Then

sudo echo "nameserver my.new.dns.server" | sudo tee /etc/resolv.conf 

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.