Bookmark

Pi.Alert trong Docker: phát hiện thiết bị lạ trên mạng LAN

Pi.Alert theo dõi thiết bị Wi-Fi/LAN mới xuất hiện và cảnh báo thiết bị lạ hoặc thiết bị “luôn phải online” bị mất. Tôi chạy nó trên Linux Docker host bằng host networking để ứng dụng nhìn được mạng local; vì thế cần cân nhắc quyền truy cập và không mở UI thẳng ra Internet.1

Youtube video player

Video gốc của i12bretro đã được xác nhận title/author qua oEmbed.2

Cài Docker trên Linux

Đăng nhập thiết bị Linux, chạy đúng block source:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# install prerequisites
sudo apt install apt-transport-https ca-certificates curl software-properties-common gnupg-agent -y
# add docker gpg key
curl -fsSL https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release)/gpg | sudo apt-key add -
# add docker software repository
sudo add-apt-repository "deb [arch=$(dpkg --print-architecture)] https://download.docker.com/linux/$(awk -F'=' '/^ID=/{ print $NF }' /etc/os-release) $(lsb_release -cs) stable"
# install docker
sudo apt install docker-ce docker-compose containerd.io -y
# enable and start docker service
sudo systemctl enable docker && sudo systemctl start docker
# add the current user to the docker group
sudo usermod -aG docker $USER
# reauthenticate for the new group membership to take effect
su - $USER

Sau khi re-authenticate để nhận group Docker, kiểm tra docker version và quyền user trước khi đi tiếp.

Chạy Pi.Alert

Tạo thư mục, chạy container tạm để lấy config/database mặc định, copy hai thư mục ra host, xóa container tạm rồi chạy container chính:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# create working directory
mkdir ~/docker/pialert -p
# set ownership on the working directories
sudo chown "$USER":"$USER" ~/docker -R
# run temp pialert container
docker run -d --name=pialert --net=host -e TZ=America/New_York jokobsk/pi.alert
# copy default config files to host
docker cp pialert:/home/pi/pialert/config ~/docker/pialert/
# copy db to host
docker cp pialert:/home/pi/pialert/db ~/docker/pialert/
# remove the temp container
docker rm pialert --force
# run the pialert container
docker run -d --name=pialert --net=host -e TZ=America/New_York -v ~/docker/pialert/db:/home/pi/pialert/db -v ~/docker/pialert/config/:/home/pi/pialert/config/ --restart=unless-stopped jokobsk/pi.alert

--net=host giúp Pi.Alert nhìn các interface của host nhưng cũng mở rộng phạm vi ứng dụng; tôi chỉ chạy trên máy tin cậy và kiểm tra docker inspect pialert.

Mở giao diện và kiểm tra

Mở:

http://DNSorIP:20211/pialert

Trang chào mừng xác nhận container hoạt động. Nguồn lưu ý cron của Pi.Alert mặc định chạy mỗi 5 phút để tìm thiết bị mới; tôi kiểm tra log, database và danh sách thiết bị trước khi coi cảnh báo là đúng.

Backup và giới hạn

Backup ~/docker/pialert/config~/docker/pialert/db trước khi nâng image. Host networking không tự tạo firewall boundary, và nhận diện thiết bị theo MAC/IP có thể thay đổi khi client dùng random MAC. Pi.Alert là tín hiệu giám sát, không thay thế firewall, IDS hoặc VLAN isolation.

Nguồn


  1. https://i12bretro.github.io/tutorials/0780.html — i12bretro tutorial 0780. Tutorial được biên tập độc lập từ numbered HTML page; host networking và cron 5 phút được giữ lại. ↩︎

  2. https://www.youtube.com/watch?v=qpDptKzTepc — Running Pi.Alert - A Network Intrusion Monitor - Containerized in Docker — i12bretro ↩︎


0 Bình luận

Góp Ý / Bình Luận / Đánh giá