Advertisement
bobdodds

opennic or root nameservers for systemd-resolved

Jan 19th, 2019
923
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.43 KB | None | 0 0
  1. #!/bin/bash
  2. # ~/bin/cron_systemd_resolved from https://pastebin.com/JBfYVVtG
  3. # ...to pick either 10 random opennic nameservers, or all 13(usually) root nameservers
  4. # sudo crontab -e, a root cron script
  5. # Bob Dodds - cto at blockrippa dot com
  6. #  https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4UJD7RNRZNH7W
  7.  
  8. # set 13 root servers--
  9. #
  10. # cron_systemd_resolved --root
  11. #
  12. # or just set random 10 working opennic servers--
  13. #
  14. # cron_systemd_resolved
  15.  
  16. unset s str
  17.  
  18. if [[ "$0 $*" =~ root ]]
  19.  then s=(
  20.   `for h in $( host -tns . |\
  21.    sed -n -e '/root-servers.net/{s/\(^.*[\t ]\)\(.*\.net\)\(\.$\)/\2/p;}' )
  22.    do host -ta $h | sed -n -e 's/\(^.*[\t ]\)\([.0-9]\+$\)/\2/p'
  23.   done`
  24.  )
  25. else
  26.  s=(
  27.  `wget -O- https://servers.opennic.org/ |\
  28.    sed -n -e '/\(^.*>\)\([0-9]\+\.[0-9]\+\.[0-9]\+\.[0-9]\+\)\(<.*>Pass<.*$\)/{
  29.    s//\2/;
  30.    H;
  31.   }' \
  32.    -e '${
  33.    g;
  34.    /./p;
  35.   }' | shuf -n10`
  36.  )
  37. fi
  38.  
  39. str=${s[@]}
  40. if [ ${#s[@]} = 10 ]
  41.  then sudo sed -i \
  42.   -e 's/^#*Cache=.*/Cache=yes/' \
  43.   -e '/^DNS=/d' \
  44.   -e "\$s/.*/DNS=${str}\n/" \
  45.    /etc/systemd/resolved.conf
  46.  sudo systemctl restart systemd-resolved
  47.  echo ${0##*/} opennic: ${s[@]} | logger --stderr
  48. elif [ ${#s[@]} -gt 10 ]
  49.  then sudo sed -i \
  50.   -e 's/^#*Cache=.*/Cache=yes/' \
  51.   -e '/^DNS=/d' \
  52.   -e "\$s/.*/DNS=${str}\n/" \
  53.    /etc/systemd/resolved.conf
  54.  sudo systemctl restart systemd-resolved
  55.  echo ${0##*/} root: ${s[@]} | logger --stderr
  56. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement