ARP 攻擊(ARP 欺騙/毒化)透過偽造 ARP 回應將攻擊者 MAC 綁定至網關 IP,導致流量劫持。Linux 下可透過靜態 ARP、arptables 過濾、arping 主動宣告三層防禦。
Gateway IP → Attacker MAC
# 永久生效 (需網路服務支援)
# /etc/ethers 格式: MAC IP
echo "aa:bb:cc:dd:ee:ff 192.168.1.1" >> /etc/ethers
# /etc/rc.local 或 NetworkManager dispatcher 腳本
arp -s 192.168.1.1 aa:bb:cc:dd:ee:ff
# 暫時生效
arp -s 192.168.1.1 aa:bb:cc:dd:ee:ff -i eth0
# 查看當前 ARP 表
arp -n
ip neigh show
缺點:無法保護網關本身,僅保護單一主機;大型網路維護成本高。
# 安裝
yum install -y arptables # 或 apt install arptables
# 只允許合法網關 MAC 回應
arptables -A INPUT --source-mac ! aa:bb:cc:dd:ee:ff -j DROP
arptables -A INPUT --destination-ip 192.168.1.1 --source-mac ! aa:bb:cc:dd:ee:ff -j DROP
# 記錄可疑 ARP
arptables -A INPUT -j LOG --log-prefix "ARP_DROP: "
# 儲存規則
arptables-save > /etc/arptables.rules
# 開機載入 (systemd service 或 rc.local)
arptables-restore < /etc/arptables.rules
定期發送免費 ARP (Gratuitous ARP) 宣告真實 IP-MAC 綁定,覆蓋偽造項目。
# 語法
arping -U -I <介面> -s <本機IP> <目標IP/網關IP>
# 範例:eth0 介面 IP 192.168.1.100,網關 192.168.1.1
arping -U -I eth0 -s 192.168.1.100 192.168.1.1
# 週期性發送 (每 10 秒)
watch -n 10 "arping -U -I eth0 -s 192.168.1.100 192.168.1.1"
# 系統服務化 (/etc/systemd/system/arping-announce.service)
[Unit]
Description=Periodic Gratuitous ARP Announcement
After=network-online.target
[Service]
Type=simple
ExecStart=/bin/bash -c 'while true; do arping -U -I eth0 -s 192.168.1.100 192.168.1.1; sleep 10; done'
Restart=always
[Install]
WantedBy=multi-user.target
# 監控 ARP 表異常變更
watch -n 5 "arp -n | grep -v incomplete | sort -k3"
# 使用 arpwatch 記錄 IP-MAC 變更並郵件通知
yum install -y arpwatch
systemctl enable --now arpwatch
# 配置 /etc/arpwatch.conf 設定監控介面與郵件目標
綜合部署「主機靜態綁定 + arptables 核心過濾 + arping 主動宣告 + 交換機 DAI/DHCP Snooping」四層防禦,可將 ARP 攻擊風險降至最低。