Arpwatch - 监控 Linux 中的以太网活动
Arpwatch 是一款开源计算机软件程序,可帮助您监控以太网流量活动(例如更改 IP 和MAC 地址)强>)在您的网络上并维护以太网/IP地址配对的数据库。
它会生成所注意到的 IP 和 MAC 地址信息配对的日志以及时间戳,因此您可以仔细观察配对活动何时出现在网络上。它还可以选择在添加或更改配对时通过电子邮件向网络管理员发送报告。
Arpwatch 工具对于网络管理员特别有用,可以监视 ARP 活动以检测 ARP 欺骗或意外行为IP/MAC 地址修改。
在 Linux 中安装 Arpwatch
Linux 发行版上未安装 Arpwatch 工具,您需要使用默认包管理器从系统存储库中安装它,如图所示。
sudo apt install arpwatch [On Debian, Ubuntu and Mint]
sudo yum install arpwatch [On RHEL/CentOS/Fedora and Rocky/AlmaLinux]
sudo emerge -a net-analyzer/arpwatch [On Gentoo Linux]
sudo apk add arpwatch [On Alpine Linux]
sudo pacman -S arpwatch [On Arch Linux]
sudo zypper install arpwatch [On OpenSUSE]
安装后,您可以查看最重要的 arpwatch 文件,这些文件的位置根据您的操作系统而略有不同。
- /usr/lib/systemd/system/arpwatch – 用于启动或停止守护进程的 arpwatch 服务。
- /etc/sysconfig/arpwatch – 这是主要的 arpwatch 配置文件。
- /usr/sbin/arpwatch – 通过终端启动和停止工具的二进制命令。
- /var/lib/arpwatch/arp.dat – 这是记录 IP/MAC 地址的主数据库文件。
- /var/log/messages – 日志文件,arpwatch 将任何更改或异常活动写入 IP/MAC。
现在运行以下命令来启动arpwatch服务。
systemctl enable arpwatch
systemctl start arpwatch
systemctl status arpwatch
如何在 Linux 中使用 Arpwatch 命令
要监视特定接口,请键入以下命令以及 -i
和设备名称。
arpwatch -i eth0
因此,每当插入新的 MAC 或特定的 IP 更改其在网络上的 MAC 地址时,您都会注意到“/var/log/syslog”或“/”中的系统日志条目使用 tail 命令查看 var/log/message' 文件。
tail -f /var/log/messages
样本输出
Apr 15 12:45:17 tecmint arpwatch: new station 172.16.16.64 d0:67:e5:c:9:67
Apr 15 12:45:19 tecmint arpwatch: new station 172.16.25.86 0:d0:b7:23:72:45
Apr 15 12:45:19 tecmint arpwatch: new station 172.16.25.86 0:d0:b7:23:72:45
Apr 15 12:45:19 tecmint arpwatch: new station 172.16.25.86 0:d0:b7:23:72:45
Apr 15 12:45:19 tecmint arpwatch: new station 172.16.25.86 0:d0:b7:23:72:45
上面的输出显示了一个新的工作站。如果进行任何更改,您将得到以下输出。
Apr 15 12:45:17 tecmint arpwatch: changed station 172.16.16.64 0:f0:b8:26:82:56 (d0:67:e5:c:9:67)
Apr 15 12:45:19 tecmint arpwatch: changed station 172.16.25.86 0:f0:b8:26:82:56 (0:d0:b7:23:72:45)
Apr 15 12:45:19 tecmint arpwatch: changed station 172.16.25.86 0:f0:b8:26:82:56 (0:d0:b7:23:72:45)
Apr 15 12:45:19 tecmint arpwatch: changed station 172.16.25.86 0:f0:b8:26:82:56 (0:d0:b7:23:72:45)
Apr 15 12:45:19 tecmint arpwatch: changed station 172.16.25.86 0:f0:b8:26:82:56 (0:d0:b7:23:72:45)
您还可以使用以下命令检查当前的 ARP 表。
arp -a
样本输出
linux教程 (172.16.16.94) at 00:14:5e:67:26:1d [ether] on eth0
? (172.16.25.125) at b8:ac:6f:2e:57:b3 [ether] on eth0
如果您想向自定义电子邮件 ID 发送警报,请打开主配置文件“/etc/sysconfig/arpwatch”并添加电子邮件,如下所示。
-u <username> : defines with what user id arpwatch should run
-e <email> : the <email> where to send the reports
-s <from> : the <from>-address
OPTIONS="-u arpwatch -e [email -s 'root (Arpwatch)'"
以下是连接新 MAC 时的电子邮件报告示例。
hostname: centos
ip address: 172.16.16.25
interface: eth0
ethernet address: 00:24:1d:76:e4:1d
ethernet vendor: GIGA-BYTE TECHNOLOGY CO.,LTD.
timestamp: Monday, April 15, 2022 15:32:29
以下是当 IP 更改其 MAC 地址时的电子邮件报告示例。
hostname: centos
ip address: 172.16.16.25
interface: eth0
ethernet address: 00:56:1d:36:e6:fd
ethernet vendor: GIGA-BYTE TECHNOLOGY CO.,LTD.
old ethernet address: 00:24:1d:76:e4:1d
timestamp: Monday, April 15, 2022 15:43:45
previous timestamp: Monday, April 15, 2022 15:32:29
delta: 9 minutes
正如您在上面看到的,它记录了主机名、IP地址、MAC地址、供应商名称和时间戳。
有关更多信息,请通过在终端上点击“man arpwatch”来查看 arpwatch 手册页。
man arpwatch