|
1 | 1 | #!/bin/bash |
2 | 2 |
|
3 | 3 | # Debian and Ubuntu Server Hardening Interactive Script |
4 | | -# Version: 0.80.8 | 2026-06-18 |
| 4 | +# Version: 0.81.0 | 2026-06-21 |
5 | 5 | # 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. |
6 | 8 | # - v0.80.8: Tested and verified compatibility with Ubuntu 26.04 LTS. |
7 | 9 | # Gracefully handle swap creation failures to prevent script aborts, ensuring setup carries on. |
8 | 10 | # - v0.80.7: Choose between tailscale/netbird or both. Improve SSH hardening flow to skip redundant checks if port is unchanged. |
|
112 | 114 | set -euo pipefail |
113 | 115 |
|
114 | 116 | # --- Update Configuration --- |
115 | | -CURRENT_VERSION="0.80.6" |
| 117 | +CURRENT_VERSION="0.81.0" |
116 | 118 | SCRIPT_URL="https://raw.githubusercontent.com/buildplan/du_setup/refs/heads/main/du_setup.sh" |
117 | 119 | CHECKSUM_URL="${SCRIPT_URL}.sha256" |
118 | 120 |
|
@@ -276,7 +278,7 @@ print_header() { |
276 | 278 | printf '%s\n' "${CYAN}╔═════════════════════════════════════════════════════════════════╗${NC}" |
277 | 279 | printf '%s\n' "${CYAN}║ ║${NC}" |
278 | 280 | 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}" |
280 | 282 | printf '%s\n' "${CYAN}║ ║${NC}" |
281 | 283 | printf '%s\n' "${CYAN}╚═════════════════════════════════════════════════════════════════╝${NC}" |
282 | 284 | printf '\n' |
@@ -4415,6 +4417,66 @@ configure_auto_updates() { |
4415 | 4417 | log "Automatic updates configuration completed." |
4416 | 4418 | } |
4417 | 4419 |
|
| 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 | + |
4418 | 4480 | configure_kernel_hardening() { |
4419 | 4481 | print_section "Kernel Parameter Hardening (sysctl)" |
4420 | 4482 | if ! confirm "Apply recommended kernel security settings (sysctl)?"; then |
@@ -5886,6 +5948,13 @@ generate_summary() { |
5886 | 5948 | printf " %-15s %s\n" "Server IPv6:" "$SERVER_IP_V6" |
5887 | 5949 | fi |
5888 | 5950 |
|
| 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 | + |
5889 | 5958 | # --- 2FA Status --- |
5890 | 5959 | if [[ "$TWO_FACTOR_ENABLED" == "true" ]]; then |
5891 | 5960 | printf " %-20s ${GREEN}Enabled (SSH Key + TOTP)${NC}\n" "2FA/MFA:" |
@@ -6223,6 +6292,7 @@ main() { |
6223 | 6292 | configure_2fa |
6224 | 6293 | configure_auto_updates |
6225 | 6294 | configure_time_sync |
| 6295 | + configure_secure_dns |
6226 | 6296 | configure_kernel_hardening |
6227 | 6297 | install_docker |
6228 | 6298 | configure_mesh_vpn |
|
0 commit comments