Linux系統下防止 ARP 欺騙_綁定IP地址和MAC地址
2020-07-08 13:08:29
供稿:網友
一、約定
1、網關上已經對下面所帶的機器作了綁定。網關IP:192.168.1.1 MAC:00:02:B3:38:08:62
2、要進行綁定的Linux主機IP:192.168.1.2 MAC:00:04:61:9A:8D:B2二、綁定步驟
1、先使用arp和arp -a查看一下當前ARP緩存列表
[root@ftpsvr ~]# arp
Address HWtype HWaddress Flags Mask Iface
192.168.1.234 ether 00:04:61:AE:11:2B C eth0
192.168.1.145 ether 00:13:20:E9:11:04 C eth0
192.168.1.1 ether 00:02:B3:38:08:62 C eth0說明:
Address:主機的IP地址
Hwtype:主機的硬件類型
Hwaddress:主機的硬件地址
Flags Mask:記錄標志,“C“表示arp高速緩存中的條目,“M“表示靜態的arp條目。[root@ftpsvr ~]# arp -a
? (192.168.1.234) at 00:04:61:AE:11:2B [ether] on eth0
? (192.168.1.1) at 00:16:76:22:23:86 [ether] on eth02、新建一個靜態的mac--〉ip對應表文件:ip-mac,將要綁定的IP和MAC地下寫入此文件,格式為 ip mac。
[root@ftpsvr ~]# echo ’192.168.1.1 00:02:B3:38:08:62 ’ 〉 /etc/ip-mac
[root@ftpsvr ~]# more /etc/ip-mac
192.168.1.1 00:02:B3:38:08:623、設置開機自動綁定
[root@ftpsvr ~]# echo ’arp -f /etc/ip-mac ’ 〉〉 /etc/rc.d/rc.local4、手動執行一下綁定
[root@ftpsvr ~]# arp -f /etc/ip-mac5、確認綁定是否成功
[root@ftpsvr ~]# arp
Address HWtype HWaddress Flags Mask Iface
192.168.0.205 ether 00:02:B3:A7:85:48 C eth0
192.168.1.234 ether 00:04:61:AE:11:2B C eth0
192.168.1.1 ether 00:02:B3:38:08:62 CM eth0[root@ftpsvr ~]# arp -a
? (192.168.0.205) at 00:02:B3:A7:85:48 [ether] on eth0
? (192.168.1.234) at 00:04:61:AE:11:2B [ether] on eth0
? (192.168.1.1) at 00:02:B3:38:08:62 [ether] PERM on eth0從綁定前后的ARP緩存列表中,可以看到網關(192.168.1.1)的記錄標志已經改變,說明綁定成功。三、添加信任的Windows主機(192.168.1.10)
1、Linux主機(192.168.1.2)上操作
[root@ftpsvr ~]# echo ’192.168.1.10 00:04:61:AE:09:14’ 〉〉 /etc/ip-mac[root@ftpsvr ~]# arp -f /etc/ip-mac2、Windows主機(192.168.1.10)上操作
1)清除ARP緩存
C:/Documents and Settings/Administrator〉arp -d2)綁定Linux主機的IP和MAC地址
C:/Documents and Settings/Administrator〉arp -s 192.168.1.2 00-04-61-9A-8D-B2你可以將上面2個步驟寫在一個BAT(批處理)文件中,這樣做的好處是,今后如果要增加其它機器的綁定,只需維護這個文件就可以了。例:
@echo off
arp -d
arp -s 192.168.1.2 00-04-61-9A-8D-B2
exit 注意:Linux和Widows上的MAC地址格式不同。Linux表示為:AA:AA:AA:AA:AA:AA,Windows表示為:AA-AA-AA-AA-AA-AA。