mirror of
https://github.com/LCTT/TranslateProject.git
synced 2024-12-26 21:30:55 +08:00
178 lines
7.0 KiB
Markdown
178 lines
7.0 KiB
Markdown
|
[#]: subject: "How to Update Pi-hole Easily"
|
|||
|
[#]: via: "https://itsfoss.com/update-pi-hole/"
|
|||
|
[#]: author: "Abhishek Prakash https://itsfoss.com/"
|
|||
|
[#]: collector: "lkxed"
|
|||
|
[#]: translator: " "
|
|||
|
[#]: reviewer: " "
|
|||
|
[#]: publisher: " "
|
|||
|
[#]: url: " "
|
|||
|
|
|||
|
How to Update Pi-hole Easily
|
|||
|
======
|
|||
|
|
|||
|
Pi-hole is one of the most effective ad-blockers available for you to use. You can install it on your router or a dedicated system and get an ad-free experience for all the devices connected through it.
|
|||
|
|
|||
|
In an earlier article, I discussed the [steps for installing Pi-hole][1]. But you must update it regularly to win the cat-and-mouse game between ad blockers and ad providers (Google, Facebook, etc). Another aspect is to patch a security vulnerability that might affect you negatively.
|
|||
|
|
|||
|
The update method depends on the installation method. To recall, I discussed two methods:
|
|||
|
|
|||
|
- **Method 1**: The existing Pi-hole installation was conducted using a script. The script was `curl -sSL https://install.pi-hole.net | bash` (or something similar).
|
|||
|
- **Method 2**: You installed Pi-hole using either Podman or Docker as a container.
|
|||
|
|
|||
|
I will cover how to update Pi-hole with both of these methods.
|
|||
|
|
|||
|
### Method 1: Updating Pi-hole that was installed by a script
|
|||
|
|
|||
|
You will not believe how easy this is. All you have to do is run the following command in your terminal!
|
|||
|
|
|||
|
```
|
|||
|
pihole -up
|
|||
|
```
|
|||
|
|
|||
|
Of course, you have to run this command on the device where you have installed Pi-hole. In other words, you may have to [SSH into your Raspberry Pi][2] or router to run the above-mentioned command.
|
|||
|
|
|||
|
Doing so will update Pi-hole. Below is the output of running the `pihole -up` command on my computer:
|
|||
|
|
|||
|
```
|
|||
|
$ pihole -up
|
|||
|
[✓] Update local cache of available packages
|
|||
|
[i] Existing PHP installation detected : PHP version 8.1.2-1ubuntu2.8
|
|||
|
[✓] Checking for git
|
|||
|
[✓] Checking for iproute2
|
|||
|
[✓] Checking for dialog
|
|||
|
[✓] Checking for ca-certificates
|
|||
|
|
|||
|
[i] Checking for updates...
|
|||
|
[i] Pi-hole Core: up to date
|
|||
|
[i] Web Interface: up to date
|
|||
|
[i] FTL: up to date
|
|||
|
|
|||
|
[✓] Everything is up to date!
|
|||
|
```
|
|||
|
|
|||
|
💡Though I haven’t encountered this myself, it is still a possibility that Pi-hole might require updates for _other_ packages (like PHP) be installed. So try and run the update command that is applicable for your package manager on a regular basis. Keeping other packages up-to-date is _just as important_ ;)
|
|||
|
|
|||
|
#### Optional: Automate Pi-hole update with cron job
|
|||
|
|
|||
|
This says that everything is up to date. But how can a normal person remember to keep everything up to date? Fret not! We can create a cron job to automatically update Pi-hole every day.
|
|||
|
|
|||
|
But before we edit the cron job, let us find the absolute path of the `pihole` command. This can be done either using the `which` command or the `command` command. You only need to run either one of the two commands listed below:
|
|||
|
|
|||
|
```
|
|||
|
command -v pihole
|
|||
|
which pihole
|
|||
|
```
|
|||
|
|
|||
|
Executing either of the commands listed above will give you the absolute path to the `pihole` command. In my case, the absolute path for the `pihole` command is `/usr/local/bin/pihole`.
|
|||
|
|
|||
|
Next, we will edit the [cron job][3]. To edit cron jobs, type the following command in your terminal (please do **NOT** use `sudo`):
|
|||
|
|
|||
|
```
|
|||
|
crontab -e
|
|||
|
```
|
|||
|
|
|||
|
Doing so will open a file in either the `nano` editor or the `vim` editor. Next, _append_ the following lines to the currently opened file:
|
|||
|
|
|||
|
```
|
|||
|
0 1 * * * /usr/local/bin/pihole -up
|
|||
|
```
|
|||
|
|
|||
|
All you need to do now is to save and exit the editor.
|
|||
|
|
|||
|
What we just did was that we made updating Pi-hole an automatic task. This will automatically run the `pihole up` command at 01:00 hours, every day.
|
|||
|
|
|||
|
### Method 2: Update Pi-hole that was installed via Podman or Docker
|
|||
|
|
|||
|
If you installed Pi-hole using either Podman or Docker, all you can do initially is to pull the image.
|
|||
|
|
|||
|
⚠️ If you used a `docker-compose.yml` file to create your container, please have it handy because we need to delete the current container and create a new one. (No data or configuration will be changed if volumes are backed up properly or if bind mounts were used.)
|
|||
|
|
|||
|
#### Step 1: Check if a newer image is available
|
|||
|
|
|||
|
To check for updates, you can run either of the following commands based on what you use:
|
|||
|
|
|||
|
```
|
|||
|
# command for Podman users
|
|||
|
podman pull docker.io/pihole/pihole:latest
|
|||
|
|
|||
|
# command for Docker users
|
|||
|
docker pull docker.io/pihole/pihole:latest
|
|||
|
```
|
|||
|
|
|||
|
If there is a newer version of the image, it will be fetched. If a newer version is not available, nothing extra will happen and you should try again later.
|
|||
|
|
|||
|
#### Step 2: Stop and remove the container
|
|||
|
|
|||
|
If a new image was downloaded, we can proceed further. Our next step should be to restart the container. To know which container to restart, we can check the output of the `docker ps` or `podman ps` command.
|
|||
|
|
|||
|
```
|
|||
|
$ docker ps
|
|||
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
|||
|
73528d5ca4e8 docker.io/pihole/pihole:latest 14 hours ago Up 14 hours ago 53/tcp pihole-aditi
|
|||
|
```
|
|||
|
|
|||
|
This shows that I have a container named `pihole-aditi`. Let’s stop and remove this container. This can be done with the following commands:
|
|||
|
|
|||
|
```
|
|||
|
# command for Podman users
|
|||
|
podman stop pihole-aditi
|
|||
|
docker rm pihole-aditi
|
|||
|
|
|||
|
# command for Docker users
|
|||
|
docker stop pihole-aditi
|
|||
|
docker rm pihole-aditi
|
|||
|
```
|
|||
|
|
|||
|
#### Step 4: Create a new container
|
|||
|
|
|||
|
I hope you took my warning seriously and have your `docker-compose.yml` file handy ;)
|
|||
|
|
|||
|
Let’s re-create a new container. You can re-create your container using the following command:
|
|||
|
|
|||
|
```
|
|||
|
docker-compose up -d
|
|||
|
```
|
|||
|
|
|||
|
Please verify that the Pi-hole container is up and running using either the `podman ps` command or the `docker ps` command.
|
|||
|
|
|||
|
#### Step 5: Remove old image(s)
|
|||
|
|
|||
|
Once the Pi-hole container starts up with the updated image, we can remove the old image and free up disk, space.
|
|||
|
|
|||
|
To remove **all the _unused_ images**, use the following command:
|
|||
|
|
|||
|
```
|
|||
|
# command for Podman users
|
|||
|
podman image prune
|
|||
|
|
|||
|
# command for Docker users
|
|||
|
docker image prune
|
|||
|
```
|
|||
|
|
|||
|
Upon running the above command, **all the _unused_** **images** will be removed. **Please take caution with this command.**
|
|||
|
|
|||
|
Done! That was all that we needed to do to update our Pi-hole container.
|
|||
|
|
|||
|
### Conclusion
|
|||
|
|
|||
|
This article goes over the two methods of updating Pi-hole based on the installation method initially used. I have also discussed setting up auto-updates for Pi-hole which was installed using the official script. There is no such option for the container method, unfortunately.
|
|||
|
|
|||
|
Do let me know if you face any issues.
|
|||
|
|
|||
|
--------------------------------------------------------------------------------
|
|||
|
|
|||
|
via: https://itsfoss.com/update-pi-hole/
|
|||
|
|
|||
|
作者:[Abhishek Prakash][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/
|
|||
|
[b]: https://github.com/lkxed
|
|||
|
[1]: https://itsfoss.com/setup-pi-hole/
|
|||
|
[2]: https://itsfoss.com/ssh-into-raspberry/
|
|||
|
[3]: https://itsfoss.com/cron-job/
|