-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup-home-network.sh
More file actions
executable file
·78 lines (69 loc) · 2.12 KB
/
Copy pathsetup-home-network.sh
File metadata and controls
executable file
·78 lines (69 loc) · 2.12 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/usr/bin/env bash
set -euo pipefail
# Make the 10 GbE homeserver uplink the boot-critical interface without
# hard-coding its DHCP address. Run with --apply from a local console or a
# session connected through that interface.
if [[ ${EUID} -ne 0 ]]; then
echo "Run this installer as root: sudo ./setup-home-network.sh [--apply]" >&2
exit 1
fi
required_interface=${REQUIRED_INTERFACE:-ens9f0}
secondary_interface=${SECONDARY_INTERFACE:-eno2}
unused_interface=${UNUSED_INTERFACE:-eno1}
apply=false
if [[ ${1:-} == "--apply" ]]; then
apply=true
elif [[ $# -gt 0 ]]; then
echo "Usage: sudo ./setup-home-network.sh [--apply]" >&2
exit 2
fi
for interface in \
"$required_interface" \
"$secondary_interface" \
"$unused_interface"; do
[[ -e "/sys/class/net/$interface" ]] || {
echo "Network interface not found: $interface" >&2
exit 1
}
done
install -d -m 0755 /etc/netplan
cat >/etc/netplan/90-honeypot-uplink.yaml <<EOF
network:
version: 2
renderer: networkd
ethernets:
${required_interface}:
dhcp4: true
dhcp-identifier: mac
optional: false
dhcp4-overrides:
route-metric: 50
${secondary_interface}:
optional: true
dhcp4-overrides:
route-metric: 200
${unused_interface}:
optional: true
EOF
chmod 0600 /etc/netplan/90-honeypot-uplink.yaml
# Netplan can emit more than one wait-online ExecStart when configurations are
# merged. Pin boot readiness to the actual required uplink and do not require
# the local DNS service to be running before Docker starts it.
install -d -m 0755 \
/etc/systemd/system/systemd-networkd-wait-online.service.d
cat \
>/etc/systemd/system/systemd-networkd-wait-online.service.d/90-honeypot-uplink.conf <<EOF
[Service]
ExecStart=
ExecStart=/lib/systemd/systemd-networkd-wait-online --interface=${required_interface}:routable --timeout=60
EOF
netplan generate
systemctl daemon-reload
if [[ "$apply" == true ]]; then
netplan apply
networkctl status "$required_interface" --no-pager
else
echo "Configuration generated but not applied."
echo "Review /etc/netplan/90-honeypot-uplink.yaml, then run:"
echo " sudo netplan try"
fi