2 # Copyright (C) 2016 Ian Kelling
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 f
=/usr
/local
/lib
/err
;test -r $f ||
{ echo "error: $0 no $f" >&2;exit 1;}; .
$f
24 usage: ${0##*/} [-h] [-t 2|3|test|client] [-m WIRELESS_MAC] [hostname]
25 setup my router in general: dhcp, dns, etc.
27 Type 2 or 3 is for setting up a backup device, there are two kinds so
28 that you can switch the main device to a backup, then a backup to the
29 main. Type test is for setting up a testing device.
31 Passing an empty string for WIRELESS_MAC, or if none is defined in the
32 secrets file, will cause the device's native mac to be used.
42 if [[ -e /root
/zblock
]]; then
48 firewall_restart
=false
54 while getopts hm
:t
:yz opt
; do
61 libremanage_host
=$hostname
77 *) echo "$0: unexpected arg to -t: $*" >&2; usage
1 ;;
89 *) echo "$0: Internal error! unexpected args: $*" >&2 ; usage
1 ;;
92 shift "$((OPTIND-1))" # Discard the options and sentinel --
99 if [[ ! $hostname ]]; then
105 if [[ -e /root
/router-secrets
]]; then
107 source /root
/router-secrets
110 if [[ ! $mac ]] && ! $test && $secrets; then
111 # if we wanted to increment it
112 #mac=${mac:0: -1}$((${mac: -1} + 2))
116 if (( $# != 0 )); then
130 # background: upgrading all packages is not recommended because it
131 # doesn't go into the firmware. build new firmware if you want
132 # lots of upgrades. I think /tmp/opkg-lists is a pre openwrt 14 location.
133 f
=(/var
/opkg-lists
/*)
134 if ! (( $
(date -r $f +%s
) + 60*60*24 > $
(date +%s
) )); then
135 if ! opkg update
; then
136 echo "$0: warning: opkg update failed" >&2
147 if [[ ! $
(opkg list-installed
"$pname") ]]; then
152 if [[ $to_install ]]; then
153 opkg
install ${to_install[@]}
162 ######### uci example:#######
163 # # https://wiki.openwrt.org/doc/uci
164 # wan_index=$(uci show firewall | sed -rn 's/firewall\.@zone\[([0-9])+\]\.name=wan/\1/p')
165 # wan="firewall.@zone[$wan_index]"
166 # if [[ $(uci get firewall.@forwarding[0].dest) != $forward_dest ]]; then
168 # v uci set firewall.@forwarding[0].dest=$forward_dest
169 # uci commit firewall
170 # firewall_restart=true
172 ####### end uci example #####
175 printf "+ uset %s\n" "$*"
178 local service
="${key%%.*}"
179 restart_var
=${service}_restart
180 if [[ ! ${!restart_var} ]]; then
181 eval $restart_var=false
183 if [[ $
(uci get
"$key") != "$val" ]]; then
184 v uci
set "$key"="$val"
186 eval $restart_var=true
191 printf "+ udel %s\n" "$*"
194 local service
="${key%%.*}"
195 restart_var
=${service}_restart
196 if [[ ! ${!restart_var} ]]; then
197 eval $restart_var=false
199 if uci get
"$key" &>/dev
/null
; then
200 v uci
set "$key"="$val"
202 eval $restart_var=true
206 v
command cedit
-v "$@"
215 elif [[ $hostname == cmc
]]; then
233 : ${key:=pictionary49}
239 # why did we lock this? i don't know
240 #passwd -l root ||: #already locked fails
242 sed -ibak '/^root:/d' /etc
/shadow
243 # /root/router created by manually running passwd then copying the resulting
244 # line. We have no mkpasswd on wrt/librecmc, then we scp it in.
245 cat /root
/router
>>/etc
/shadow
246 # otherwise, serial console gets root login with no password
247 uset system.@system
[0].ttylogin
1
251 cat >/usr
/bin
/archlike-pxe-mount
<<'EOFOUTER'
253 # symlinks are collapsed for nfs mount points, so use a bind mount.
254 # tried putting this in /etc/config/fstab,
255 # then doing block mount, it didn't work. This doesn't persist across reboots,
256 # todo: figure that out
258 for d in /run/{arch,parabola}iso/bootmnt; do
259 cat >>/etc/fstab <<EOF
260 /mnt/usb/tftpboot $d none bind 0 0
262 mount | grep $d &>/dev/null || mount $d
264 /etc/init.d/nfsd restart
266 chmod +x
/usr
/bin
/archlike-pxe-mount
268 sed -i '/^root:/s,/bin/ash$,/bin/bash,' /etc
/passwd
272 uset dropbear.@dropbear
[0].PasswordAuth
0
273 uset dropbear.@dropbear
[0].RootPasswordAuth
0
274 uset dropbear.@dropbear
[0].Port
2220
275 if ! cmp -s /root
/dropbear_rsa_host_key
/etc
/dropbear
/dropbear_rsa_host_key
; then
276 cp /root
/dropbear_rsa_host_key
/etc
/dropbear
/dropbear_rsa_host_key
277 dropbear_restart
=true
280 if $dropbear_restart; then
281 v
/etc
/init.d
/dropbear restart
285 uset network.lan.ipaddr
$l.
$lanip
286 uset network.lan.netmask
$mask
287 if $dev2 ||
$client; then
289 uset network.lan.gateway
$l.1
290 uset network.wan.proto none
291 uset network.wan6.proto none
293 /etc
/init.d
/dnsmasq stop
294 /etc
/init.d
/dnsmasq disable
295 /etc
/init.d
/odhcpd stop
296 /etc
/init.d
/odhcpd disable
297 rm -f /etc
/resolv.conf
298 cat >/etc
/resolv.conf
<<'EOF'
303 # things i tried to keep dnsmasq running but not enabled except local dns,
304 # but it didnt work right and i dont need it anyways.
305 # uset dhcp.wan.ignore $dev2 # default is false
306 # uset dhcp.lan.ignore $dev2 # default is false
307 # uset dhcp.@dnsmasq[0].interface lo
308 # uset dhcp.@dnsmasq[0].localuse 0
309 # uset dhcp.@dnsmasq[0].resolvfile /etc/dnsmasq.conf
310 # uset dhcp.@dnsmasq[0].noresolv 1
311 # todo: populate /etc/resolv.conf with a static value
314 # these are the defaults
316 # this is not needed unless switching from the above condition.
317 # disabling just to debug
318 #uset network.lan.gateway ''
320 uset network.wan.proto dhcp
321 uset network.wan6.proto dhcpv6
322 /etc
/init.d
/dnsmasq start
323 # todo: figure out why this returns 1
324 /etc
/init.d
/dnsmasq
enable ||
:
325 /etc
/init.d
/odhcpd start
326 /etc
/init.d
/odhcpd
enable
329 wireless_restart
=false
332 uset wireless.default_radio0.network
'wwan'
333 uset wireless.default_radio0.ssid
${rclientssid[$h]}
334 uset wireless.default_radio0.encryption
'psk2'
335 uset wireless.default_radio0.device
'radio0'
336 uset wireless.default_radio0.mode
'sta'
337 uset wireless.default_radio0.bssid
${rclientbssid[$h]}
338 # todo: look into whether 5g network is available.
339 uset wireless.default_radio0.key
${rclientkey[$h]}
340 uset wireless.radio0.disabled false
341 uset wireless.radio1.disabled true
343 # defaults, just reseting in case client config ran
344 uset wireless.default_radio0.network lan
345 uset wireless.default_radio0.mode ap
347 uset wireless.default_radio
$x.ssid
"$ssid"
348 uset wireless.default_radio
$x.key
$key
349 uset wireless.default_radio
$x.encryption psk2
351 uset wireless.default_radio
$x.macaddr
$macpre$
((macsuf
+ 2*x
))
353 # secondary device has wireless disabled
354 uset wireless.radio
$x.disabled
$dev2
358 if grep '^OPENWRT_BOARD="mvebu/cortexa9"' /etc
/os-release
&>/dev
/null
; then
359 # todo, I also enabled irqbalance, didnt script it though
360 # https://forum.openwrt.org/t/wrt1900acs-wifi-issue-after-upgrade-from-19-07-to-21-02-vacuum-cleaner-legacy-rate-support/113311/28
361 cat >/etc
/rc.
local <<'EOF'
362 echo "0" >> /sys/kernel/debug/ieee80211/phy0/mwlwifi/tx_amsdu
363 echo "0" >> /sys/kernel/debug/ieee80211/phy1/mwlwifi/tx_amsdu
366 chmod +x
/etc
/rc.
local
368 uset wireless.radio0.disassoc_low_ack
0
369 uset wireless.radio1.disassoc_low_ack
0
373 # found with https://openwrt.org/docs/guide-user/network/wifi/iwchan
374 uset wireless.radio0.channel
11
379 # usb, screen, relay are for libremanage
382 # relay package temporarily disabled
383 # /root/relay_1.0-1_mips_24kc.ipk
385 # note: prometheus-node-exporter-lua-openwrt seems to be a dependency of
386 # prometheus-node-exporter-lua in practice.
387 v pi tcpdump screen rsync unbound-daemon unbound-checkconf \
388 kmod-usb-storage block-mount kmod-fs-ext4 \
389 prometheus-node-exporter-lua-openwrt \
390 prometheus-node-exporter-lua
391 # nfs-kernel-server \
392 # openvpn-openssl adblock libusb-compat \
393 # kmod-usb-serial-cp210x kmod-usb-serial-ftdi \
396 cat >/etc
/libremanage.conf
<<EOF
397 ${libremanage_host}_type=switch
398 ${libremanage_host}_channel=1
403 v
/etc
/init.d
/fstab
enable ||
:
405 # rebooting makes mounting work, but comparing lsmod,
406 # i'm guessing this will too. todo, test it.
407 # 255 == module already loaded
408 for mod
in scsi_mod sd_mod
; do v modprobe
$mod ||
[[ $?
== 255 ]]; done
410 # for archlike pxe. The default settings in the installer expect to find
411 # the NFS at one of these dirs
412 mkdir
-p /run
/archiso
/bootmnt
413 mkdir
-p /run
/parabolaiso
/bootmnt
415 # todo: at some later time, i found /mnt/usb not mounted, watch to see if
416 # that is the case after running this or rebooting.
417 # wiki says safe to do in case of fstab changes:
419 ## ian: usb broke on old router. if that happens, can just comment this to disable problems
420 # echo | cedit /etc/config/fstab ||:
421 cedit
/etc
/config
/fstab
<<EOF || { v block umount; v block mount; }
422 config global automount
427 # /overlay is an / overlay mount for installing extra packages, etc.
428 # https://openwrt.org/docs/guide-user/additional-software/extroot_configuration
429 option target /mnt/usb
430 # option target /overlay
431 option device /dev/sda1
433 option options rw,async,noatime,nodiratime
438 # ian: disabled because afaik I don't need it, no benefit.
439 # config global autoswap
440 # option from_fstab 1
444 # option device /dev/sda1
450 # exportfs -ra wont cut it when its the same path, but now a bind mount
451 # todo: restart nfs when nfs is enabled?
452 #cedit /etc/exports <<EOF || v /etc/init.d/nfsd restart ||:
453 cedit
/etc
/exports
<<EOF ||:
454 /mnt/usb $lan/$cidr(rw,no_root_squash,insecure,sync,no_subtree_check)
456 /run/archiso/bootmnt $lan/$cidr(rw,no_root_squash,insecure,sync,no_subtree_check)
457 /run/parabolaiso/bootmnt $lan/$cidr(rw,no_root_squash,insecure,sync,no_subtree_check)
461 # todo: enable nfs when we need it only.
462 # v /etc/init.d/portmap start
463 # v /etc/init.d/nfsd start
464 # v /etc/init.d/portmap enable
465 # v /etc/init.d/nfsd enable
468 cedit
/etc
/config
/prometheus-node-exporter-lua
<<'EOF' || /etc/init.d/prometheus-node-exporter-lua restart
469 config prometheus-node-exporter-lua 'main'
470 option listen_ipv6 '0'
471 option listen_interface 'lan'
472 option listen_port '9100
475 # default, as of this writing is:
476 # config prometheus-node-exporter-lua 'main'
477 # option listen_interface 'loopback'
478 # option listen_port '9100'
484 ########## openvpn exampl
485 ########## missing firewall settings for routing lan
487 # v /etc/init.d/openvpn start
488 # v /etc/init.d/openvpn enable
490 # # from https://wiki.openwrt.org/doc/uci/firewall
491 # # todo: not sure if /etc/init.d/network needs restarting.
492 # # I did, and I had to restart the vpn afterwards.
493 # # This maps a uci interface to a real interface which is
494 # # managed outside of uci.
495 # cedit /etc/config/network <<'EOF' ||:
496 # config interface 'tun0'
497 # option ifname 'tun0'
498 # option proto 'none'
500 # cedit /etc/config/openvpn <<'EOF' || v /etc/init.d/openvpn restart
501 # config openvpn my_client_config
503 # option config /etc/openvpn/client.conf
510 network_restart
=false
512 cedit wific
/etc
/config
/network
<<EOF || network_restart=true
513 # https://openwrt.org/docs/guide-user/network/wifi/connect_client_wifi
514 config interface 'wwan'
519 cedit
/etc
/config
/network
<<EOF || network_restart=true
520 config 'route' 'transmission'
521 option 'interface' 'lan'
522 option 'target' '10.173.0.0'
523 option 'netmask' '255.255.0.0'
524 option 'gateway' '$l.3'
526 option interface 'wg0'
527 option proto 'wireguard'
528 option private_key '$(cat /root/wg.key)'
529 option listen_port $wgport
530 list addresses '10.3.0.1/24'
531 list addresses 'fdfd::1/64'
534 config wireguard_wg0 'wgclient'
535 option public_key '3q+WJGrm85r59NgeXOIvppxoW4ux/+koSw6Fee1c1TI='
536 option preshared_key '$(cat /root/wg.psk)'
537 list allowed_ips '10.3.0.2/24'
538 list allowed_ips 'fdfd::2/64'
541 # Need to reload before we change dnsmasq to give out
542 # static ips in our new range.
543 if $network_restart; then
544 v
/etc
/init.d
/network reload
550 cedit wific
/etc
/config
/firewall
<<EOF
555 option forward REJECT
564 cedit
host /etc
/config
/firewall
<<EOF
574 cedit
host /etc
/config
/firewall
<<EOF
586 cedit
/etc
/config
/firewall
<<EOF
587 ## begin no external dns for ziva
590 option src_ip 10.2.0.23
598 option dest_ip 10.2.0.23
606 option src_ip 10.2.0.31
614 option dest_ip 10.2.0.31
622 option src_ip 10.2.0.32
630 option dest_ip 10.2.0.32
634 ## end no external dns for ziva
645 option src_dport 9091
646 option dest_port 9091
652 option dest_port 9091
658 option src_dport 3005
659 option dest_port 3005
665 option dest_port 3005
671 option src_dport 2202
678 option dest_port 2202
684 option src_dport 8989
685 option dest_port 8989
691 option dest_port 8989
697 option src_dport 2205
704 option dest_port 2205
709 option src_dport 2207
716 option dest_port 2207
721 option src_dport 2208
728 option dest_port 2208
733 option src_dport 2209
740 option dest_port 2209
746 option src_dport 2202
753 option dest_port 2202
759 option src_dport 8000
760 option dest_port 8000
766 option dest_port 8000
772 option dest_port 2220
778 option dest_port $wgport
782 option name navidrome
784 option src_dport 4533
785 option dest_port 4533
791 option dest_port 4533
793 # So a client can just have i.b8.nz dns even when they
796 # option name navidromelan
798 # option src_dport 4533
799 # option dest_port 4533
800 # option dest_ip $l.2
805 # option name icecast
807 # option src_dport 8000
808 # option dest_port 8000
809 # option dest_ip $l.2
813 # option target ACCEPT
814 # option dest_port 8000
843 # option name httpskd8448
845 # option src_dport 8448
847 # option dest_ip $l.2
851 # option target ACCEPT
852 # option dest_port 8448
856 option name syncthing
858 option src_dport 22001
864 option dest_port 22001
870 # option src_dport $i2pport
871 # option dest_ip $l.178
875 # option target ACCEPT
876 # option dest_port $i2pport
882 # note, using mac transform, we could allow all traffic to a host like this,
883 # replacing 1 as appropriate
884 #option dest_ip ::111:11ff:fe11:1111/::ffff:ffff:ffff:ffff
890 # option name http-ipv6
893 # option dest_port 80
894 # option target ACCEPT
898 # option name https-ipv6
901 # option dest_port 443
902 # option target ACCEPT
906 option name node-exporter
909 option dest_port 9101
914 option name mail587-ipv6
923 firewall-cedit || firewall_restart
=true
926 # not using and in newer wrt, fails, probably due to nonexistent file, error output
929 # Reference error: left-hand side expression is not an array or object
930 # In [anonymous function](), file /usr/share/ucode/fw4.uc, line 3137, byte 12:
931 # called from function [arrow function] (/usr/share/ucode/fw4.uc:733:71)
932 # called from function foreach ([C])
933 # called from function [anonymous function] (/usr/share/ucode/fw4.uc:733:72)
934 # called from function render_ruleset (/usr/share/firewall4/main.uc:56:24)
935 # called from anonymous function (/usr/share/firewall4/main.uc:143:29)
937 # ` if (!inc.enabled) {`
941 # The rendered ruleset contains errors, not doing firewall restart.
942 # /usr/bin/wrt-setup-local:160:error: ""$@"" returned 1
944 ## include a file with users custom iptables rules
946 # option path /etc/firewall.user
947 # option type 'restore'
948 # option family 'ipv4'
952 # not using wireguard for now
953 # if ! uci get firewall.@zone[1].network | grep wg0 &>/dev/null; then
954 # # cant mix cedit plus uci
955 # echo | cedit /etc/config/firewall ||:
956 # uci add_list firewall.@zone[1].network=wg0
957 # uci commit firewall
959 # firewall_restart=true
964 cedit
/etc
/hosts
<<EOF ||:
969 #mail_host=$(grep -F mail.iankelling.org /etc/hosts | awk '{print $1}')
970 # if [[ $mail_host ]]; then
971 # sed -i '/^$mail_host/a mail.iankelling.org' /etc/hosts
975 uset dhcp.@dnsmasq
[0].domain b8.nz
976 uset system.@system
[0].hostname
$hostname
977 uset dhcp.@dnsmasq
[0].
local
979 # uci doesnt seem to have a way to set an empty value,
980 # if you delete it, it goes back to the default. this seems
981 # to be a decent workaround.
982 # todo: setup /etc/resolv.conf to point to 127.0.0.1
983 # later note: disabled, I dunno why I set this.
984 # uset dhcp.@dnsmasq[0].resolvfile /dev/null
986 # if dnsmasq happens to not send out a dns server,
987 # odhcpd will send one out like this:
988 # NetworkManager[953]: <info> [1614982580.5192] dhcp6 (wlan0): option dhcp6_name_servers => 'fd58:5801:8e02::1'
989 # but i dont want ipv6 dns, just keep it simple to ipv4.
990 # I know my isp doesnt have ipv6 right now,
991 # so just stop this thing.
992 # note: tried this, it didn't do anything:
993 # uset dhcp.@odhcpd[0].dns 10.2.0.1
995 # iank, disablde while debugging.
996 #/etc/init.d/odhcpd stop
997 #/etc/init.d/odhcpd disable
999 # todo: make the above conditional on which server this is.
1001 # avoid errors in log. current isp doesnt have ipv6
1002 uset unbound.@unbound
[0].protocol ip4_only
1004 # todo: im not sure all these are needed, but they all look
1005 # like good options.
1006 # https://blog.cloudflare.com/dns-over-tls-for-openwrt/
1007 # https://gist.github.com/vqiu/7b32d3a19a7a09d32e108d998de166c2
1008 #https://blog.thestateofme.com/2018/04/04/howto-secure-your-dns-with-a-raspberry-pi-unbound-and-cloudflare-1-1-1-1/
1010 # # i found that the zone example was having no effect on the config
1012 # https://github.com/openwrt/packages/blob/openwrt-19.07/net/unbound/files/README.md
1014 # # todo: unbound-control, i'm not sure what the purpose of that thing is, some
1015 # # kind of coordination with dhcp of dnsmasq, but what?
1017 # note: for debugging, edit /etc/init.d/unbound, change
1018 # procd_set_param command $PROG -d -c $UB_TOTAL_CONF
1020 # procd_set_param command $PROG -vvv -d -c $UB_TOTAL_CONF
1026 qname-minimisation: yes
1027 rrset-roundrobin: yes
1028 use-caps-for-id: yes
1030 private-domain: b8.nz
1031 local-zone: "10.in-addr.arpa." transparent
1032 access-control-view: 10.2.0.31/32 "youtube"
1037 # no sy until that dongle is used by ziva
1040 #access-control-view: 10.2.0.7/32 "youtube"
1042 access-control-view: 10.2.0.29/32 "youtube"
1044 access-control-view: 10.2.0.32/32 "youtube"
1047 } | cedit
/etc
/unbound
/unbound_srv.conf || restart_unbound
=true
1050 # dns based blocking vs ip based. with ip, same
1051 # server can have multiple domains. in dns,
1052 # you have to make sure clients to use the local dns.
1053 # https dns will need to be blocked by ip in
1054 # order to be comprehensive
1056 cedit
/etc
/unbound
/unbound_ext.conf
<<'EOF' || restart_unbound=true
1057 local-data-ptr: "10.2.0.1 cmc.b8.nz"
1058 local-data-ptr: "10.2.0.2 kd.b8.nz"
1059 local-data-ptr: "10.2.0.3 sy.b8.nz"
1060 local-data-ptr: "10.2.0.4 wrt2.b8.nz"
1061 local-data-ptr: "10.2.0.5 x2.b8.nz"
1062 local-data-ptr: "10.2.0.6 x2w.b8.nz"
1063 local-data-ptr: "10.2.0.7 syw.b8.nz"
1064 local-data-ptr: "10.2.0.8 tp.b8.nz"
1065 local-data-ptr: "10.2.0.9 bb8.b8.nz"
1066 local-data-ptr: "10.2.0.12 demohost.b8.nz"
1067 local-data-ptr: "10.2.0.14 wrt3.b8.nz"
1068 local-data-ptr: "10.2.0.17 x3w.b8.nz"
1069 local-data-ptr: "10.2.0.18 x3.b8.nz"
1070 local-data-ptr: "10.2.0.19 brother.b8.nz"
1071 local-data-ptr: "10.2.0.23 tpw.b8.nz"
1072 local-data-ptr: "10.2.0.24 one9p.b8.nz"
1073 local-data-ptr: "10.2.0.25 hp.b8.nz"
1074 local-data-ptr: "10.2.0.28 frodo.b8.nz"
1075 local-data-ptr: "10.2.0.29 bow.b8.nz"
1076 local-data-ptr: "10.2.0.31 amazontab.b8.nz"
1077 local-data-ptr: "10.2.0.32 samsungtab.b8.nz"
1078 local-data-ptr: "10.2.0.38 x8.b8.nz"
1079 local-data-ptr: "10.2.0.48 bigs.b8.nz"
1080 local-data-ptr: "10.2.0.49 pi4.b8.nz"
1081 local-data-ptr: "10.2.0.50 pi4w.b8.nz"
1082 local-data-ptr: "10.2.0.52 s22.b8.nz"
1083 local-data-ptr: "10.173.0.2 transmission.b8.nz"
1084 local-data-ptr: "10.173.8.1 defaultnn.b8.nz"
1085 local-data-ptr: "10.173.8.2 nn.b8.nz"
1089 # forward-addr: 8.8.8.8
1090 # forward-addr: 8.8.8.8
1091 # https://developers.cloudflare.com/1.1.1.1/1.1.1.1-for-families/setup-instructions/dns-over-https
1092 forward-addr: 1.1.1.3@853#family.cloudflare-dns.com
1093 forward-addr: 1.0.0.3@853#family.cloudflare-dns.com
1094 forward-ssl-upstream: yes
1099 local-zone: "googlevideo.com." refuse
1100 local-zone: "video.google.com." refuse
1101 local-zone: "youtu.be." refuse
1102 local-zone: "youtube-nocookie.com." refuse
1103 local-zone: "youtube-ui.l.google.com." refuse
1104 local-zone: "youtube.com." refuse
1105 local-zone: "youtube.googleapis.com." refuse
1106 local-zone: "youtubeeducation.com." refuse
1107 local-zone: "youtubei.googleapis.com." refuse
1108 local-zone: "yt3.ggpht.com." refuse
1109 local-zone: "youtubekids.com." refuse
1110 # try global if no match in view
1115 if $restart_unbound; then
1116 /etc
/init.d
/unbound restart
1117 if ! unbound-checkconf
; then
1118 echo $0: error
: unbound-checkconf failed
>&2
1124 # # disabled for now. i want to selectively enable it
1125 # # for specific hosts.
1126 # if [[ $(uci get adblock.global.adb_enabled) != 0 ]]; then
1127 # v uci set adblock.global.adb_enabled=0
1128 # uci commit adblock
1129 # /etc/init.d/adblock restart
1131 # # https://github.com/openwrt/packages/tree/master/net/adblock/files
1132 # cat >/etc/crontabs/root <<'EOF'
1133 # 0 06 * * * /etc/init.d/adblock reload
1137 # useful: http://wiki.openwrt.org/doc/howto/dhcp.dnsmasq
1139 # sometimes /mnt/usb fails, cuz it's just a flash drive,
1140 # so make sure we have this dir or else dnsmasq will fail
1142 mkdir
-p /mnt
/usb
/tftpboot
1143 cedit
/etc
/dnsmasq.conf
<<EOF || dnsmasq_restart=true
1147 ptr-record=1.0.2.10.in-addr.arpa.,cmc.b8.nz
1149 # https://ret2got.wordpress.com/2018/01/19/how-your-ethereum-can-be-stolen-using-dns-rebinding/
1151 rebind-domain-ok=b8.nz
1153 # This says the ip of dns server.
1154 # It is default if dnsmasq is doing dns, otherwise, we have to specify it.
1155 # To see it in action, I ran this from a client machine:
1156 # sudo dhcpcd -o domain_name_servers -T
1157 dhcp-option=option:dns-server,$l.1
1159 # use this when doing fai to get the right timezone, its nfsroot is
1160 # setup to use this dhcp option only and call ntpdate.
1161 # generate ips with:
1162 # for h in 0.ubuntu.pool.ntp.org 1.ubuntu.pool.ntp.org ntp.ubuntu.com; do host -t a $h | awk '{print $NF}'; done | while read -r l; do printf ,$l; done
1163 dhcp-option=option:ntp-server,188.165.3.28,202.12.97.45,91.236.251.13,50.205.244.23,78.30.254.80,31.131.0.123,202.65.114.202,94.228.220.14,185.125.190.57,185.125.190.58,91.189.91.157,185.125.190.56,91.189.94.4
1166 # results from googling around dnsmasq optimizations
1167 # about 50k in memory. router has 62 megs.
1168 # in a browsing session, I probably won't ever do 5000 lookups
1169 # before the ttl expiration or whatever does expiration.
1172 # ask all servers, use the one which responds first.
1173 # http://ma.ttwagner.com/make-dns-fly-with-dnsmasq-all-servers/
1176 # namebench benchmarks dns servers. google's dns was only
1177 # slightly less fast than some others, and I trust it more
1178 # to give accurate results, stay relatively fast, and
1179 # not do anythin too malicious, so just use that.
1180 # download namebench and run it like this:
1181 # for x in all regional isp global preferred nearby; do ./namebench.py -s \$x -c US -i firefox -m weighted -J 10 -w; echo \$x; hr; done
1185 server=2606:4700:4700::1113
1186 server=2606:4700:4700::1003
1191 # server=2001:4860:4860::8888
1192 # server=2001:4860:4860::8844
1195 # to fixup existin ips, on the client you can do
1196 # sudo dhclient -r; sudo dhclient <interface-name>
1198 # /etc/init.d/dnsmasq stop
1199 # vi /tmp/dhcp.leases
1200 # /etc/init.d/dnsmasq start
1203 # default dhcp range is 100-150
1204 # bottom port, iPXE (PCI 03:00.0) in seabios boot menu
1205 dhcp-host=c8:60:00:31:6b:75,set:kd,$l.2,kd
1206 dhcp-host=94:05:bb:1e:2c:2e,set:sy,$l.3,sy
1207 #dhcp-host=94:05:bb:1e:2c:2e,set:bo,$l.38,bo
1208 # top port, iPXE (PCI 04:00.0) in seabios boot menu
1209 #dhcp-host=c8:60:00:2b:15:07,set:kd,$l.2,kd
1210 # 4 is reserved for a staticly configured host wrt2
1212 # temporarily commented
1213 dhcp-host=f0:de:f1:81:ec:88,set:x2,$l.5,x2
1215 dhcp-host=c4:8e:8f:44:f5:63,set:x2w,$l.6,x2w
1216 dhcp-host=10:51:07:f5:f1:b8,set:syw,$l.7,syw
1217 dhcp-host=80:fa:5b:1c:6e:cf,set:amy,$l.8,amy
1218 # This is so fai can have an explicit name to use for testing,
1219 # or else any random machine which did a pxe boot would get
1220 # reformatted. The mac is from doing a virt-install, cancelling it,
1221 # and copying the generated mac, so it should be randomish.
1222 dhcp-host=52:54:00:9c:ef:ad,set:demohost,$l.12,demohost
1223 ## for using different dhcp server
1224 #dhcp-host=52:54:00:9c:ef:ad,ignore
1226 dhcp-host=ac:d1:b8:5c:eb:d7,set:x3w,$l.17,x3w
1227 dhcp-host=00:1f:16:14:01:d8,set:x3,$l.18,x3
1228 # BRN001BA98CA823 in dhcp logs
1229 dhcp-host=00:1b:a9:8c:a8:23,set:brother,$l.19,brother
1231 dhcp-host=00:26:b6:f7:d4:d8,set:amyw,$l.23,amyw
1232 dhcp-host=9a:c6:52:6f:ce:7c,set:onep9,$l.24,onep9
1233 dhcp-host=38:63:bb:07:5a:f9,set:hp,$l.25,hp
1234 dhcp-host=00:26:18:97:bb:16,set:frodo,$l.28,frodo
1235 #dhcp-host=00:26:b6:f6:0f:e9,set:frodow,$l.28,frodow
1236 dhcp-host=70:a6:cc:3a:bb:b4,set:bow,$l.29,bow
1237 dhcp-host=6c:56:97:88:7b:74,set:amazontab,$l.31,amazontab
1238 dhcp-host=0a:8a:9b:cf:b5:ec,set:samsungtab,$l.32,samsungtab
1239 # old x2 with bad fan
1240 dhcp-host=00:1f:16:16:39:24,set:x8,$l.38,x8
1242 dhcp-host=38:2c:4a:c9:33:13,set:bigs,$l.48,bigs
1243 dhcp-host=e4:5f:01:07:50:40,set:pi4,$l.49,pi4
1244 dhcp-host=e4:5f:01:07:50:3f,set:pi4w,$l.50,pi4w
1246 dhcp-host=a8:79:8d:71:54:68,set:s22,$l.52,s22
1250 #dhcp-host=52:54:00:56:09:f9,set:faiserver,$l.15,faiserver
1255 # pxe tftpboot for arch-like. todo: openwrt snapshot from 2022-01, it cant
1256 # access /mnt/usb/tftpboot due to ujail sandbox
1258 #tftp-root=/mnt/usb/tftpboot
1259 #tftp-root=/var/run/dnsmasq/tftpboot
1262 dhcp-optsfile=/var/run/dnsmasq/dhcpopts.conf
1264 # for debugging dhcp
1269 if $dnsmasq_restart && ! $dev2; then
1270 # todo: can our ptr records be put in /etc/hosts?
1271 # eg: user normal /etc/hosts records, and they wont be used for A resolution
1272 # due to the other settings, but will be used for ptr? then maybe
1273 # we dont have to restart dnsmasq for a dns update?
1276 # https://www.redpill-linpro.com/techblog/2019/08/27/evaluating-local-dnssec-validators.html#toggling-dnssec-validation-1
1277 # we could turn on dnssec validation when wrt gets dnsmasq > 2.80. currently at 2.80.
1278 # also we can turn off dnssec in systemd-resolved if we know the router is doing it.
1280 # Also, reload of dnsmasq seems to break things, wifi
1281 # clients were not getting internet connectivity.
1283 v
/etc
/init.d
/dnsmasq restart
1286 if $firewall_restart; then
1287 v
/etc
/init.d
/firewall restart
1291 # if already stopped, gives error we want to ignore
1292 /etc
/init.d
/uhttpd stop |
& sed '1{/^Command failed/d}'
1293 /etc
/init.d
/uhttpd disable |
& sed '1{/^Command failed/d}'
1295 # this may just restart the network and take care of the network_restart below.
1296 if $wireless_restart; then
1300 # todo: we should catch errors and still run this if needed
1301 if $network_restart; then