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