client连接server 用到udp的67,68 端口
dhcp server IP必须是静态配置的。
[[email protected] ~]# yum install dhcp -y
配置文件在
[[email protected] ~]# cd /etc/dhcp/
[[email protected] dhcp]# ls
dhclient.d dhclient-exit-hooks.d dhcpd6.conf dhcpd.conf
查找模板所在位置
rpm -ql dhcp | more
把模板重定向到dhcpd.comf
[[email protected] dhcp]# cat /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample > /etc/dhcp/dhcpd.conf
查看主机分配的域名
search 后面显示为域名
[[email protected] ~]# cat /etc/resolv.conf
; generated by /sbin/dhclient-script
search localdomain aaa.com
nameserver 192.168.130.2
配置文件
option domain-name "example.org"; 分配给client域名
option domain-name-servers ns1.example.org, ns2.example.org; 分配给client的dns地址
default-lease-time 600; 租期
max-lease-time 7200;
每个subnet是一个作用域,可以为不同网段分配地址
subnet 10.5.5.0 netmask 255.255.255.224 {
range 10.5.5.26 10.5.5.30;
option domain-name-servers ns1.internal.example.org;
option domain-name "internal.example.org";
option routers 10.5.5.1; 分配给client的网关
option broadcast-address 10.5.5.31; 广播地址
default-lease-time 600;
max-lease-time 7200;
}
service dhcpd restart
service dhcpd onfigtest 检测语法是否正确
server端查看分配给client的dhcp信息
/var/lib/dhcp
[[email protected] lib]# cd dhcpd/
[[email protected] dhcpd]# ls
dhcpd6.leases dhcpd.leases dhcpd.leases~
[[email protected] dhcpd]# cat dhcpd.leases
在client端查看
/var/lib/dhclient/dhclient-eth0.leases
日志信息
Aug 20 11:13:05 www kernel: ADDRCONF(NETDEV_UP): eth0: link is not ready
Aug 20 11:13:05 www kernel: ADDRCONF(NETDEV_CHANGE): eth0: link becomes ready
Aug 20 11:13:21 www dhcpd: DHCPREQUEST for 192.168.130.140 from 00:0c:29:6c:07:43 via eth0: unknown lease 192.168.130.140.
Aug 20 11:13:28 www dhcpd: DHCPREQUEST for 192.168.130.140 from 00:0c:29:6c:07:43 via eth0: unknown lease 192.168.130.140.
Aug 20 11:13:49 www dhcpd: DHCPDISCOVER from 00:0c:29:6c:07:43 via eth0
Aug 20 11:13:50 www dhcpd: DHCPOFFER on 192.168.130.150 to 00:0c:29:6c:07:43 via eth0
Aug 20 11:13:50 www dhcpd: DHCPREQUEST for 192.168.130.150 (192.168.130.139) from 00:0c:29:6c:07:43 via eth0
Aug 20 11:13:50 www dhcpd: DHCPACK on 192.168.130.150 to 00:0c:29:6c:07:43 via eth0
Aug 20 11:18:01 www dhcpd: DHCPREQUEST for 192.168.130.150 from 00:0c:29:6c:07:43 via eth0
Aug 20 11:18:01 www dhcpd: DHCPACK on 192.168.130.150 to 00:0c:29:6c:07:43 via eth0
mac地址绑定
host test{
hardware ethernet 08:00:07:26:c0:a5;
fixed-address 192.168.130.150;
}
如果服务器有好几张网卡,只让其中一张网卡提供dhcp服务
[[email protected] ~]# vim /etc/sysconfig/dhcpd
# Command line options here
DHCPDARGS='eth0'
网络唤醒
[[email protected] ~]# ether-wake -i eth0 mac 会把mac地址为mac的远程开机
在客户端进行查看
ifconfig eth0
route -n
cat /etc/resolv.conf