-
Notifications
You must be signed in to change notification settings - Fork 1
/
tethering.sh
executable file
·28 lines (24 loc) · 1.03 KB
/
tethering.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/usr/bin/env sh
set -e
: ${RNDIS_USB_NET:=10.15.19.0/24}
: ${RNDIS_USB_HOST:=10.15.19.100}
: ${RNDIS_USB_DEVICE:=10.15.19.82}
# TODO: use nftables instead?
sudo sysctl net.ipv4.ip_forward=1 >/dev/null
sudo iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
sudo iptables -A FORWARD -s $RNDIS_USB_NET -j ACCEPT
sudo iptables -A POSTROUTING -t nat -j MASQUERADE -s $RNDIS_USB_NET
MANUAL_STEPS_NEEDED=1
if ip a | grep -q "inet $RNDIS_USB_HOST"; then
(set -x; ssh root@$RNDIS_USB_DEVICE dinitctl start usb-internet) && MANUAL_STEPS_NEEDED=0
fi
if [ $MANUAL_STEPS_NEEDED -eq 1 ]; then
cat <<'EOF'
>> Now run 'dinitctl start usb-internet' or 'ip route add default via $RNDIS_USB_HOST' on your device!
(running 'dinitctl stop usb-internet' or 'ip route del default via $RNDIS_USB_HOST' will undo this)
EOF
fi
cat <<'EOF'
>> NOTE: Consider 'apk add resolvconf-none' if in early bringup without WLAN for a while to avoid the need to
e.g. 'rm /etc/resolv.conf; echo "nameserver 1.1.1.1" > /etc/resolv.conf' on every boot
EOF