dhcpd動態獲取ip地址,對於小型局域網很便利的。在不大的網絡社會靜態ip也是不錯的!html
環境 vim
centos6.5 10.10.24.1 (dns-server) centos
winxp sp3 服務器
(client) 網段 10.10.24.0/24網絡
0一、設置主機名dom
hostname dns.mvpbang.comui
vim /etc/sysconfig/networkspa
HOSTNAME=dns.mvpbang.comrest
/etc/hosts 10.10.24.1 dns.mvpbang.com #設置主機名解析router
0二、配置靜態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
0三、安裝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"; }