已经忙了将近两个星期的dhcp 包解析,整个过程中option 82包的解析费掉的时间最多,因为我花了很久才抓到这个包,之前的开发过程没有写过日志,option82包的解析,我决定写点东西,一为备忘,二为纪念我的08年阳历年。
option82包是dhcp包option部分的一项,具体内容可以参考rfc3046。
这个包里面包括了交换机、dhcp客户端所在vlan以及端口号 ,这些信息对于某些应用是非常重要的。
本文的重点是如何让交换机启动填充option82。
1、交换机配置(2950)
configure terminal
ip dhcp snooping
ip dhcp snooping vlan 1
ip dhcp snooping information option
以上为交换机全局配置,接着配置dhcp server所连接的接口,这里是2
interface f0/2
设置该接口为信任接口
p dhcp snooping trust
ip dhcp snooping limit rate 1000end
show running-config
copy running-config startup-configshow ip dhcp snooping
确保 dhcp客户端所连接接口是un trust的,否则交换机不会填充option82.
交换机上配置结束
2、配置dhcpd.
vim /etc/dhcpd.conf
看到内容如下:
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
#
ok,我们来打开/usr/share/doc/dhcp*/dhcpd.conf.sample,内容是:
ddns-update-style interim;
ignore client-updates;subnet 192.168.0.0 netmask 255.255.255.0 {
# — default gateway
option routers 192.168.0.1;
option subnet-mask 255.255.255.0;option nis-domain “domain.org”;
option domain-name “domain.org”;
option domain-name-servers 192.168.1.1;option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# — Selects point-to-point node (default is hybrid). Don’t change this unless
# — you understand Netbios very well
# option netbios-node-type 2;range dynamic-bootp 192.168.0.128 192.168.0.254;
default-lease-time 21600;
max-lease-time 43200;# we want the nameserver to appear at a fixed address
host ns {
next-server marvin.redhat.com;
hardware ethernet 12:34:56:78:AB:CD;
fixed-address 207.175.42.254;
}
}
然后我们直接复制这个文件覆盖/etc/dhcpd.conf
然后修改为:
ddns-update-style interim;
ignore client-updates;subnet 192.168.1.0 netmask 255.255.255.0 {
# — default gateway
option routers 192.168.1.1;
option subnet-mask 255.255.255.0;option nis-domain “domain.org”;
option domain-name “domain.org”;
option domain-name-servers 192.168.1.1;option time-offset -18000; # Eastern Standard Time
# option ntp-servers 192.168.1.1;
# option netbios-name-servers 192.168.1.1;
# — Selects point-to-point node (default is hybrid). Don’t change this unless
# — you understand Netbios very well
# option netbios-node-type 2;range dynamic-bootp 192.168.1.128 192.168.1.254;
default-lease-time 21600;
max-lease-time 43200;# we want the nameserver to appear at a fixed address
host ns {
next-server marvin.redhat.com;
hardware ethernet 00:16:D3:B5:C4:9A;
fixed-address 192.168.1.101;
}
}
简单说明一下:
# — default gateway 是设置网关相关信息。
range dynamic-bootp 地址池
# we want the nameserver to appear at a fixed address 依据MAC地址固定绑定ip。
3. 打开wireshark, 设置filter: udp and (port 67 or port 68),开启监听
让dhcp客户端来一把dhcp请求,这时候wireshark就会看到已经被填充了option 82的包。
Option: (t=82,l=18) Agent Information Option
4、收工,准备c程序解包。