Local network tool that transparently redirects all X/Twitter traffic to xcancel.com, allowing you to browse Twitter content without directly accessing X's servers.
Guide for configuring Pi-hole to redirect X/Twitter domains to your nginx server.
Your nginx IP is your Docker host’s IP address.
# Find your host IP
hostname -I | awk '{print $1}'
Your nginx IP is the dedicated IP you assigned in docker-compose.yaml:
# Check your docker-compose.yaml or .env file
grep NGINX_IP .env
# Or check running container
docker inspect xcancel-nginx | grep IPAddress
Log in to Pi-hole admin interface (usually http://pi.hole/admin or http://<pi-hole-ip>/admin)
Navigate to Local DNS → DNS Records
Add the following entries:
| Domain | IP Address |
|---|---|
twitter.com |
<your-nginx-ip> |
x.com |
<your-nginx-ip> |
t.co |
<your-nginx-ip> |
www.twitter.com |
<your-nginx-ip> |
www.x.com |
<your-nginx-ip> |
www.t.co |
<your-nginx-ip> |
SSH into your Pi-hole server:
# Edit custom DNS records
sudo vim /etc/pihole/custom.list
Add these lines (replace 192.168.1.100 with your nginx IP):
192.168.1.100 twitter.com
192.168.1.100 www.twitter.com
192.168.1.100 x.com
192.168.1.100 www.x.com
192.168.1.100 t.co
192.168.1.100 www.t.co
Restart DNS service:
pihole restartdns
Pi-hole doesn’t support true wildcard DNS entries in the standard interface, but you can handle common subdomains:
192.168.1.100 mobile.twitter.com
192.168.1.100 mobile.x.com
192.168.1.100 api.twitter.com
192.168.1.100 api.x.com
Note: Redirecting API subdomains may break Twitter apps and bots. Only add these if you want to redirect API traffic as well.
If you need true wildcard support (e.g., *.twitter.com), you can use dnsmasq configuration directly:
# Edit dnsmasq custom config
sudo vim /etc/dnsmasq.d/99-twitter-redirect.conf
Add:
address=/twitter.com/192.168.1.100
address=/x.com/192.168.1.100
address=/t.co/192.168.1.100
This will match all subdomains. Restart dnsmasq:
pihole restartdns
From your Pi-hole server:
# Should return your nginx IP
dig @127.0.0.1 twitter.com +short
dig @127.0.0.1 x.com +short
dig @127.0.0.1 t.co +short
From a client device (configured to use Pi-hole):
# Should return your nginx IP
nslookup twitter.com
nslookup x.com
twitter.com or x.comFrom a client device using Pi-hole:
# Test HTTP redirect
curl -I http://twitter.com
# Expected output includes:
# HTTP/1.1 301 Moved Permanently
# Location: https://xcancel.com/
# Test HTTPS (if you configured SSL)
curl -I https://twitter.com
Open a browser and visit https://twitter.com - should redirect to xcancel.com.
Check Pi-hole is authoritative:
# From client
nslookup twitter.com
# Server line should show Pi-hole's IP
If showing a different DNS server:
Check Pi-hole DNS records:
# On Pi-hole server
pihole -q twitter.com
# Should show "found in exact custom.list match"
Flush Pi-hole cache:
pihole restartdns
Even with correct Pi-hole configuration, clients may cache old DNS results:
Windows:
ipconfig /flushdns
macOS:
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
Linux:
sudo systemd-resolve --flush-caches
# Or
sudo service network-manager restart
Browser:
Modern browsers have their own DNS cache:
chrome://net-internals/#dns and click “Clear host cache”network.dnsCacheExpiration to 0 in about:config)If DNS resolves correctly but redirect isn’t working:
docker compose ps
# Should show nginx as "Up"
docker compose logs nginx
# Should show incoming requests
curl -H "Host: twitter.com" http://<nginx-ip>/
# Should return 301 redirect
# On nginx host
sudo iptables -L | grep -E '80|443'
If Pi-hole is blocking the domains instead of resolving them:
twitter.com, x.com, t.coIf you only want certain devices to use the redirect while others still access X directly:
See Pi-hole documentation on Groups for details.
Run the included dnsmasq container with a different IP and point only specific devices to it. See DNSMASQ_SETUP.md.
To stop redirecting X/Twitter traffic:
/etc/pihole/custom.list and remove linespihole restartdns
Clear client DNS caches (see above)
docker compose down
This redirect works alongside Pi-hole’s ad-blocking. You can still:
If Pi-hole is your DHCP server, all clients will automatically use Pi-hole DNS and get the redirect.
Pi-hole will log all queries for twitter.com/x.com in its statistics. You can:
Some security-conscious clients may alert about “DNS hijacking” when twitter.com resolves to an unexpected IP. This is expected behavior and safe in this context since you control the DNS server.
You’re implementing split-brain DNS (internal vs external resolution). This means:
This is a standard and safe networking practice.