I have found a nice script on this website, this contains a very long list of iptables commands that allow ad blocking using iptables on Linux.
See it here: https://pgl.yoyo.org/as/iplist.php?ipformat=iptables&showintro=1&mimetype=plaintext.
I have found this does not work in iptables when fed in as a list of rules. The way to use this is to edit it and add this at the very top.
#!/bin/sh
So that it looks like this.
#!/bin/sh
/sbin/iptables -A OUTPUT -o eth0 -d 103.245.223.131 -j REJECT # athena-ads.wikia.com
/sbin/iptables -A OUTPUT -o eth0 -d 103.245.223.194 -j REJECT # athena-ads.wikia.com
/sbin/iptables -A OUTPUT -o eth0 -d 103.31.6.184 -j REJECT # ads.imgur.com
/sbin/iptables -A OUTPUT -o eth0 -d 103.31.6.32 -j REJECT # ads.imgur.com
/sbin/iptables -A OUTPUT -o eth0 -d 103.31.6.33 -j REJECT # ads.imgur.com
/sbin/iptables -A OUTPUT -o eth0 -d 103.31.6.34 -j REJECT # ads.imgur.com
/sbin/iptables -A OUTPUT -o eth0 -d 103.31.6.35 -j REJECT # ads.imgur.com
/sbin/iptables -A OUTPUT -o eth0 -d 103.31.6.36 -j REJECT # ads.imgur.com
Then place the script in the /etc/network/if-up.d directory and then make it executable.
┏jcartwright@jcartwright-System-Version╼╸╸╸╸╸╸╾
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━◉:/etc/network/if-up.d$ sudo chmod +x ads
[sudo] password for jcartwright:
Then run all scripts in the aforementioned directory using this command.
┏jcartwright@jcartwright-System-Version╼╸╸╸╸╸╸╾
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━◉:/etc/network/if-up.d$ sudo run-parts /etc/network/if-up.d/
wpa_supplicant: unknown mode: ""
run-parts: /etc/network/if-up.d//wpasupplicant exited with return code 1
This worked very well. Connections to the ad networks in the iptables script will just timeout.
┏jcartwright@jcartwright-System-Version╼╸╸╸╸╸╸╾
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━◉:~/Documents$ ping clickthrutraffic.com
PING clickthrutraffic.com (95.211.219.66) 56(84) bytes of data.
^C
--- clickthrutraffic.com ping statistics ---
79 packets transmitted, 0 received, 100% packet loss, time 79864ms
To download this list easily, use the htmlq utility and then save the content from the <pre> tags to plain text.
┏jcartwright@jcartwright-System-Version╼╸╸╸╸╸╸╾
┗━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━◉:~/Documents$ curl --silent -L https://pgl.yoyo.org/as/iplist.php?ipformat=iptables | htmlq pre | w3m -dump -T text/html | awk NF > ads
This does work just fine to easily save the iptables list.
Could you be kind enough to list these IP tables or provide files in the format appropriate for inputting into our routers, since changing settings individually on all devices throughout ones home is tedious and inefficient, in general.