Update: DNS Picker 2024-01-07
So, I did a little video showing the dnspicker in action:
DNS Picker 2024-01-06
I was looking for a little application that would stay in my notification area (that's system tray for you Windows users) and allow me to quickly select which DNS servers I am using. I thought it might be nice if I could create maybe four or five different profiles and be able to pick one with a click or two. The fact that Linux has this shitty habit of messing with /etc/resolv.conf means that I have set the immutable bit on my /etc/resolv.conf file, so that would have to be dealt with by this DNS toggler too. Well, as it turns out, people do not generally pay much attention to DNS and as far as I know, such an application does not exist. That sucks.
I of course, am not an application developer. I am easily annoyed by development environments and find myself frustrated and yelling things like "This sucks!" before I even get started. It would be nice if I could find a language and development environment I can live with, but here we are. Anyways, I found YAD, which has the ability to stuff an icon in the notification area, and assign tasks to clicking on the icon. The way it uses a pipe to accept input is a little clumsy, and I only setup two DNS profiles, but it does work. I made little green and red "D" icons and use those to tell me at a glance whether I am using my encrypted DNS or not. Basically switching between 10.0.0.1 (my WireGuard VPN DNS server) and 192.168.1.1 (my home router which forwards requests to my ISP) is done by simply clicking the icon.
It uses the file /etc/dnspickerg to tell me whether or not I am currently using my encrypted DNS and simply touches or rm's the file depending on which way it is toggling. Anyways, here it is:
#!/usr/bin/env bash
PIPE=$(mktemp -u --tmpdir ${0##*/}.XXXXXXXX)
mkfifo $PIPE
export PIPE
exec 3<> $PIPE
function on_exit() {
echo "quit" >&3
rm -f $PIPE
}
trap on_exit EXIT
function on_click() {
exec 3<> $PIPE
if [ -f /etc/dnspickerg ]; then
echo "icon:/path/dns-red.png" >&3
echo "tooltip:ISP DNS" >&3
sudo chattr -i /etc/resolv.conf
echo "nameserver 192.168.1.1" | sudo tee /etc/resolv.conf
sudo chattr +i /etc/resolv.conf
sudo rm /etc/dnspickerg
else
echo "icon:/path/dns-green.png" >&3
echo "tooltip:Encrypted DNS" >&3
sudo chattr -i /etc/resolv.conf
echo "nameserver 10.9.9.1" | sudo tee /etc/resolv.conf
sudo chattr +i /etc/resolv.conf
sudo touch /etc/dnspickerg
fi
}
export -f on_click
# Set DNS to encrypted by default on startup
sudo chattr -i /etc/resolv.conf
echo "nameserver 10.9.9.1" | sudo tee /etc/resolv.conf
sudo chattr +i /etc/resolv.conf
yad --notification --listen --image="/path/dns-green.png" --text="Encrypted DNS" --command="bash -c on_click" <&3