Skip to content

Instantly share code, notes, and snippets.

@smstec
Created December 12, 2018 18:19
Show Gist options
  • Save smstec/c27169228859c5b4418ebe544082ae6d to your computer and use it in GitHub Desktop.
Save smstec/c27169228859c5b4418ebe544082ae6d to your computer and use it in GitHub Desktop.
Bypass pihole for certain IP addresses.
#!/bin/bash
# -- Assumptions/Warnings:
# -- You're not using any kind of NAT or custom iptables rules already on the Pi (as these will be wiped)
# -- <PUT_IP_ADDRESS_HERE> is the device you wish to exclude
# -- 1.1.1.1 is the DNS server you wish excluded devices to use (this is the cloudflare server)
# -- stolen from https://www.reddit.com/r/pihole/comments/56y6lb/ignore_one_device_completely/d8niqzi
# Run as root/sudo it.
sysctl net.ipv4.ip_forward=1
iptables -F
iptables -t nat -F
iptables -X
iptables -t nat -A PREROUTING -s <PUT_IP_ADDRESS_HERE> -p tcp --dport 53 -j DNAT --to-destination 1.1.1.1:53
iptables -t nat -A PREROUTING -s <PUT_IP_ADDRESS_HERE> -p udp --dport 53 -j DNAT --to-destination 1.1.1.1:53
iptables -t nat -A POSTROUTING -j MASQUERADE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment