1.到 http://www.isc.org/index.pl?/sw/dhcp/
下载dhcp-3.0.5, 解压后生成dhcp-3.0.5目录,
进入该目录执行./configure,该命令生成work.linux-2.2目录。
进入这个work.linux-2.2目录后,在编译时指定我们的交叉编译器,
make "CC=/usr/local/arm/3.4.1/bin/arm-linux-gcc -static"
注:如果编译器是2.95.3会出现一大堆的重定义,所以建议用3.3.2版本的编译器。-static是把dhclient编译器成静态的。
由于我们不想生成的dhclient太大,所以修改work.linux-2.2中,每一个子目录下的Makefile,把其中的DEBUG -g注释掉,
执行编译通过后,在work.linux-2.2/client中,生成的dhclient就是我们想要的了。
[root@localhost client]# file dhclient
dhclient: ELF 32-bit LSB executable, ARM, version 1 (ARM), for GNU/Linux 2.0.0, statically linked, not stripped
2.把dhclient 放在/sbin这个目录
(1)dhclient.conf这个文件在只有一个网卡的情况下,可以为空,但在2410上有两个网卡(10M,100M),所以必须指定网卡。其内容如下所示:
#Defaults
timeout 60;
reboot 10;
retry 60;
select-timeout 5;
initial-interval 2;
script "/etc/dhclient-script";
interface "eth0" {
request subnet-mask,
broadcast-address,
routers,
domain-name-servers,
domain-name,
host-name;
require domain-name-servers;
}
(2)dhclient-script 放在 /etc下 chmod +x /etc/dhclient-script
(3)
#/var/state/dhcp/dhclient.lease 上有dhcp服务器反馈的信息.2410上没有这个目录,所以要新建这个目录
设置好这4个文件好,执行
# ./dhclient eth0
Internet Systems Consortium DHCP Client V3.0.5
Copyright 2004-2006 Internet Systems Consortium.
All rights reserved.
For info, please visit http://www.isc.org/sw/dhcp/
Listening on LPF/eth0/00:01:5d:68:7a:0f
Sending on LPF/eth0/00:01:5d:68:7a:0f
Sending on Socket/fallback
DHCPREQUEST on eth0 to 255.255.255.255 port 67
DHCPACK from 192.168.1.1
bound to 192.168.1.127 -- renewal in 2982 seconds.
成功地绑定到192.168.1.127
# ifconfig
eth0 Link encap:Ethernet HWaddr 00:01:5D:68:7A:0F
inet addr:192.168.1.127 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:13 errors:0 dropped:0 overruns:0 frame:0
TX packets:2 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:100
RX bytes:4712 (4.6 kb) TX bytes:0 (0.0 b)
Interrupt:37 Base address:0x300
3.dhclient自生成的另外一些相关信息
(1)/var/run/dhclient.pid
dhclinet 的id号
# cat /var/run/dhclient.pid
234
(2) /etc/resolv.conf
dhclient 获得的DNS
# cat /etc/resolv.conf
search domain
nameserver 210.34.0.14
nameserver 210.34.0.18
(3)var/state/dhcp/dhclient.leases
dhclient从DHCP服务器中获得的全部相关信息
#cat /var/state/dhcp/dhclient.leases
lease {
interface "eth0";
fixed-address 192.168.1.127;
option subnet-mask 255.255.255.0;
option dhcp-lease-time 7200;
option routers 192.168.1.1;
option dhcp-option-overload 3;
option dhcp-message-type 5;
option dhcp-server-identifier 192.168.1.1;
option domain-name-servers 210.34.0.14,210.34.0.18;
option domain-name "domain";
renew 5 2003/6/13 17:24:26;
rebind 5 2003/6/13 18:15:14;
expire 5 2003/6/13 18:30:14;
}
lease {
interface "eth0";
fixed-address 192.168.1.127;
option subnet-mask 255.255.255.0;
option routers 192.168.1.1;
option dhcp-lease-time 7200;
option dhcp-option-overload 3;
option dhcp-message-type 5;
option domain-name-servers 210.34.0.14,210.34.0.18;
option dhcp-server-identifier 192.168.1.1;
option domain-name "domain";
renew 5 2003/6/13 17:58:58;
rebind 5 2003/6/13 18:54:16;
expire 5 2003/6/13 19:09:16;
}
在编译内核时候要注意选中:
内核必须支持
CONFIG_PACKET (packet socket)
CONFIG_FILTER (socket filtering)
在编译内核时,在network option中选择。
补充: