Skip to content

Instantly share code, notes, and snippets.

@milankragujevic
Last active July 18, 2023 11:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save milankragujevic/12c5c8c96985256915a1cca7768f9646 to your computer and use it in GitHub Desktop.
Save milankragujevic/12c5c8c96985256915a1cca7768f9646 to your computer and use it in GitHub Desktop.
Hijack DNS on OpenWrt to another DNS server
iptables -I FORWARD ! -s 192.168.100.242 -p tcp --dport 53 -j ACCEPT
iptables -I FORWARD ! -s 192.168.100.242 -p udp --dport 53 -j ACCEPT
iptables -t nat -A PREROUTING ! -s 192.168.100.242 -p tcp --dport 53 -j DNAT --to 192.168.100.242:53
iptables -t nat -A PREROUTING ! -s 192.168.100.242 -p udp --dport 53 -j DNAT --to 192.168.100.242:53
iptables -I FORWARD ! -s 192.168.100.242 -p tcp --dport 5353 -j ACCEPT
iptables -I FORWARD ! -s 192.168.100.242 -p udp --dport 5353 -j ACCEPT
iptables -t nat -A PREROUTING ! -s 192.168.100.242 -p tcp --dport 5353 -j DNAT --to 192.168.100.242:53
iptables -t nat -A PREROUTING ! -s 192.168.100.242 -p udp --dport 5353 -j DNAT --to 192.168.100.242:53
iptables -A FORWARD -p tcp --dport 53 -s 192.168.100.242 -j ACCEPT
iptables -A FORWARD -p udp --dport 53 -s 192.168.100.242 -j ACCEPT
iptables -t nat -I POSTROUTING ! -s 192.168.100.242 -p udp --dport 53 -d 192.168.100.242 -j MASQUERADE
# NOTE: 192.168.100.242 is the IP of the DNS server
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment