Linux 日志审计与轻量级入侵检测实践

日志是安全排查的第一手资料 系统层面的关键日志位置: /var/log/auth.log(Debian/Ubuntu)或 journalctl -u sshd:登录与认证记录 /var/log/syslog / journalctl:系统级事件 /var/log/nginx/access.log:Web 访问记录 auditd 日志(/var/log/audit/audit.log):文件访问与系统调用审计 快速排查异常登录 # 查看最近登录成功记录 last -20 # 查看登录失败记录 sudo grep "Failed password" /var/log/auth.log | tail -50 # 统计失败登录来源 IP 排名 sudo grep "Failed password" /var/log/auth.log \ | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr | head 使用 auditd 监控关键文件 sudo apt install auditd sudo systemctl enable --now auditd # 监控 /etc/passwd 的写入操作 sudo auditctl -w /etc/passwd -p wa -k passwd_changes # 查询相关审计记录 sudo ausearch -k passwd_changes 规则可写入 /etc/audit/rules.d/audit.rules 实现持久化,重启后仍然生效。 ...

2026-07-27 · 1 min · 128 words · ITNote

Linux 防火墙配置指南:ufw 与 nftables

ufw:面向新手的简化管理 ufw(Uncomplicated Firewall)是对 iptables/nftables 的简化封装,适合快速配置基础规则。 sudo apt install ufw # 默认策略:拒绝入站,允许出站 sudo ufw default deny incoming sudo ufw default allow outgoing # 放行必要端口 sudo ufw allow 22022/tcp # SSH(对应自定义端口) sudo ufw allow 80/tcp sudo ufw allow 443/tcp # 限制某端口的来源 IP 段 sudo ufw allow from 192.168.1.0/24 to any port 8000 sudo ufw enable sudo ufw status verbose nftables:更细粒度的现代方案 nftables 是 iptables 的继任者,语法更统一,规则集也更易维护。 sudo apt install nftables # /etc/nftables.conf table inet filter { chain input { type filter hook input priority 0; policy drop; ct state established,related accept iif lo accept tcp dport 22022 accept tcp dport { 80, 443 } accept # 限制单 IP 新建连接速率,缓解简单的连接洪泛 tcp dport 22022 ct state new limit rate 10/minute accept } chain forward { type filter hook forward priority 0; policy drop; } chain output { type filter hook output priority 0; policy accept; } } sudo nft -f /etc/nftables.conf sudo systemctl enable --now nftables 场景示例:仅内网可访问的 AI 推理服务 将 vLLM 等服务监听在内网接口,或通过防火墙限制外部访问: ...

2026-07-27 · 1 min · 187 words · ITNote