install pi-hole docker on ubuntu 18.04

Pi-hole是一个开源的本来是针对树莓派开发的基于dns的广告过滤软件。在ubuntu上可以直接安装,也可以通过docker安装。通过安装对本地的设置影响比较小,而且便于迁移。

假设已经安装了docker,如果没有安装的话,可以使用下面的命令安装:

sudo apt-get install docker

安装好docker以后,运行如下命令:

sudo docker pull pihole/pihole

运行

sudo docker images 就可以看到刚才下载的docker image

然后运行以下命令:

sudo systemctl disable systemd-resolved.service
sudo systemctl stop systemd-resolved
sudo vi /etc/NetworkManager/NetworkManager.conf
在main部分添加:dns=default,保存退出
sudo mv /etc/resolv.conf /etc/resolv.conf.bak
sudo service network-manager restart

重启network-manager以后,缺省dns变成192.168.1.1。

下面就可以运行pihole的container了。

可以参考这个链接的脚本:

我用的是这个:

sudo docker run -d \
— name pihole \
-p 53:53/tcp -p 53:53/udp \
-p 8080:80 \
-p 443:443 \
-e TZ=”America/Los_Angeles” \
-v “${DOCKER_CONFIGS}/etc-pihole/:/etc/pihole/” \
-v “${DOCKER_CONFIGS}/etc-dnsmasq.d/:/etc/dnsmasq.d/” \
-e ServerIP=”192.168.1.xx" \
— cap-add=NET_ADMIN \
— dns=1.1.1.1 \
— restart=unless-stopped \
pihole/pihole:latest

启动container的时候,遇到一个问题,说是53端口被占用了,所以container没有启动成功。

运行netstat -tunl发现端口53,被ip10.0.3.1占用。运行ifconfig,发现10.0.3.1是被interface lxcbr0使用。

Because LXD is now installed by default, the LXC bridge (lxcbr0) is now started automatically:

Image for post
Image for post

To disable the automatic start of the virtual bridge lxcbr0, adapt /etc/default/lxc-net and set USE_LXC_BRIDGE to false:

root@xenial:~# sed -i "/USE_LXC_BRIDGE/s/true/false/g" /etc/default/lxc-net

This disables the automatic start of the virtual bridge at boot time to turn off and delete the bridge during runtime:

root@xenial:~# ifconfig lxcbr0 down
root@xenial:~# brctl delbr lxcbr0

重启机器,53端口就没有人占用了,可以顺利启动pihole container。

sudo docker logs pihole |grep password

就可以看到登录WebUI的密码。

sudo docker ps可以看到运行的container

CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b7a3d6011343 pihole/pihole:latest “/s6-init” 27 hours ago Up 27 hours (healthy) 0.0.0.0:53->53/udp, 0.0.0.0:53->53/tcp, 0.0.0.0:443->443/tcp, 0.0.0.0:67->67/udp, 0.0.0.0:8080->80/tcp pihole

用这个命令登录到docker里面:

sudo docker exec -it 6adf18811606 /bin/bashpihole -a -p 可以修改密码。

Written by

自由撰稿人,时评人,平等公义追求者

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store