From 93da6e0ea6172c254d0e9e252d4d5dffa9a069c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=85=AD=E5=BC=80=E7=AE=B1?= Date: Thu, 1 Dec 2022 01:53:15 +0800 Subject: [PATCH] =?UTF-8?q?[=E6=89=8B=E5=8A=A8=E9=80=89=E9=A2=98][tech]:?= =?UTF-8?q?=2020221129.5=20=E2=AD=90=EF=B8=8F=E2=AD=90=EF=B8=8F=20How=20to?= =?UTF-8?q?=20Set=20Up=20Pi-hole=20to=20Get=20an=20Ad-free=20Life.md?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...ø How to Set Up Pi-hole to Get an Ad-free Life.md | 262 ++++++++++++++++++ 1 file changed, 262 insertions(+) create mode 100644 sources/tech/20221129.5 ā­ļøā­ļø How to Set Up Pi-hole to Get an Ad-free Life.md diff --git a/sources/tech/20221129.5 ā­ļøā­ļø How to Set Up Pi-hole to Get an Ad-free Life.md b/sources/tech/20221129.5 ā­ļøā­ļø How to Set Up Pi-hole to Get an Ad-free Life.md new file mode 100644 index 0000000000..0c8732bca5 --- /dev/null +++ b/sources/tech/20221129.5 ā­ļøā­ļø How to Set Up Pi-hole to Get an Ad-free Life.md @@ -0,0 +1,262 @@ +[#]: subject: "How to Set Up Pi-hole to Get an Ad-free Life" +[#]: via: "https://itsfoss.com/setup-pi-hole/" +[#]: author: "Pratham Patel https://itsfoss.com/author/pratham/" +[#]: collector: "lkxed" +[#]: translator: " " +[#]: reviewer: " " +[#]: publisher: " " +[#]: url: " " + +How to Set Up Pi-hole to Get an Ad-free Life +====== + +Pi-hole is a DNS-based advertisement blocker. Unlike a Chrome or Firefox extension, a Pi-hole can block ads even on your TV! So letā€™s see how to install and take advantage of this amazing tool! + +### What is Pi-hole? + +Pi-hole is a DNS Server. It blocks advertisement serving domains. Set it up on a dedicated Raspberry Pi or some other computer and then use its IP address as the DNS of your device. If you use it as DNS of your router, youā€™ll get an ad-free experience on all connected devices, even your smart TVs and smartphones. + +Want more details? Let me explain. + +A DNS Server tells your computer what the IP address for `google.com` is. Without a _valid_ IP address, your computer can not communicate over the Internet to another computer. + +Pi-hole has a list of domains that must be blocked. Once a computer queries Pi-holeā€™s DNS Server for the IP address for a website like `adservice.google.com`, if it is a domain that must be blocked, then, Pi-hole will respond back with an invalid IP address (which is usually `0.0.0.0`). + +Since ā€œ0.0.0.0ā€ is not a valid IP address, your computer can never talk to the `adservice.google.com` website. This results in the blocking of advertisements. + +Set it at the router level and you go ad-free for your entire home networkā€“yes, even for your ā€œsmartā€ devices like TV, toaster and washing machineā€“instead of being limited to your browser. + +### Setting up Pi-hole + +Using something like this requires some level of experience with the Linux command line, time and patience. Itā€™s more of a [DIY Raspberry Pi project][1] but you can also use it with a normal computer running [Pi-hole][2] in a container. + +So, Iā€™ll be discussing two methods of installing Pi-hole: + +- Automated install on a Raspberry Pi device +- Using Docker or Podman to run Pi-hole in a container + +Let us cover the easier method first method. + +#### Method 1: Automated installation of Pi-hole (requires Raspberry Pi) + +The automated installation is the simplest installation method for installing Pi-hole. It has a few requirements. The picture below mentions OS and hardware support. + +![Pi-hole support for hardware and Operating System][3] + +As you can see above, Pi-hole supports most of the popular Linux distributions. From my personal experience, Pi-hole does not consume more than ~100 MB of RAM and only uses less than 1% of CPU. Meaning it can even run on a [Raspberry Pi Zero W][4]! + +Now that you know which hardware is supported, let us start with the installation steps! + +To install Pi-hole using the automated installation method, all you need to do is run the following command. I understand that running a bash script downloaded from the internet is not usual but this is the official installation method. + +``` +curl -sSL https://install.pi-hole.net | bash +``` + +Once you run the above command, the Pi-hole installer will start and begin to install necessary dependencies and then prompt you with the following screen, indicating that the installer has begun. + +![Pi-hole installer's initial screen][5] + +PS: You can use your mouse to interact with this command line installer ;) + +As depicted from the message shown below, Pi-hole is a free and open source software that mainly relies on donations made by normal folks like you and me. If you find Pi-hole to be useful, please consider donating. [Here is the hyperlink to Pi-holeā€™s donations so you donā€™t have to type the URL yourself][6] ;) + +![Pi-hole is a FOSS project. Please donate if it helped you.][7] + +Next up, you will be asked if the computer on which Pi-hole is being installed has a static IP address for your Local Area Network or not. Since your computers need to know about Pi-holeā€™s IP address beforehand, it is best that the assigned IP address does not change. For more information on how to achieve this, please consult your routerā€™s manual; look for the part with ā€œstatic/reserved IP addressā€. + +![The Pi-hole installer recommends that the IP address of your computer is a static IP address.][8] + +Once you have a static IP assigned to the computer running the Pi-hole, press continue. In the next step you will be asked to choose a DNS provider. This is the server that is asked for [DNS Resolution][9]. Some of the most popular DNS providers are listed for you to choose from. + +Generally, I would recommend that you use either the ā€œQuad9 (filtered, ECS, DNSSEC)ā€ option or the ā€œOpenDNS (ECS, DNSSEC)ā€ option or ā€œCloudflare (DNSSEC)ā€ option. They are quite trusted and have good privacy policy (as opposed to Googleā€™s DNS service). + +![Choosing an upstream DNS provider for the Pi-hole][10] + +Once you have selected a DNS provider, you will be asked for another choice. Here, you are asked to choose a ā€œblocklistā€ that contains a list of websites to block. Pi-hole has a recommended blocklist and is asking if you want to use said blocklist. + +I have used this blocklist and it does a good job of blocking a _majority_ of advertisements so I highly recommend you say ā€œYesā€ to this prompt. + +![Choosing between using the default blocklist or no blocklist][11] + +If you want to monitor items like ā€œNumber of total DNS queriesā€, ā€œNumber of DNS queries blocked/passedā€, etc, you can enable the Web UI to view this data. [This is what the Pi-hole Web UI looks like][12] (this is an older announcement and the Web UI may have changed by the time you read this article). + +Disabling or enabling the Pi-hole Web UI will not affect the functionality of Pi-hole itself. It is just another way to manage Pi-hole. + +![The Pi-hole installer needs user input regarding the availibility of a Web UI.][13] + +If you chose to install the Pi-hole Web UI, the installer will ask you to if you want to install the ā€œlighttpdā€ web server. This is unnecessary if you already have a web server like Apache. But if you do not already have a web server installed already, I recommend you let the Pi-hole installer handle the installation and setup of the lighttpd web server. + +![Should the Pi-hole installer install 'lighttpd' web server or does the user already have a web server?][14] + +For the Pi-hole Web UI to show accurate statistics, the data needs to be logged. The next step is asking if you want to enable logging of queries. It logs items like which computer made a query for which domain name and if it was blocked or allowed, etc. + +If you have enabled the Pi-hole Web UI, I recommend that you enable this. + +![THe Pi-hole installer is asking if the user needs queries logged.][15] + +If you enabled query logging in the previous step, you will now be asked for the verbosity of logging. Choose the logging level that you are most comfortable with and proceed with the next step. + +![The Pi-hole installer is asking for verbosity of logs.][16] + +The installation is now complete! Pi-hole is up and running now. + +**But donā€™t close this window just yet!** If you have enabled the Pi-hole Web UI, you will be given a password that will be used to log in the Pi-hole Web UI. Please note this down. + +![The final screen of Pi-hole automated installation that shows you methods of accessing the Pi-hole Web UI and the randomly generated password][17] + +Once the installation finishes, you will be shown the methods for accessing Pi-hole. + +In my case, since the computerā€™s IP address is ā€œ192.168.122.191ā€, I will type the address `http://192.168.122.191/admin` in my web browser to access Pi-hole Web UI. + +Or, if I am already using ā€œ192.168.122.191ā€ as my DNS server, I can simply type in `http://pi.hole/admin` to view it. + +#### Method 2: Install Pi-hole using Podman/Docker + +This is the recommended method: + +- If you want to deploy Pi-hole without much hassle and/or do not wish to interact with any installer prompts (it is only a 3-step process!) +- If you want to test Pi-hole without actually having to install it and without having your config files modified +- If you want a ā€œreproducibleā€ setup without having to configure everything exactly like before + +For this method, you must have either Podman or Docker installed. For this tutorial, I will be using Docker on Ubuntu 22.04 LTS. However, you can follow the steps on any Linux distribution. + +##### Step 1: Install Docker + +As discussed above, you must have Docker installed. If you donā€™t have it installed, we have covered the procedure about [installing Docker on Ubuntu][18]. + +##### Step 2: Create a docker-compose file + +The easiest way to get a container like Pi-hole up and running via Docker is by using the docker-compose file. + +You can create the docker-compose file anywhere you wish; its location does not matter. Below are the contents of the `docker-compose.yml` file: + +``` +version: '3' + +services: + pihole: + image: docker.io/pihole/pihole:latest + container_name: pihole-aditi + restart: unless-stopped + ports: + - '53:53/tcp' + volumes: + - './pi-hole/etc-pihole:/etc/pihole' + - './pi-hole/etc-dnsmasq.d:/etc/dnsmasq.d' + environment: + TZ: 'Asia/Kolkata' + WEBPASSWORD: 'your-password-here' +``` + +**Please replace the string `your-password-here` with a safe and strong password**. This is the password for the Pi-hole Web UI. + +##### Step 3: Starting the Pi-hole container + +We have a few prerequisites to satisfy before starting the Pi-hole container. + +The first pre-requisite is to create a few directories. Do so by running the following command in your terminal: + +``` +mkdir -vp pi-hole/etc-{pihole,dnsmasq.d} +``` + +These directories will store only the configuration files, so their size will not be greater than a few hundred MBs. These directories should be created in the same location as the `docker-compose.yml` file. + +**This next step is optional but if you are following this guide on Fedora or a RHEL-based distribution**, you need to open port 53 in your firewall. + +``` +sudo firewall-cmd --add-service=dns --permanent +sudo firewall-cmd --reload +``` + +Once this is done, we can start out Pi-hole container! Do so by running the following command: + +``` +docker-compose up -d +``` + +Executing the above command will automatically fetch the latest Pi-hole image and start a container for you. Logging into the Pi-hole Web UI is the same as the previous method. Either type in the IP address of your computer or the `pi.hole` address in your web browser followed by the `/admin` string. + +Both of the following methods are valid for accessing the Pi-hole Web UI: + +- `http:///admin` +- `http://pi.hole/admin` + +You now have Pi-hole installed on your comptuer using Docker! How cool is that?! + +### Setting up Pi-hole + +To start using Pi-hole, you must follow either of the following methods: + +- Add the computerā€™s IP address with Pi-hole installed as the DNS server for your router. This is the most recommended method since it enables blocking ads on tricky devices to configure. Please refer to your routerā€™s manual on how this can be achieved. +- You can add the IP address of the computer hosting Pi-hole as the DNS server for every computer, phone or tablet on your network. This can be tedious but useful in cases where you wish to allow ads on particular devices. I do not recommend this unless you know what you are doing. + +Once you have followed either method 1 or method 2, you can check whether Pi-hole is working. + +``` +dig +short @ ads.google.com +``` + + The `dig` utility is helpful for looking up corresponding IP address for each domain name. In this command, you are querying our Pi-hole server to get the IP address of ā€œads.google.comā€ is. The website ā€œads.google.comā€ is used to serve ads. So, if you get back `0.0.0.0`, your Pi-hole is working! + +Below is the output from my computer: + +``` +$ dig +short @192.168.122.191 ads.google.com +0.0.0.0 +``` + +As you can see, the IP address I got back from Pi-hole is infact an invalid IP address. Meaning any communication to Googleā€™s Ad servers is blocked. Yay! + +But let us also see if ā€œgoogle.comā€ is working. Where will we go to solve our future problems if it doesnā€™t work? So letā€™s see that too! + +You can run the same command as above but with ā€œgoogle.comā€ instead of ā€œads.google.comā€. If the Pi-hole is working correctly, **we should get a** _**valid**_ **IP address in return**. Letā€™s see what happens on my computer. + +``` +$ dig +short @10.0.0.14 google.com +216.58.203.46 +``` + +As expected, ā€œgoogle.comā€ works but ā€œads.google.comā€ is blocked. Our Pi-hole server is working as intended. Perfect! + +### Conclusion + +It requires some effort and expertise to set up Pi-hole to get an ad-free internet experience. As you can see, itā€™s not entirely complicated. You need to be patience with such DIY projects. + +For a Raspberry Pi lover like me, using Pi-hole gives good practice for building projects with [amazing single-board computers][19]. + +I have tried giving all the proper steps but I understand if it doesnā€™t work for you. If you face any issues, please let me know in the comments and Iā€™ll try to help you out. + +-------------------------------------------------------------------------------- + +via: https://itsfoss.com/setup-pi-hole/ + +ä½œč€…ļ¼š[Pratham Patel][a] +选题ļ¼š[lkxed][b] +čÆ‘č€…ļ¼š[čÆ‘č€…ID](https://github.com/čÆ‘č€…ID) +ę ”åƹļ¼š[ę ”åÆ¹č€…ID](https://github.com/ę ”åÆ¹č€…ID) + +ęœ¬ę–‡ē”± [LCTT](https://github.com/LCTT/TranslateProject) 原创ē¼–čƑļ¼Œ[Linuxäø­å›½](https://linux.cn/) č£čŖ‰ęŽØå‡ŗ + +[a]: https://itsfoss.com/author/pratham/ +[b]: https://github.com/lkxed +[1]: https://itsfoss.com/raspberry-pi-projects/ +[2]: https://pi-hole.net/ +[3]: https://itsfoss.com/wp-content/uploads/2022/11/image.png +[4]: https://itsfoss.com/raspberry-pi-zero-w/ +[5]: https://itsfoss.com/wp-content/uploads/2022/11/pihole-automated-install-01.png +[6]: https://pi-hole.net/donate/ +[7]: https://itsfoss.com/wp-content/uploads/2022/11/pihole-automated-install-02.png +[8]: https://itsfoss.com/wp-content/uploads/2022/11/pihole-automated-install-03.png +[9]: https://www.datadoghq.com/knowledge-center/dns-resolution/#how-does-dns-resolution-work +[10]: https://itsfoss.com/wp-content/uploads/2022/11/pihole-automated-install-04.png +[11]: https://itsfoss.com/wp-content/uploads/2022/11/pihole-automated-install-05.png +[12]: https://pi-hole.net/blog/2018/01/13/pi-hole-web-interface-the-next-generation/ +[13]: https://itsfoss.com/wp-content/uploads/2022/11/pihole-automated-install-06.png +[14]: https://itsfoss.com/wp-content/uploads/2022/11/pihole-automated-install-07.png +[15]: https://itsfoss.com/wp-content/uploads/2022/11/pihole-automated-install-08.png +[16]: https://itsfoss.com/wp-content/uploads/2022/11/pihole-automated-install-09.png +[17]: https://itsfoss.com/wp-content/uploads/2022/11/pihole-automated-install-10.png +[18]: https://linuxhandbook.com/install-docker-ubuntu/ +[19]: https://itsfoss.com/raspberry-pi-alternatives/