DNS Leak Prevention and Firewall Configuration
Red Hat-based Distros (RHEL, CentOS, Fedora, Rocky Linux, AlmaLinux, etc.) Using firewalld
firewalld# Block all outbound DNS TCP/UDP traffic by default
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="0.0.0.0/0" port port="53" protocol="tcp" reject'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="0.0.0.0/0" port port="53" protocol="udp" reject'
# Allow DNS traffic to local Docker bridge subnet (example here: 172.28.0.0/16)
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="172.28.0.0/16" port port="53" protocol="tcp" accept'
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="172.28.0.0/16" port port="53" protocol="udp" accept'
# Reload firewall to apply rules
sudo firewall-cmd --reloadDebian/Ubuntu Using ufw
ufw# Deny all outgoing DNS traffic by default
sudo ufw deny out 53/tcp
sudo ufw deny out 53/udp
# Allow DNS queries only to Docker network IP range (example: 172.28.0.0/16)
sudo ufw allow out to 172.28.0.0/16 port 53 proto tcp
sudo ufw allow out to 172.28.0.0/16 port 53 proto udp
# Reload ufw to apply changes
sudo ufw reloadArch Linux or Other Distros Using iptables
iptablesFor Arch Linux or Other Distros Using nftables
nftablesFirewall Configuration Notes
PreviousPrivate and Secure DNS with Pi-hole and UnboundNextConfiguring DoT with Unbound and Pi-hole on OPNsense
Last updated