This project provides a hardened Bash script to enforce persistent, secure DNS configuration on Ubuntu VPS systems hosted on IONOS.
Key improvement vs v2: DHCP is still used for IP/gateway, but DHCP-provided DNS (IONOS 212.227.x.x) is ignored — see technical discussion.
- Disables cloud-init network management (network config)
- Disables netplan configuration generated by cloud-init
- Enables systemd-networkd
- Keeps DHCP for IP on
ens6but rejects DHCP DNS - Forces Cloudflare DNS on interface
ens6 - Enables DNS-over-TLS using systemd-resolved
- Adds Quad9 as fallback DNS provider
- Makes DNS configuration persistent across reboots
Primary
- 1.1.1.1
- 1.0.0.1
Fallback
- 9.9.9.9
- 149.112.112.112
All DNS queries are encrypted using DNS-over-TLS.
IONOS typically injects DNS via DHCP. Even if you set DNS= in [Network], systemd-networkd may still
accept and expose the DHCP DNS unless you explicitly disable it.
v3 adds:
[DHCPv4]
UseDNS=no
[DHCPv6]
UseDNS=noThis keeps DHCP for addressing but prevents the resolver stack from learning/using the IONOS DNS servers.
- Ubuntu 20.04 / 22.04 / 24.04
- VPS network interface name:
ens6 - Root privileges
Download and run:
chmod +x setup-dns-ionos-v3.sh
sudo ./setup-dns-ionos-v3.sh
sudo rebootAfter reboot:
resolvectl status ens6
resolvectl statusExpected:
- On link
ens6: DNS Servers show1.1.1.1 1.0.0.1 DNSOverTLS: yes- IONOS
212.227.x.xmust not appear as active DNS servers
Note: depending on Ubuntu/systemd version, DHCP DNS might still be visible under “DHCP Server” info, but it must not be selected as “DNS Servers” for the link nor as the “Current DNS Server”.
/etc/systemd/network/10-ens6.network/etc/systemd/resolved.conf.d/dns-hardened.conf/etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
sudo rm /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
sudo rm /etc/systemd/network/10-ens6.network
sudo rm /etc/systemd/resolved.conf.d/dns-hardened.conf
sudo mv /etc/netplan/50-cloud-init.yaml.bak /etc/netplan/50-cloud-init.yaml
sudo rebootIf /etc/resolv.conf was replaced and you want the previous one back, restore the backup created by the script:
/etc/resolv.conf.bak.<timestamp>.
-
systemd-networkd docs
https://www.freedesktop.org/software/systemd/man/systemd.network.html
https://www.freedesktop.org/software/systemd/man/systemd-networkd.service.html -
systemd-resolved docs
https://www.freedesktop.org/software/systemd/man/systemd-resolved.service.html
https://www.freedesktop.org/software/systemd/man/resolved.conf.html -
Ubuntu networking / netplan
https://ubuntu.com/server/docs/network-configuration
https://netplan.io/reference/ -
cloud-init networking
https://cloudinit.readthedocs.io/en/latest/topics/network-config.html -
Cloudflare DNS
https://developers.cloudflare.com/1.1.1.1/setup/linux/ -
Quad9 DNS
https://www.quad9.net/service/service-addresses-and-features -
DNS-over-TLS RFCs
RFC 7858 (DNS over TLS)
RFC 8310 (DNS Privacy Profiles) -
Ubuntu stub resolver model
https://wiki.ubuntu.com/SystemdResolved
IONOS VPS DNS Enterprise Hardening (v5.2)
This repository documents the enterprise DNS hardening configuration for an IONOS VPS running Ubuntu,
based on
systemd-networkdandsystemd-resolvedwith DNS-over-TLS enforcement.🔐 Security Goals
✅ Verified Runtime Output
This confirms:
🔄 Differences from v3
Original v5.1 features:
v5.2 adds:
🔥 DNS Firewall Policy
Only the following traffic is allowed:
All other DNS traffic is blocked.
🔁 Automatic Fallback
A systemd timer checks every 5 minutes:
🔄 Rollback
A full rollback script
rollback-dns-ionos-v5.2.shrestores:🔍 Verification Commands
🌐 VPN / Cloudflare DNS Check
To verify that your DNS hardening works correctly when connected via VPN, use Cloudflare's test page:
Step 1: Connect to your VPN
Ensure you are connected to your private VPN network, so that private subnet traffic is routed correctly.
Step 2: Check DNS resolution via the terminal
# Query a public domain resolvectl query google.comVerify DoT (DNS-over-TLS) connectivity
Check VPN/private subnet DNS is still allowed
Step 3: Use Cloudflare's diagnostic page
Open in your browser:
https://one.one.one.one/help/
Step 4: Optional automated check via curl
This shows your current public IP and whether WARP (Cloudflare) is active.
Notes:
Intended for VPS and hardened server environments only.
Not recommended for desktop systems.
🚀 Status
SOC / ISP grade DNS security, VPN-safe, leak-proof, IPv6 compliant.
setup-dns-ionos-plus.sh.xzsetup-dns-ionos-plus.sh.xz.sha256rollback-dns-ionos.sh.xzrollback-dns-ionos.sh.xz.sha256📦Bash script