fix efi, autodiscover, add a host
[automated-distro-installer] / wrt-setup-local
1 #!/bin/bash
2 # Copyright (C) 2016 Ian Kelling
3
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.
8
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.
13
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.
17
18
19 set -eE -o pipefail
20 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
21
22
23 usage() {
24 cat <<EOF
25 usage: ${0##*/} [-h] [-t 2|3|test|client] [-m WIRELESS_MAC]
26 setup my router in general: dhcp, dns, etc.
27
28 Type 2 or 3 is for setting up a backup device, there are two kinds so
29 that you can switch the main device to a backup, then a backup to the
30 main. Type test is for setting up a testing device.
31
32 Passing an empty string for WIRELESS_MAC, or if none is defined in the
33 secrets file, will cause the device's native mac to be used.
34
35 EOF
36
37 exit $1
38 }
39
40
41
42
43
44 secrets=false
45 if [[ -e /root/router-secrets ]]; then
46 secrets=true
47 source /root/router-secrets
48 fi
49 rmac=$(cat /sys/class/net/eth0/address)
50 if $secrets; then
51 hostname=${rhost[$rmac]}
52 fi
53 : ${hostname:=wrt}
54
55
56 dnsmasq_restart=false
57 firewall_restart=false
58 dev2=false
59 test=false
60 client=false
61 libremanage_host=wrt2
62 lanip=1
63 while getopts hm:t: opt; do
64 case $opt in
65 h) usage ;;
66 t)
67 case $2 in
68 2|3)
69 dev2=true
70 libremanage_host=$hostname
71 ;;&
72 2)
73 lanip=4
74 hostname=wrt2
75 ;;
76 3)
77 lanip=14
78 hostname=wrt3
79 ;;
80 test)
81 test=true
82 ;;
83 client)
84 client=true
85 ;;
86 *) echo "$0: unexpected arg to -t: $*" >&2; usage 1 ;;
87 esac
88 ;;
89 m) mac=$OPTARG ;;
90 *) echo "$0: Internal error! unexpected args: $*" >&2 ; usage 1 ;;
91 esac
92 done
93 shift "$((OPTIND-1))" # Discard the options and sentinel --
94
95 if [[ ! $mac ]] && ! $test && $secrets; then
96 # if we wanted to increment it
97 #mac=${mac:0: -1}$((${mac: -1} + 2))
98 mac=${rwmac[$rmac]}
99 fi
100
101 if (( $# != 0 )); then
102 usage 1
103 fi
104
105
106 macpre=${mac:0: -1}
107 macsuf=${mac: -1}
108
109
110 p_updated=false
111 pmirror() {
112 if $p_updated; then
113 return
114 fi
115 # background: upgrading all packages is not recommended because it
116 # doesn't go into the firmware. build new firmware if you want
117 # lots of upgrades. I think /tmp/opkg-lists is a pre openwrt 14 location.
118 f=(/var/opkg-lists/*)
119 if ! (( $(date -r $f +%s) + 60*60*24 > $(date +%s) )); then
120 if ! opkg update; then
121 echo "$0: warning: opkg update failed" >&2
122 fi
123 p_updated=true
124 fi
125 }
126
127 pi() {
128 to_install=()
129 for p in "$@"; do
130 pname=${p##*/}
131 pname=${pname%%_*}
132 if [[ ! $(opkg list-installed "$pname") ]]; then
133 to_install+=($p)
134 pmirror
135 fi
136 done
137 if [[ $to_install ]]; then
138 opkg install ${to_install[@]}
139 fi
140 }
141
142 v() {
143 printf "+ %s\n" "$*"
144 "$@"
145 }
146
147 ######### uci example:#######
148 # # https://wiki.openwrt.org/doc/uci
149 # wan_index=$(uci show firewall | sed -rn 's/firewall\.@zone\[([0-9])+\]\.name=wan/\1/p')
150 # wan="firewall.@zone[$wan_index]"
151 # if [[ $(uci get firewall.@forwarding[0].dest) != $forward_dest ]]; then
152 # # default is wan
153 # v uci set firewall.@forwarding[0].dest=$forward_dest
154 # uci commit firewall
155 # firewall_restart=true
156 # fi
157 ####### end uci example #####
158
159 uset() {
160 printf "+ uset %s\n" "$*"
161 local key="$1"
162 local val="$2"
163 local service="${key%%.*}"
164 restart_var=${service}_restart
165 if [[ ! ${!restart_var} ]]; then
166 eval $restart_var=false
167 fi
168 if [[ $(uci get "$key") != "$val" ]]; then
169 v uci set "$key"="$val"
170 uci commit $service
171 eval $restart_var=true
172 fi
173 }
174
175 udel() {
176 printf "+ udel %s\n" "$*"
177 local key="$1"
178 local val="$2"
179 local service="${key%%.*}"
180 restart_var=${service}_restart
181 if [[ ! ${!restart_var} ]]; then
182 eval $restart_var=false
183 fi
184 if uci get "$key" &>/dev/null; then
185 v uci set "$key"="$val"
186 uci commit $service
187 eval $restart_var=true
188 fi
189 }
190
191
192
193 ### network config
194 ###
195 lan=10.0.0.0
196 if $test; then
197 lan=10.1.0.0
198 elif [[ $hostname == cmc ]]; then
199 lan=10.2.0.0
200 elif $client; then
201 lan=10.3.0.0
202 fi
203
204 if $test; then
205 ssid="gnuv3"
206 elif $secrets; then
207 ssid=${rssid[$rmac]}
208 fi
209
210 : ${ssid:=librecmc}
211
212
213 if $secrets; then
214 key=${rkey[$rmac]}
215 fi
216 : ${key:=pictionary49}
217
218 mask=255.255.0.0
219 cidr=16
220 l=${lan%.0}
221
222 passwd -l root ||: #already locked fails
223
224 sed -ibak '/^root:/d' /etc/shadow
225 # /root/router created by manually running passwd then copying the resulting
226 # line. We have no mkpasswd on wrt/librecmc, then we scp it in.
227 cat /root/router >>/etc/shadow
228 # otherwise, serial console gets root login with no password
229 uset system.@system[0].ttylogin 1
230
231
232
233 cat >/usr/bin/archlike-pxe-mount <<'EOFOUTER'
234 #!/bin/bash
235 # symlinks are collapsed for nfs mount points, so use a bind mount.
236 # tried putting this in /etc/config/fstab,
237 # then doing block mount, it didn't work. This doesn't persist across reboots,
238 # todo: figure that out
239 rm -f /etc/fstab
240 for d in /run/{arch,parabola}iso/bootmnt; do
241 cat >>/etc/fstab <<EOF
242 /mnt/usb/tftpboot $d none bind 0 0
243 EOF
244 mount | grep $d &>/dev/null || mount $d
245 done
246 /etc/init.d/nfsd restart
247 EOFOUTER
248 chmod +x /usr/bin/archlike-pxe-mount
249
250 sed -i '/^root:/s,/bin/ash$,/bin/bash,' /etc/passwd
251
252
253
254 uset dropbear.@dropbear[0].PasswordAuth 0
255 uset dropbear.@dropbear[0].RootPasswordAuth 0
256 uset dropbear.@dropbear[0].Port 2220
257 if ! cmp -s /root/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key; then
258 cp /root/dropbear_rsa_host_key /etc/dropbear/dropbear_rsa_host_key
259 dropbear_restart=true
260 fi
261
262 if $dropbear_restart; then
263 v /etc/init.d/dropbear restart
264 fi
265
266
267 uset network.lan.ipaddr $l.$lanip
268 uset network.lan.netmask $mask
269 if $dev2 || $client; then
270 if $dev2; then
271 uset network.lan.gateway $l.1
272 uset network.wan.proto none
273 uset network.wan6.proto none
274 fi
275 /etc/init.d/dnsmasq stop
276 /etc/init.d/dnsmasq disable
277 /etc/init.d/odhcpd stop
278 /etc/init.d/odhcpd disable
279 rm -f /etc/resolv.conf
280 cat >/etc/resolv.conf <<'EOF'
281 nameserver 8.8.8.8
282 nameserver 8.8.4.4
283 EOF
284
285 # things i tried to keep dnsmasq running but not enabled except local dns,
286 # but it didnt work right and i dont need it anyways.
287 # uset dhcp.wan.ignore $dev2 # default is false
288 # uset dhcp.lan.ignore $dev2 # default is false
289 # uset dhcp.@dnsmasq[0].interface lo
290 # uset dhcp.@dnsmasq[0].localuse 0
291 # uset dhcp.@dnsmasq[0].resolvfile /etc/dnsmasq.conf
292 # uset dhcp.@dnsmasq[0].noresolv 1
293 # todo: populate /etc/resolv.conf with a static value
294
295 else
296 # these are the defaults
297 uset network.lan.gateway ''
298 uset network.wan.proto dhcp
299 uset network.wan6.proto dhcpv6
300 /etc/init.d/dnsmasq start
301 # todo: figure out why this returns 1
302 /etc/init.d/dnsmasq enable ||:
303 /etc/init.d/odhcpd start
304 /etc/init.d/odhcpd enable
305 fi
306
307 wireless_restart=false
308
309 if $client; then
310 uset wireless.default_radio0.network 'wwan'
311 uset wireless.default_radio0.ssid ${rclientssid[$rmac]}
312 uset wireless.default_radio0.encryption 'psk2'
313 uset wireless.default_radio0.device 'radio0'
314 uset wireless.default_radio0.mode 'sta'
315 uset wireless.default_radio0.bssid ${rclientbssid[$rmac]}
316 # todo: look into whether 5g network is available.
317 uset wireless.default_radio0.key ${rclientkey[$rmac]}
318 uset wireless.radio0.disabled false
319 uset wireless.radio1.disabled true
320 else
321 # defaults, just reseting in case client config ran
322 uset wireless.default_radio0.network lan
323 uset wireless.default_radio0.mode ap
324 for x in 0 1; do
325 uset wireless.default_radio$x.ssid "$ssid"
326 uset wireless.default_radio$x.key $key
327 uset wireless.default_radio$x.encryption psk2
328 if [[ $mac ]]; then
329 uset wireless.default_radio$x.macaddr $macpre$((macsuf + 2*x))
330 fi
331 # secondary device has wireless disabled
332 uset wireless.radio$x.disabled $dev2
333 done
334 fi
335
336
337
338
339
340 # usb, screen, relay are for libremanage
341 # rsync is for brc
342 #
343 # relay package temporarily disabled
344 # /root/relay_1.0-1_mips_24kc.ipk
345 v pi kmod-usb-storage block-mount kmod-fs-ext4 nfs-kernel-server \
346 tcpdump openvpn-openssl adblock libusb-compat \
347 screen kmod-usb-serial-cp210x kmod-usb-serial-ftdi rsync
348
349 cat >/etc/libremanage.conf <<EOF
350 ${libremanage_host}_type=switch
351 ${libremanage_host}_channel=1
352 EOF
353
354
355
356 v /etc/init.d/fstab enable ||:
357
358 # rebooting makes mounting work, but comparing lsmod,
359 # i'm guessing this will too. todo, test it.
360 # 255 == module already loaded
361 for mod in scsi_mod sd_mod; do v modprobe $mod || [[ $? == 255 ]]; done
362
363 # for archlike pxe. The default settings in the installer expect to find
364 # the NFS at one of these dirs
365 mkdir -p /run/archiso/bootmnt
366 mkdir -p /run/parabolaiso/bootmnt
367
368 # todo: at some later time, i found /mnt/usb not mounted, watch to see if
369 # that is the case after running this or rebooting.
370 # wiki says safe to do in case of fstab changes:
371
372 ## ian: usb broke on old router. if that happens, can just comment this to disable problems
373 # echo | cedit /etc/config/fstab ||:
374 v cedit /etc/config/fstab <<EOF || { v block umount; v block mount; }
375 config global automount
376 option from_fstab 1
377 option anon_mount 1
378
379 config mount
380 # /overlay is an / overlay mount for installing extra packages, etc.
381 # https://openwrt.org/docs/guide-user/additional-software/extroot_configuration
382 option target /mnt/usb
383 # option target /overlay
384 option device /dev/sda1
385 option fstype ext4
386 option options rw,async,noatime,nodiratime
387 option enabled 0
388 EOF
389
390
391 # ian: disabled because afaik I don't need it, no benefit.
392 # config global autoswap
393 # option from_fstab 1
394 # option anon_swap 1
395
396 # config swap
397 # option device /dev/sda1
398 # option enabled 1
399
400
401
402
403 # exportfs -ra wont cut it when its the same path, but now a bind mount
404 # todo: restart nfs when nfs is enabled?
405 #cedit /etc/exports <<EOF || v /etc/init.d/nfsd restart ||:
406 cedit /etc/exports <<EOF ||:
407 /mnt/usb $lan/$cidr(rw,no_root_squash,insecure,sync,no_subtree_check)
408 # for arch pxe
409 /run/archiso/bootmnt $lan/$cidr(rw,no_root_squash,insecure,sync,no_subtree_check)
410 /run/parabolaiso/bootmnt $lan/$cidr(rw,no_root_squash,insecure,sync,no_subtree_check)
411 EOF
412
413
414 # todo: enable nfs when we need it only.
415 # v /etc/init.d/portmap start
416 # v /etc/init.d/nfsd start
417 # v /etc/init.d/portmap enable
418 # v /etc/init.d/nfsd enable
419
420
421
422
423
424
425
426
427 ########## openvpn exampl
428 ########## missing firewall settings for routing lan
429 ########## traffic
430 # v /etc/init.d/openvpn start
431 # v /etc/init.d/openvpn enable
432
433 # # from https://wiki.openwrt.org/doc/uci/firewall
434 # # todo: not sure if /etc/init.d/network needs restarting.
435 # # I did, and I had to restart the vpn afterwards.
436 # # This maps a uci interface to a real interface which is
437 # # managed outside of uci.
438 # v cedit /etc/config/network <<'EOF' ||:
439 # config interface 'tun0'
440 # option ifname 'tun0'
441 # option proto 'none'
442 # EOF
443 # v cedit /etc/config/openvpn <<'EOF' || v /etc/init.d/openvpn restart
444 # config openvpn my_client_config
445 # option enabled 1
446 # option config /etc/openvpn/client.conf
447 # EOF
448
449 wgip4=10.3.0.1/24
450 wgip6=fdfd::1/64
451 wgport=26000
452
453 network_restart=false
454 if $client; then
455 v cedit wific /etc/config/network <<EOF || network_restart=true
456 # https://openwrt.org/docs/guide-user/network/wifi/connect_client_wifi
457 config interface 'wwan'
458 option proto 'dhcp'
459 EOF
460 fi
461
462 v cedit /etc/config/network <<EOF || network_restart=true
463 config 'route' 'transmission'
464 option 'interface' 'lan'
465 option 'target' '10.173.0.0'
466 option 'netmask' '255.255.0.0'
467 option 'gateway' '$l.3'
468
469 option interface 'wg0'
470 option proto 'wireguard'
471 option private_key '$(cat /root/wg.key)'
472 option listen_port $wgport
473 list addresses '10.3.0.1/24'
474 list addresses 'fdfd::1/64'
475
476 # tp
477 config wireguard_wg0 'wgclient'
478 option public_key '3q+WJGrm85r59NgeXOIvppxoW4ux/+koSw6Fee1c1TI='
479 option preshared_key '$(cat /root/wg.psk)'
480 list allowed_ips '10.3.0.2/24'
481 list allowed_ips 'fdfd::2/64'
482 EOF
483
484 if $network_restart; then
485 v /etc/init.d/network reload
486 fi
487
488 firewall-cedit() {
489
490 if $client; then
491 v cedit wific /etc/config/firewall <<EOF
492 config zone
493 option name wwan
494 option input REJECT
495 option output ACCEPT
496 option forward REJECT
497 option masq 1
498 option mtu_fix 1
499 option network wwan
500 EOF
501 fi
502
503 case $hostname in
504 wrt)
505 v cedit host /etc/config/firewall <<EOF
506 config redirect
507 option name ssh
508 option src wan
509 option src_dport 22
510 option dest_ip $l.3
511 option dest lan
512 EOF
513 ;;
514 cmc)
515 v cedit host /etc/config/firewall <<EOF
516 config redirect
517 option name ssh
518 option src wan
519 option src_dport 22
520 option dest_ip $l.2
521 option dest lan
522 EOF
523 ;;
524 esac
525
526 v cedit /etc/config/firewall <<EOF
527 config rule
528 option src wan
529 option target ACCEPT
530 option dest_port 22
531
532 config redirect
533 option name sshtp
534 option src wan
535 option src_dport 2202
536 option dest_port 22
537 option dest_ip $l.2
538 option dest lan
539 config rule
540 option src wan
541 option target ACCEPT
542 option dest_port 2202
543
544 config redirect
545 option name sshx2
546 option src wan
547 option src_dport 2205
548 option dest_port 22
549 option dest_ip $l.5
550 option dest lan
551 config rule
552 option src wan
553 option target ACCEPT
554 option dest_port 2205
555
556 config redirect
557 option name sshx3
558 option src wan
559 option src_dport 2207
560 option dest_port 22
561 option dest_ip $l.7
562 option dest lan
563 config rule
564 option src wan
565 option target ACCEPT
566 option dest_port 2207
567
568 config redirect
569 option name sshtp
570 option src wan
571 option src_dport 2208
572 option dest_port 22
573 option dest_ip $l.8
574 option dest lan
575 config rule
576 option src wan
577 option target ACCEPT
578 option dest_port 2208
579
580 config redirect
581 option name sshbb8
582 option src wan
583 option src_dport 2209
584 option dest_port 22
585 option dest_ip $l.9
586 option dest lan
587 config rule
588 option src wan
589 option target ACCEPT
590 option dest_port 2209
591
592 config redirect
593 option name icecast
594 option src wan
595 option src_dport 8000
596 option dest_port 8000
597 option dest_ip $l.2
598 option dest lan
599 config rule
600 option src wan
601 option target ACCEPT
602 option dest_port 8000
603
604 config rule
605 option name sshwrt
606 option src wan
607 option target ACCEPT
608 option dest_port 2220
609
610 config rule
611 option name wg
612 option src wan
613 option target ACCEPT
614 option dest_port $wgport
615 option proto udp
616
617
618 config redirect
619 option name httpkd
620 option src wan
621 option src_dport 80
622 option dest lan
623 option dest_ip $l.2
624 option proto tcp
625 config rule
626 option src wan
627 option target ACCEPT
628 option dest_port 80
629 option proto tcp
630
631 config redirect
632 option name httpskd
633 option src wan
634 option src_dport 443
635 option dest lan
636 option dest_ip $l.2
637 option proto tcp
638 config rule
639 option src wan
640 option target ACCEPT
641 option dest_port 443
642 option proto tcp
643
644 config redirect
645 option name syncthing
646 option src wan
647 option src_dport 22001
648 option dest_ip $l.8
649 option dest lan
650 config rule
651 option src wan
652 option target ACCEPT
653 option dest_port 22001
654
655
656 config rule
657 option name ssh-ipv6
658 option src wan
659 option dest lan
660 # note, using mac transform, we could allow all traffic to a host like this,
661 # replacing 1 as appropriate
662 #option dest_ip ::111:11ff:fe11:1111/::ffff:ffff:ffff:ffff
663 option dest_port 22
664 option target ACCEPT
665 option family ipv6
666
667 config rule
668 option name http-ipv6
669 option src wan
670 option dest lan
671 option dest_port 80
672 option target ACCEPT
673 option family ipv6
674
675 config rule
676 option name https-ipv6
677 option src wan
678 option dest lan
679 option dest_port 443
680 option target ACCEPT
681 option family ipv6
682
683 config rule
684 option name node-exporter
685 option src wan
686 option dest lan
687 option dest_port 9101
688 option target ACCEPT
689 option family ipv6
690
691 config rule
692 option name mail587-ipv6
693 option src wan
694 option dest lan
695 option dest_port 587
696 option target ACCEPT
697 option family ipv6
698
699 EOF
700 }
701 firewall-cedit || firewall_restart=true
702
703 # not using wireguard for now
704 # if ! uci get firewall.@zone[1].network | grep wg0 &>/dev/null; then
705 # # cant mix cedit plus uci
706 # echo | cedit /etc/config/firewall ||:
707 # uci add_list firewall.@zone[1].network=wg0
708 # uci commit firewall
709 # firewall-cedit ||:
710 # firewall_restart=true
711 # fi
712
713
714
715 v cedit /etc/hosts <<EOF || dnsmasq_restart=true
716 127.0.1.1 $hostname
717 EOF
718 # not sure this case statement is needed
719 case $hostname in
720 cmc)
721 v cedit host /etc/hosts <<EOF || dnsmasq_restart=true
722 $l.1 $hostname
723 EOF
724 ;;
725 esac
726
727
728 #mail_host=$(grep -F mail.iankelling.org /etc/hosts | awk '{print $1}')
729 # if [[ $mail_host ]]; then
730 # sed -i '/^$mail_host/a mail.iankelling.org' /etc/hosts
731 # fi
732
733
734 uset dhcp.@dnsmasq[0].domain b8.nz
735 uset system.@system[0].hostname $hostname
736 uset dhcp.@dnsmasq[0].local
737
738 # uci doesnt seem to have a way to set an empty value,
739 # if you delete it, it goes back to the default. this seems
740 # to be a decent workaround.
741 # todo: setup /etc/resolv.conf to point to 127.0.0.1
742 uset dhcp.@dnsmasq[0].resolvfile=/dev/null
743
744 # disabled for now. i want to selectively enable it
745 # for specific hosts.
746 if [[ $(uci get adblock.global.adb_enabled) != 0 ]]; then
747 v uci set adblock.global.adb_enabled=0
748 uci commit adblock
749 /etc/init.d/adblock restart
750 fi
751 # https://github.com/openwrt/packages/tree/master/net/adblock/files
752 cat >/etc/crontabs/root <<'EOF'
753 0 06 * * * /etc/init.d/adblock reload
754 EOF
755
756
757 # useful: http://wiki.openwrt.org/doc/howto/dhcp.dnsmasq
758
759 # sometimes /mnt/usb fails, cuz it's just a flash drive,
760 # so make sure we have this dir or else dnsmasq will fail
761 # to start.
762 mkdir -p /mnt/usb/tftpboot
763 v cedit /etc/dnsmasq.conf <<EOF || dnsmasq_restart=true
764 server=/b8.nz/#
765 ptr-record=1.0.2.10.in-addr.arpa.,cmc.b8.nz
766 ptr-record=2.0.2.10.in-addr.arpa.,kd.b8.nz
767 ptr-record=3.0.2.10.in-addr.arpa.,sy.b8.nz
768 ptr-record=4.0.2.10.in-addr.arpa.,wrt2.b8.nz
769 ptr-record=5.0.2.10.in-addr.arpa.,x2.b8.nz
770 ptr-record=6.0.2.10.in-addr.arpa.,xw2.b8.nz
771 ptr-record=7.0.2.10.in-addr.arpa.,syw.b8.nz
772 ptr-record=8.0.2.10.in-addr.arpa.,tp.b8.nz
773 ptr-record=9.0.2.10.in-addr.arpa.,bb8.b8.nz
774 ptr-record=12.0.2.10.in-addr.arpa.,demohost.b8.nz
775 ptr-record=14.0.2.10.in-addr.arpa.,wrt3.b8.nz
776 ptr-record=19.0.2.10.in-addr.arpa.,brother.b8.nz
777 ptr-record=25.0.2.10.in-addr.arpa.,hp.b8.nz
778 ptr-record=.0.2.10.in-addr.arpa.,transmission.b8.nz
779
780 # https://ret2got.wordpress.com/2018/01/19/how-your-ethereum-can-be-stolen-using-dns-rebinding/
781 stop-dns-rebind
782 rebind-domain-ok=b8.nz
783
784 # this says the ip of default gateway and dns server,
785 # but I think they are unneded and default
786 #dhcp-option=3,$l.1
787 #dhcp-option=6,$l.1
788
789
790
791 # results from googling around dnsmasq optimizations
792 # about 50k in memory. router has 62 megs.
793 # in a browsing session, I probably won't ever do 5000 lookups
794 # before the ttl expiration or whatever does expiration.
795 cache-size=10000
796
797 # ask all servers, use the one which responds first.
798 # http://ma.ttwagner.com/make-dns-fly-with-dnsmasq-all-servers/
799 all-servers
800
801 # namebench benchmarks dns servers. google's dns was only
802 # slightly less fast than some others, and I trust it more
803 # to give accurate results, stay relatively fast, and
804 # not do anythin too malicious, so just use that.
805 # download namebench and run it like this:
806 # 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
807 # google
808 server=8.8.4.4
809 server=8.8.8.8
810 server=2001:4860:4860::8888
811 server=2001:4860:4860::8844
812
813
814 # to fixup existin ips, on the client you can do
815 # sudo dhclient -r; sudo dhclient <interface-name>
816
817 # default dhcp range is 100-150
818 # bottom port, iPXE (PCI 03:00.0) in seabios boot menu
819 dhcp-host=c8:60:00:31:6b:75,set:kd,$l.2,kd
820 dhcp-host=94:05:bb:1e:2c:2e,set:sy,$l.3,sy
821 # top port, iPXE (PCI 04:00.0) in seabios boot menu
822 #dhcp-host=c8:60:00:2b:15:07,set:kd,$l.2,kd
823 # 4 is reserved for a staticly configured host wrt2
824 # old x2 with bad fan
825 #dhcp-host=00:1f:16:16:39:24,set:x2,$l.5,x2
826 dhcp-host=f0:de:f1:81:ec:88,set:x2,$l.5,x2
827 dhcp-host=c4:8e:8f:44:f5:63,set:x2w,$l.6,x2w
828 dhcp-host=34:7d:f6:ed:ec:07,set:syw,$l.7,syw
829 dhcp-host=80:fa:5b:1c:6e:cf,set:tp,$l.8,tp
830 # This is so fai can have an explicit name to use for testing,
831 # or else any random machine which did a pxe boot would get
832 # reformatted. The mac is from doing a virt-install, cancelling it,
833 # and copying the generated mac, so it should be randomish.
834 dhcp-host=52:54:00:9c:ef:ad,set:demohost,$l.12,demohost
835 dhcp-host=62:03:cb:a8:3e:a3,set:trp,$1.13,trp
836 dhcp-host=00:1f:16:14:01:d8,set:x3,$l.18,x3
837 # BRN001BA98CA823 in dhcp logs
838 dhcp-host=00:1b:a9:8c:a8:23,set:brother,$l.19,brother
839 dhcp-host=38:63:bb:07:5a:f9,set:hp,$l.25,hp
840 dhcp-host=00:26:b6:f6:0f:e9,set:frodow,$l.28,frodow
841 dhcp-host=00:26:18:97:bb:16,set:frodo,$l.29,frodo
842
843
844 # faiserver vm
845 dhcp-host=52:54:00:56:09:f9,set:faiserver,$l.15,faiserver
846
847 # This is the ip it picks by default if dhcp fails,
848 # so might as well use it.
849 # hostname is the name it uses according to telnet
850 dhcp-host=b4:75:0e:94:29:ca,set:switch9429ca,$l.251,switch9429ca
851
852 # template
853 # dhcp-host=,$l.,
854
855 # Just leave the tftp server up even if we aren't doing pxe boot.
856 # It has no sensitive info.
857 enable-tftp=br-lan
858 tftp-root=/mnt/usb/tftpboot
859 dhcp-optsfile=/etc/dnsmasq-dhcpopts.conf
860
861 #log-queries=extra
862 EOF
863
864
865 if $dnsmasq_restart && ! $dev2; then
866 # todo: can our ptr records be put in /etc/hosts?
867 # eg: user normal /etc/hosts records, and they wont be used for A resolution
868 # due to the other settings, but will be used for ptr? then maybe
869 # we dont have to restart dnsmasq for a dns update?
870 #
871 # todo: according to this
872 # https://www.redpill-linpro.com/techblog/2019/08/27/evaluating-local-dnssec-validators.html#toggling-dnssec-validation-1
873 # we should turn on dnssec validation when wrt gets version > 2.80. currently at 2.80.
874 # todo: download https://downloads.openwrt.org/snapshots/packages/mipsel_24kc/base/dnsmasq-full_2.84-1_mipsel_24kc.ipk
875 # and install it. then we can turn off dnssec in systemd-resolved
876 #
877 # Also, reload of dnsmasq seems to break things, wifi
878 # clients were not getting internet connectivity.
879 v /etc/init.d/dnsmasq restart
880 fi
881
882 if $firewall_restart; then
883 v /etc/init.d/firewall restart
884 fi
885
886 # this may just restart the network and take care of the network_restart below.
887 if $wireless_restart; then
888 v wifi
889 fi
890
891 # todo: we should catch errors and still run this if needed
892 if $network_restart; then
893 reboot
894 fi
895
896 exit 0