dhcpd动态获取ip地址,对于小型局域网很便利的。在不大的网络社会静态ip也是不错的!
环境
centos6.5 10.10.24.1 (dns-server)
winxp sp3
(client) 网段 10.10.24.0/24
01、设置主机名
hostname dns.mvpbang.com
vim /etc/sysconfig/network
HOSTNAME=dns.mvpbang.com
/etc/hosts 10.10.24.1 dns.mvpbang.com #设置主机名解析
02、配置静态IP(dns-server)
nm-connection-editor #图形化配置IP信息
[root@dns ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
HWADDR=00:0C:29:85:49:C5 //max地址
TYPE=Ethernet
BOOTPROTO=static //静态ip
IPADDR=10.10.24.1
PREFIX=24
GATEWAY=255.255.255.0
DEFROUTE=yes
IPV4_FAILURE_FATAL=yes
IPV6INIT=no NAME=eth1
UUID=e62aaf9b-6c40-4bcc-9afc-ce4dd9bcbfce
ONBOOT=yes //开机自动连接
LAST_CONNECT=1492955485
service network restart #重启下网络服务
ip a/ifconfig
03、安装dhcpd
https://centos.pkgs.org/6/centos-x86_64/dhcp-4.1.1-53.P1.el6.centos.x86_64.rpm.html
https://centos.pkgs.org/6/centos-x86_64/dhcp-common-4.1.1-53.P1.el6.centos.x86_64.rpm.html
dhcp-4.1.1-53.P1.el6.centos.x86_64.rpm
dhcp-common-4.1.1-53.P1.el6.centos.x86_64.rpm
rpm -ivh dhcp*
rpm -qa dhcp
/etc/dhcp/dhcpd.conf #默认配置信息
/usr/share/doc/dhcp-4.1.1
/var/lib/dhcpd/dhcpd.leases #记录了dhcp客户端的信息
#配置参数意义
vim /etc/dhcp/dhcpd.conf
#支持的dhcp动态更新方式(non:不支持;interim:互动更新模式;ad-hoc:特殊更新模式)
ddns-update-style interim;
#ignore client-updates; #忽略客户端更新
#subnet<子网络号> netmask <子网掩码>
subnet 10.10.24.0 netmask 255.255.255.0
{
#指定地址池,10.10.24.100~10.10.24.120范围之内的IP地址动态分配给客户机
range 10.10.24.100 10.10.24.120;
option routers 10.10.24.254; #客户端默认网关
option subnet-mask 255.255.255.0; #指定客户端子网掩码
option domain-name "dns.mvpbang.com"; #指定DNS后缀
option domain-name-servers 10.10.24.1; #DNS服务器地址
option broadcast-address 10.10.24.255; #指定广播地址
default-lease-time 86400; #指定默认租约时间,单位是秒 默认1天
max-lease-time 172800; #指定最长租赁时间,单位是秒
#为网络适配器的物理地址为00:0C:29:23:F5:A2的主机保留指定IP地址或者是打印机
host pc1 {
hardware ethernet 00:0C:29:D4:E7:58;
fixed-address 192.168.1.50;
}
}
错误:
tail -f /var/log/message
启动服务时报错 message Can't chown new lease file: Operation not permitted 服务无法正常启动,
解决:
vim /etc/rc.d/init.d/dhcpd
user=dhcpd
group=dhcpd
改为
user=root
group=root
#重启dhcpd服务
service dhcpd restart
#查看客户端获取ip
[root@dns ~]# tail -f /var/lib/dhcpd/dhcpd.leases
lease 10.10.24.100 { starts 0 2017/04/23 16:11:09; ends 1 2017/04/24 16:11:09; cltt 0 2017/04/23 16:11:09; binding state active; next binding state free; hardware ethernet 00:0c:29:69:5d:52; uid "\001\000\014)i]R"; client-hostname "PC7183-20140621"; }