From 24f19dd46cd7bb1c5bc1a46694a3b4ac928c16e2 Mon Sep 17 00:00:00 2001 From: Ian Kelling Date: Mon, 20 Dec 2021 00:27:31 -0500 Subject: [PATCH] fully adopt wireguard --- brc2 | 14 +++--- btrbk-run | 3 +- distro-end | 122 ++++++++++++++++++++++++++++------------------- hssh | 5 +- mail-route | 3 +- mail-setup | 82 +++++++++++++++++-------------- vpn-mail-forward | 18 +++++-- 7 files changed, 148 insertions(+), 99 deletions(-) diff --git a/brc2 b/brc2 index 4dc573b..0e9736e 100644 --- a/brc2 +++ b/brc2 @@ -1028,17 +1028,17 @@ wghole() { [Interface] # contents hole-priv.key PrivateKey = $(cat hole-priv.key) -# UDP service port -ListenPort = 32454 -Address = 10.5.3.$ipsuf/24 +ListenPort = 1194 +Address = 10.8.0.$ipsuf/24 # https://dev.to/tangramvision/what-they-don-t-tell-you-about-setting-up-a-wireguard-vpn-1h2g -PostUp = ping -c1 10.5.3.1 +# ||: makes the systemd service not fail due to the failed command +PostUp = ping -c1 10.8.0.1 ||: [Peer] # li PublicKey = zePGl7LoS3iv6ziTI/k8BMh4L3iL3K2t9xJheMR4hQA= -AllowedIPs = 10.5.3.0/24 -Endpoint = 72.14.176.105:32454 +AllowedIPs = 10.8.0.0/24 +Endpoint = 72.14.176.105:1194 PersistentKeepalive = 25 EOF umask $umask_orig @@ -1047,7 +1047,7 @@ EOF cedit -q $host /p/c/machine_specific/li/filesystem/etc/wireguard/wghole.conf </dev/null } diff --git a/btrbk-run b/btrbk-run index 99c980e..e96bb52 100644 --- a/btrbk-run +++ b/btrbk-run @@ -524,7 +524,8 @@ fi if [[ $ret == 0 ]]; then for tg in ${targets[@]}; do - ssh root@$tg /a/exe/mail-backup-clean + : + #ssh root@$tg /a/exe/mail-backup-clean done fi diff --git a/distro-end b/distro-end index 880c25b..117042e 100755 --- a/distro-end +++ b/distro-end @@ -61,10 +61,15 @@ cd / # case $distro in # esac -# get sudo pass cached right away -if ! sudo -nv 2>/dev/null; then - sudo -v -fi +case $HOSTNAME in + li|bk|je) : ;; + *) + # get sudo pass cached right away + if ! sudo -nv 2>/dev/null; then + sudo -v + fi + ;; +esac # old repo. remove when all machines updated sudo rm -fv /etc/apt/sources.list.d/wireguard-ubuntu-wireguard-bionic.list @@ -505,47 +510,6 @@ esac s rm -fv /etc/apt/preferences.d/radicale ######### end universal pinned packages ###### -### system76 things ### -case $HOSTNAME in - sy) - # note, i stored the initial popos packages at /a/bin/data/popos-pkgs - if [[ ! -e /etc/apt/sources.list.d/system76.list ]]; then - # https://blog.zackad.dev/en/2017/08/17/add-ppa-simple-way.html - sd /etc/apt/sources.list.d/system76.list < /sys/kernel/debug/dynamic_debug/control + # dmesg -w ;;& $MAIL_HOST|bk) for unit in ${nn_progs[@]}; do i /etc/systemd/system/$unit.service.d/nn.conf <&2' ERR m() { printf "%s\n" "$*"; "$@"; } found=false + +ifname=$1 +shift + # wait up to 10 seconds for the gateway to appear for i in in {1..10}; do gw=$(/usr/sbin/ip route | sed -rn 's/^default via .* dev (\S+).*/\1/p') @@ -23,10 +27,18 @@ do-forward() { m /sbin/ip6tables -t nat $cmd PREROUTING -i $gw -p tcp -m tcp --dport $port -j DNAT --to-destination 2600:3c00:e002:3800::4 done # for bk to talk to MAIL_HOST, only need port 25. - ip6tables -t nat $cmd PREROUTING -i tun1 -s 2600:3c00:e002:3800::5 -d 2600:3c00:e000:280::2 -p tcp -m tcp --dport 25 -j DNAT --to-destination 2600:3c00:e002:3800::4 + ip6tables -t nat $cmd PREROUTING -i $ifname -s 2600:3c00:e002:3800::5 -d 2600:3c00:e000:280::2 -p tcp -m tcp --dport 25 -j DNAT --to-destination 2600:3c00:e002:3800::4 # we could leave these on all the time but its convenient to do it here - m /sbin/iptables $cmd FORWARD -i tun+ -o $gw -j ACCEPT - m /sbin/iptables $cmd FORWARD -i $gw -o tun+ -j ACCEPT + m /sbin/iptables $cmd FORWARD -i $ifname -o $gw -j ACCEPT + m /sbin/iptables $cmd FORWARD -i $gw -o $ifname -j ACCEPT + + case $ifname in + wg*) + /sbin/iptables -t nat $cmd POSTROUTING -s 10.8.0.0/24 -o $gw -j MASQUERADE + /sbin/ip6tables -t nat $cmd POSTROUTING -s 2600:3c00:e002:3800::/64 -o $gw -j MASQUERADE + ;; + esac + } ports=(25 143 587) -- 2.30.2