Audit và quản lý dịch vụ nền trên OpenWrt
Trước khi cài DNS, DDNS, VPN hoặc service mới, cần biết service nào đang chạy, port nào đang listen, config nằm ở đâu và init script sẽ khởi động ra sao.
1. Ghi nhận trạng thái ban đầu
ubus call system boardcat /etc/openwrt_releasefree -hdf -huci show systemuci show dhcp
Liệt kê init script:
ls -l /etc/init.d/service list 2>/dev/null || true
Liệt kê port:
ss -lntup 2>/dev/null || netstat -lntup
Ghi lại port, process, interface bind và service owner trước khi thay đổi.
2. Kiểm tra log và cấu hình liên quan
logread | tail -n 100logread -e dnsmasqlogread -e netifdps w
Nếu chuẩn bị thay DNS, phải xác định dnsmasq đang cấp DHCP, làm DNS forwarder hay cả hai. Không dừng nó chỉ vì một hướng dẫn bên ngoài yêu cầu; có thể làm toàn LAN mất DHCP.
3. Kiểm tra package feed
opkg updateopkg list-installed
Trên release dùng apk, dùng công cụ package tương ứng của release. Không trộn feed khác phiên bản hoặc kiến trúc. Kiểm tra dung lượng trước khi cài:
df -h /overlay /
Nếu package cần nhiều storage, dùng USB/extroot theo tài liệu đúng target thay vì xóa file hệ thống.
4. Cài và test service theo từng giai đoạn
- Ghi lại config và port hiện tại:
cp -a /etc/config /tmp/config.before-servicess -lntup 2>/dev/null || netstat -lntup
- Cài package đúng feed/release.
- Tạo config tối thiểu, bind vào IP/interface dự kiến; không bind
0.0.0.0nếu chỉ cần LAN. - Chạy foreground/test mode nếu service hỗ trợ để đọc lỗi.
- Kiểm tra port chưa bị chiếm:
ss -lntup 2>/dev/null || netstat -lntup
- Chỉ khi service trả lời đúng mới enable init script:
/etc/init.d/SERVICE enable/etc/init.d/SERVICE start/etc/init.d/SERVICE status
Thay SERVICE bằng tên thật; không chạy nguyên placeholder.
5. Quản lý service
Các thao tác init thường gặp:
/etc/init.d/SERVICE start/etc/init.d/SERVICE stop/etc/init.d/SERVICE restart/etc/init.d/SERVICE reload/etc/init.d/SERVICE enable/etc/init.d/SERVICE disable
enable tạo liên kết khởi động cùng hệ thống; start chỉ chạy phiên hiện tại. Sau khi enable, reboot có kiểm soát để xác nhận service thực sự tự khởi động:
/etc/init.d/SERVICE enabled/etc/init.d/SERVICE status
6. Đổi port/DNS an toàn
Nếu chuyển DNS hoặc web UI sang port mới:
- Cập nhật service config.
- Cập nhật firewall cho đúng source/destination/port.
- Cập nhật client hoặc DHCP option.
- Reload service.
- Kiểm tra bằng hostname/IP và công cụ phù hợp:
nslookup openwrt.orgnslookup openwrt.org 192.168.1.1dig @192.168.1.1 openwrt.org
Không mở port quản trị ra WAN để test. Nếu service DNS mới thay dnsmasq, giữ phương án DHCP riêng và xác minh lease trước khi stop thành phần cũ.
7. Kiểm tra reboot và rollback
Trước reboot, lưu:
uci export > /tmp/uci-before-service.txtlogread > /tmp/log-before-service.txt
Sau reboot kiểm tra:
uptime/etc/init.d/SERVICE statusss -lntup 2>/dev/null || netstat -lntuplogread -e SERVICE
Nếu lỗi, disable/stop service rồi khôi phục config đã sao lưu:
/etc/init.d/SERVICE disable/etc/init.d/SERVICE stopcp -a /tmp/config.before-service/* /etc/config//etc/init.d/dnsmasq restart/etc/init.d/network restart
Chỉ xóa package sau khi xác định không còn config/data cần giữ; không xóa thủ công file hệ thống để “dọn” lỗi.
Nguồn
Nguồn: OpenWrt Base system.
Bình Luận & Thảo Luận
Góp ý, hỏi đáp và chia sẻ suy nghĩ của bạn