转自 红茶三杯
一、机制概述
二、Option82
基本的交互过程如下(下面描述的过程与上面的配图无关):
- DHCP client广播DHCP request
- 交换机收到DHCP request,它在报文中插入option82信息(当然,要你先做了相应的配置后),在插入的信息中,remote-ID suboption是该交换机的MAC;circuit-ID suboption是收到DHCP request报文的接口ID。
- 如果交换机上还部署了DHCP relay,那么交换机将中继地址也添加进DHCP报文中
- 交换机将携带了option82信息的DHCP报文转发给DHCP服务器
- DHCP服务器接收到了DHCP报文,如果这台服务器是能够识别option82的,那么它将根据option82中携带的信息,来为客户端分配IP地址,以及选择相应的策略。然后服务器回应一个DHCP包,其中也包含option82信息。
- 交换机收到该DHCP报文后,发现报文的option82信息正是从本地始发,交换机将option82信息移除后,将DHCP报文转发给DHCP client。
在上述事件的发生过程中,下面字段的内容不会发生改变:
- Circuit-ID suboption fields
- Remote-ID suboption fields
Option报文结构:
DHCP option 82又称为DHCP中继代理信息选项(Relay Agent Information Option),是DHCP报文中的一个选项,其编号为82。rfc3046定义了option 82,选项位置在option 255之前而在其它option之后。
CODE:82
LEN:Agent Information field的字节数,不包含code及len字段的长度
Option82可包含多个suboption,rfc3046定义了如下两个:
Subopt:子选项编号,如果是circuit ID则值为1,remote ID则值为2
Len:Sub-option Value的字节个数,不包括SubOpt和Len字段的两个字节
option82子选项1:即Circuit ID,它表示接收到的DHCP请求报文来自的电路标识,这个标识只在中继代理节点内部有意义,在服务器端不可以解析其含义,只作为一个不具含义的标识使用。一般情况下,默认是接收到DHCP请求报文的接入交换机VlanID加接入二层端口名称,如Vlan2+Ethernet0/0/10,也可以由用户指定自己的代理电路ID。通常子选项1与子选项2要共同使用来标识DHCP客户端的信息。
option82子选项2:即 Remote ID,一般情况下为插入该option82信息的接入层交换机的MAC。
CISCO注释:If the DHCP relay agent is enabled but DHCP snooping is disabled, the DHCP option-82 data insertion feature is not supported.
三、DHCP Snooping Binding Database
SW1#show ip dhcp snooping binding
MacAddress ipAddress Lease(sec) Type VLAN Interface
——- ———– ———- ————- —- ——————–
00:B0:64:04:09:99 192.168.10.1 86025 dhcp-snooping 10 FastEthernet0/1
Total number of bindings: 1
配置命令非常简单,全局命令:
SW2(config)#ip dhcp snooping database ?
由于flash空间非常有限,因此建议将文件存储在TFTP服务器上。当部署在TFTP服务器上时,注意先创建一个空的文件以对应配置命令中的URL,这个文件用于dhcp snooping bingding database的写入(视具体设备而定)。
形成的文件的格式如下:
TYPE DHCP-SNOOPING
VERSION 1
BEGIN
…
…
END
下面是一个例子:
2bb4c2a1
TYPE DHCP-SNOOPING
VERSION 1
BEGIN
192.1.168.1 3 0003.47d8.c91f 2BB6488E interface-id 21ae5fbb
192.1.168.3 3 0003.44d6.c52f 2BB648EB interface-id 1bdb223f
192.1.168.2 3 0003.47d9.c8f1 2BB648AB interface-id 584a38f0
END
四、配置示例
1.实验1:基础实验
PC属于VLAN10,网关在SW2上。DHCPserver属于VLAN100,网关在SW2上。
SW1为接入层交换机,部署DHCP snooping,将Fa0/24定义为trust接口。
SW2为核心层交换机,部署DHCP relay
DHCPserver的配置如下:
no ip routing
ip default-gateway 192.168.100.254
Interface fast0/0
Service dhcp
Ip dhcp pool vlan10
SW1的配置如下:
vlan 10
!
ip dhcp snooping !! 全局开启DHCP snooping
ip dhcp snooping vlan 10 !! vlan10激活DHCP snooping
no ip dhcp snooping information option !! 不写入option82
!
Interface fast0/1
interface fast0/24
SW2的配置如下:
vlan 10
vlan 100
!
Interface fast0/1
interface fast0/24
Interface vlan 10
Interface vlan 100
实验结果:
PC获取到了地址,在SW1上查看dhcp snooping bingding databsae:
SW1#show ip dhcp snooping binding
MacAddress ipAddress Lease(sec) Type VLAN Interface
—— ————— ———- ———- —- ——————-
00:B0:64:04:09:99 192.168.10.1 86025 dhcp-snooping 10 FastEthernet0/1
Total number of bindings: 1
2.实验2:接入交换机插入option82,核心交换机做中继
在SW1上开启DHCP snooping,同时不去no ip dhcp snooping information option,也就是插入option82。
其他设备配置与上一个实验相同,发现PC机无法获取地址,通过在网关设备上,也即是SW2上debug会发现报错:relay information option exists, but giaddr is zero。giaddr字段意思为该报文做经过的第一个DHCP中继代理的IP地址。
在SW2上增加配置:(全局配置模式)ip dhcp relay information trust-all
或:
Interface vlan 10
上述命令,将使交换机接受携带option82信息,同时giaddr为0的dhcp报文,然后做中继。
如此一来即可成功获取地址。
SW1的配置如下:
vlan 10
!
ip dhcp snooping
ip dhcp snooping vlan 10
Interface fast0/1
interface fast0/24
SW2的配置如下:
vlan 10
vlan 100
!
ip dhcp relay information trust-all
Interface fast0/1
interface fast0/24
Interface vlan 10
Interface vlan 100
3.实验3:接入层交换机插入option82,上游核心交换机也开启dhcp snooping
接入层交换机SW1开启dhcp snooping,插入option82;
核心层交换机SW2也开启dhcp snooping,默认所有端口都是untrust的,这时如果SW2的fast0/24口收到携带了option82的dhcp报文,则丢弃。解决办法之一,是将SW2的fast0/24口配置为trust接口,但是这么一来通过该trust接口收到的dhcp报文,是不会创建dhcp snooping binding表项的。另一个方法是,使用命令:ip dhcp snooping information option allow-untrusted。这条命令放行携带了option82的DHCP报文,同时会在本地创建dhcp snooping binding表项。
SW1的配置如下:
vlan 10
!
ip dhcp snooping
ip dhcp snooping vlan 10
Interface fast0/1
interface fast0/24
SW2的配置如下:
vlan 10
vlan 100
!
ip dhcp snooping information option allow-untrusted
ip dhcp relay information trust-all
Interface fast0/1
interface fast0/24
Interface vlan 10
Interface vlan 100
4.无DHCP中继环境中,option82及相关问题
这个环境比较简单,PC与DHCP服务器同处一个VLAN,我主要想证实一下普通交换机对携带了option82的DHCP包的处理情况。
SW1仍然开启dhcp snooping,同时插入option82
SW2将服务器划入与PC相同的VLAN,相当于纯做透传。
其中SW1的配置如下:
vlan 10
!
ip dhcp snooping
ip dhcp snooping vlan 10
Interface fast0/1
interface fast0/24
SW2的配置如下:
vlan 10
!
Interface fast0/1
interface fast0/24
Interface vlan 10
DHCP server的配置就是常规配置,这里不再赘述。
实验的结果是,PC无法获取地址。
我们分析一下,SW1将PC发出来的DHCP 请求消息插入option82,随后发给SW2。通过SW2上的debug信息我们发现:
*Mar 16 17:09:21.858: DHCPD: inconsistent relay information.
*Mar 16 17:09:21.858: DHCPD: relay information option exists, but giaddr is zero.
SW2意识到,DHCP报文中有中继信息选项,也就是option82,但是giaddr是全0。SW2虽然意识到了这个问题,但还是乖乖将这个数据交给了DHCPserver,通过在DHCPserver上的debug信息:
*Mar 4 07:02:23.473: DHCPD: inconsistent relay information.
*Mar 4 07:02:23.473: DHCPD: relay information option exists, but giaddr is zero.
显然,DHCP服务器也意识到了上面的问题,它采取的动作是,忽略这个DHCP请求。因此PC无法获取地址。
解决的办法之一,是SW1不插入opiton82,另一个方法,是在DHCPserver上,使用配置:
(全局配置模式)ip dhcp relay information trust-all
或:
Interface fast0/0
思路和实验2一样。这样一来SW2会接受这些DHCP报文并进行处理,PC就能够获取到地址了。
5.其他配置
ip dhcp snooping limit rate rate
ip dhcp snooping verify mac-address
Configure the switch to verify that the source MAC address in a DHCP packet received on untrusted ports matches the client hardware address in the packet. The default is to verify that the source MAC address matches the client hardware address in the packet.
ip dhcp snooping binding mac-address vlan vlan-id ip-address interface interface-id expiry seconds
静态配置一条dhcp snooping bingding dabase表项,该命令是在特权模式下配置。