3131#
3232
3333BIND_CONF_OPTIONS=/etc/bind/named.conf.options
34- RESOLV_CONF=/etc/resolv.conf
3534NAT64_PREFIX=64:ff9b::/96
3635
3736DNS64_NAMESERVER_ADDR=127.0.0.1
3837DNS64_CONF=" dns64 ` echo $NAT64_PREFIX | tr \" /\" \"\/\" ` { clients { any; }; recursive-only yes; };"
3938
39+ # Currently solution was verified only on raspbian and ubuntu.
40+ #
41+ without NAT64 || test $PLATFORM = ubuntu || test $PLATFORM = raspbian || die " dns64 is not tested under $PLATFORM ."
42+
43+ if [ $PLATFORM = raspbian ]; then
44+ RESOLV_CONF_HEAD=/etc/resolv.conf.head
45+ elif [ $PLATFORM = ubuntu ]; then
46+ RESOLV_CONF_HEAD=/etc/resolvconf/resolv.conf.d/head
47+ fi
48+
49+ dns64_update_resolvconf ()
50+ {
51+ if [ $PLATFORM = ubuntu ]; then
52+ sudo resolvconf -u || true
53+ elif [ $PLATFORM = raspbian ]; then
54+ sudo systemctl restart dhcpcd || true
55+ fi
56+ }
57+
4058dns64_install ()
4159{
4260 with NAT64 && with DNS64 || return 0
4361
4462 test -f $BIND_CONF_OPTIONS || die ' Cannot find bind9 configuration file!'
4563 sudo sed -i ' /^};/i\\tallow-recursion { any; };' $BIND_CONF_OPTIONS
4664 sudo sed -i ' /^};/i\\t' " $DNS64_CONF " $BIND_CONF_OPTIONS
65+
66+ sudo sh -c " echo \" nameserver $DNS64_NAMESERVER_ADDR \" >> $RESOLV_CONF_HEAD "
67+
68+ if have systemctl; then
69+ sudo systemctl enable bind9 || true
70+ sudo systemctl is-enabled bind9 || die ' Failed to enable bind9!'
71+ sudo systemctl start bind9 || die ' Failed to start bind9!'
72+ fi
73+
74+ dns64_update_resolvconf
4775}
4876
4977dns64_uninstall ()
5078{
5179 with NAT64 && with DNS64 || return 0
5280
53- dns64_stop
81+ dns64_stop
5482 sudo sed -i ' /^\tallow-recursion/d' $BIND_CONF_OPTIONS
5583 sudo sed -i ' /^\tdns64/d' $BIND_CONF_OPTIONS
84+
85+ sudo sed -i ' /^nameserver ' $DNS64_NAMESERVER_ADDR ' /d' $RESOLV_CONF_HEAD || true
86+
87+ dns64_update_resolvconf
88+
89+ if have systemctl; then
90+ sudo systemctl stop bind9 || true
91+ sudo systemctl disable bind9 || true
92+ fi
5693}
5794
5895dns64_start ()
5996{
6097 with NAT64 && with DNS64 || return 0
6198
62- if have systemctl; then
99+ if have systemctl; then
63100 sudo systemctl start bind9 || die ' Failed to start bind9!'
64101 fi
65-
66- sudo sed -i ' 1a nameserver ' $DNS64_NAMESERVER_ADDR $RESOLV_CONF
67102}
68103
69104dns64_stop ()
@@ -73,6 +108,4 @@ dns64_stop()
73108 if have systemctl; then
74109 sudo systemctl stop bind9 || true
75110 fi
76-
77- sudo sed -i ' /^nameserver\s' $DNS64_NAMESERVER_ADDR ' /d' $RESOLV_CONF
78111}
0 commit comments