Skip to content

Commit f72d90f

Browse files
authored
Merge pull request #117 from buildplan/secure_dns
feat: add optional DNS setup
2 parents ab56795 + 9e94d23 commit f72d90f

3 files changed

Lines changed: 78 additions & 8 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77

88
-----
99

10-
**Version:** v0.80.8
10+
**Version:** v0.81.0
1111

12-
**Last Updated:** 2026-06-18
12+
**Last Updated:** 2026-06-22
1313

1414
**Compatible With:**
1515

@@ -88,12 +88,12 @@ sha256sum du_setup.sh
8888

8989
Compare the output hash to the one below. They must match exactly.
9090

91-
`a8d1c0e63c6a37ce103d4520312c9404f3bee713cfdca9aab06086494cb9c09a`
91+
`e00875833c298fb48ede07c9454693b4e4c5f33903939455d149568d4c9506a0`
9292

9393
Or echo the hash to check, it should output: `du_setup.sh: OK`
9494

9595
```bash
96-
echo a8d1c0e63c6a37ce103d4520312c9404f3bee713cfdca9aab06086494cb9c09a du_setup.sh | sha256sum --check
96+
echo e00875833c298fb48ede07c9454693b4e4c5f33903939455d149568d4c9506a0 du_setup.sh | sha256sum --check
9797
```
9898

9999
### 3. Run the Script

du_setup.sh

Lines changed: 73 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
#!/bin/bash
22

33
# Debian and Ubuntu Server Hardening Interactive Script
4-
# Version: 0.80.8 | 2026-06-18
4+
# Version: 0.81.0 | 2026-06-21
55
# Changelog:
6+
# - v0.81.0: Added optional encrypted DNS (DoT) setup using Quad9 and Cloudflare.
7+
# Includes automatic installation of systemd-resolved if needed and configuration to block tracking protocols.
68
# - v0.80.8: Tested and verified compatibility with Ubuntu 26.04 LTS.
79
# Gracefully handle swap creation failures to prevent script aborts, ensuring setup carries on.
810
# - v0.80.7: Choose between tailscale/netbird or both. Improve SSH hardening flow to skip redundant checks if port is unchanged.
@@ -112,7 +114,7 @@
112114
set -euo pipefail
113115

114116
# --- Update Configuration ---
115-
CURRENT_VERSION="0.80.6"
117+
CURRENT_VERSION="0.81.0"
116118
SCRIPT_URL="https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh"
117119
CHECKSUM_URL="${SCRIPT_URL}.sha256"
118120

@@ -276,7 +278,7 @@ print_header() {
276278
printf '%s\n' "${CYAN}╔═════════════════════════════════════════════════════════════════╗${NC}"
277279
printf '%s\n' "${CYAN}║ ║${NC}"
278280
printf '%s\n' "${CYAN}║ DEBIAN/UBUNTU SERVER SETUP AND HARDENING SCRIPT ║${NC}"
279-
printf '%s\n' "${CYAN}║ v0.80.8 | 2026-06-18${NC}"
281+
printf '%s\n' "${CYAN}║ v0.81.0 | 2026-06-21${NC}"
280282
printf '%s\n' "${CYAN}║ ║${NC}"
281283
printf '%s\n' "${CYAN}╚═════════════════════════════════════════════════════════════════╝${NC}"
282284
printf '\n'
@@ -4415,6 +4417,66 @@ configure_auto_updates() {
44154417
log "Automatic updates configuration completed."
44164418
}
44174419

4420+
configure_secure_dns() {
4421+
print_section "Secure DNS Configuration (DNS-over-TLS)"
4422+
4423+
if ! confirm "Configure secure, encrypted DNS (Quad9 + Cloudflare fallback) and disable local tracking protocols?"; then
4424+
print_info "Skipping secure DNS configuration."
4425+
log "Secure DNS skipped by user."
4426+
return 0
4427+
fi
4428+
4429+
# Ensure systemd-resolved is installed and active
4430+
if ! command -v systemd-resolve >/dev/null 2>&1 && ! command -v resolvectl >/dev/null 2>&1; then
4431+
print_warning "systemd-resolved is not installed on this system."
4432+
if confirm "Install and enable systemd-resolved to handle encrypted DNS?"; then
4433+
if ! apt-get update -qq || ! apt-get install -y -qq systemd-resolved; then
4434+
print_error "Failed to install systemd-resolved."
4435+
log "Failed to install systemd-resolved for secure DNS."
4436+
return 0
4437+
fi
4438+
else
4439+
print_info "Skipping secure DNS setup."
4440+
log "Secure DNS skipped (systemd-resolved not installed)."
4441+
return 0
4442+
fi
4443+
fi
4444+
4445+
print_info "Backing up current resolved config (if exists)..."
4446+
if [[ -f /etc/systemd/resolved.conf ]]; then
4447+
cp /etc/systemd/resolved.conf "$BACKUP_DIR/resolved.conf.backup"
4448+
log "Backed up /etc/systemd/resolved.conf"
4449+
fi
4450+
4451+
print_info "Applying secure DNS settings (Quad9 with Cloudflare Fallback)..."
4452+
# Using Domains=~. forces global DNS to override DHCP interface-specific DNS safely
4453+
mkdir -p /etc/systemd/resolved.conf.d
4454+
tee /etc/systemd/resolved.conf.d/99-secure-dns.conf > /dev/null <<EOF
4455+
[Resolve]
4456+
DNS=9.9.9.9#dns.quad9.net 149.112.112.112#dns.quad9.net 2620:fe::fe#dns.quad9.net 2620:fe::9#dns.quad9.net
4457+
FallbackDNS=1.1.1.1#cloudflare-dns.com 1.0.0.1#cloudflare-dns.com 2606:4700:4700::1111#cloudflare-dns.com 2606:4700:4700::1001#cloudflare-dns.com
4458+
Domains=~.
4459+
DNSSEC=allow-downgrade
4460+
DNSOverTLS=opportunistic
4461+
MulticastDNS=no
4462+
LLMNR=no
4463+
EOF
4464+
4465+
print_info "Enabling and restarting systemd-resolved..."
4466+
systemctl enable --now systemd-resolved
4467+
systemctl restart systemd-resolved
4468+
4469+
# Ensure the OS is actually pointing to systemd-resolved for DNS queries
4470+
if [[ ! -L /etc/resolv.conf ]] || [[ "$(readlink /etc/resolv.conf)" != "../run/systemd/resolve/stub-resolv.conf" && "$(readlink /etc/resolv.conf)" != "/run/systemd/resolve/stub-resolv.conf" ]]; then
4471+
print_info "Symlinking /etc/resolv.conf to the secure stub resolver..."
4472+
rm -f /etc/resolv.conf
4473+
ln -s /run/systemd/resolve/stub-resolv.conf /etc/resolv.conf
4474+
fi
4475+
4476+
print_success "Secure DNS configured and activated."
4477+
log "Secure DNS (Quad9+Cloudflare DoT) successfully configured with Domains=~. override."
4478+
}
4479+
44184480
configure_kernel_hardening() {
44194481
print_section "Kernel Parameter Hardening (sysctl)"
44204482
if ! confirm "Apply recommended kernel security settings (sysctl)?"; then
@@ -5886,6 +5948,13 @@ generate_summary() {
58865948
printf " %-15s %s\n" "Server IPv6:" "$SERVER_IP_V6"
58875949
fi
58885950

5951+
# --- DNS Status ---
5952+
if grep -q "Domains=~." /etc/systemd/resolved.conf 2>/dev/null || grep -q "Domains=~." /etc/systemd/resolved.conf.d/*.conf 2>/dev/null; then
5953+
printf " %-20s ${GREEN}Encrypted (Quad9 + Cloudflare)${NC}\n" "DNS Resolution:"
5954+
else
5955+
printf " %-20s ${YELLOW}Standard/Provider Default${NC}\n" "DNS Resolution:"
5956+
fi
5957+
58895958
# --- 2FA Status ---
58905959
if [[ "$TWO_FACTOR_ENABLED" == "true" ]]; then
58915960
printf " %-20s ${GREEN}Enabled (SSH Key + TOTP)${NC}\n" "2FA/MFA:"
@@ -6223,6 +6292,7 @@ main() {
62236292
configure_2fa
62246293
configure_auto_updates
62256294
configure_time_sync
6295+
configure_secure_dns
62266296
configure_kernel_hardening
62276297
install_docker
62286298
configure_mesh_vpn

du_setup.sh.sha256

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
a8d1c0e63c6a37ce103d4520312c9404f3bee713cfdca9aab06086494cb9c09a du_setup.sh
1+
e00875833c298fb48ede07c9454693b4e4c5f33903939455d149568d4c9506a0 du_setup.sh

0 commit comments

Comments
 (0)