RobertBerger

dns-1

Apr 21st, 2021
682
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/bin/sh
  2.  
  3. # debug:
  4. export DEBUG=on
  5.  
  6. # no debug:
  7. #unset DEBUG
  8.  
  9. dbg_echo () {
  10.           [[ "$DEBUG" ]] && builtin echo $@
  11. }
  12.  
  13. export nameserver=$(cat /proc/net/pnp | grep nameserver | awk '{print $2}')
  14.  
  15. if [ -z "${nameserver}" ]; then
  16.    # we have no namersver entry in /proc/net/pnp
  17.    dbg_echo "no nameserver"
  18. else
  19.    # we do have a nameserver entry in /proc/net/pnp
  20.    dbg_echo "nameserver: ${nameserver}"
  21.    # sysvinit:
  22.    if [ $(pidof /sbin/init) ]; then
  23.       dbg_echo "it's sysvinit"
  24.       # we just make some entry of nameservers in /etc/resolv.conf
  25.       # interface is irrelevant at the moment
  26.       echo "nameserver 192.168.42.254
  27.            nameserver 8.8.8.8
  28.            search res.training" | resolvconf -a dummy.if
  29.    fi
  30.    # systemd:
  31.    if [ $(pidof systemd) ]; then
  32.       dbg_echo "it's systemd"
  33.       dbg_echo "systemd-resolve --interface eth0 --set-dns ${nameserver}"
  34.       systemd-resolve --interface eth0 --set-dns ${nameserver}
  35.    fi
  36. fi
  37.  
RAW Paste Data