基础环境:
0 1 2 3 4 5 6 |
[root@PXE ~]# uname -a Linux PXE 2.6.32-358.el6.x86_64 #1 SMP Fri Feb 22 00:31:26 UTC 2013 x86_64 x86_64 x86_64 GNU/Linux [root@PXE ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:70:00:DA inet addr:1.1.1.13 Bcast:1.1.1.255 Mask:255.255.255.0 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 |
安装过程:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
[root@PXE ~]# rpm -q dhcp package dhcp is not installed [root@PXE ~]# yum install dhcp ===================================================================================================================================== Package Arch Version Repository Size ===================================================================================================================================== Installing: dhcp x86_64 12:4.1.1-49.P1.el6.centos base 822 k Installing for dependencies: portreserve x86_64 0.0.4-9.el6 base 23 k Updating for dependencies: dhclient x86_64 12:4.1.1-49.P1.el6.centos base 319 k dhcp-common x86_64 12:4.1.1-49.P1.el6.centos base 143 k Transaction Summary ===================================================================================================================================== Install 2 Package(s) Upgrade 2 Package(s) [root@PXE ~]# rpm -q dhcp #检查dhcp是否安装 dhcp-4.1.1-49.P1.el6.centos.x86_64 [root@PXE ~]# cp /etc/dhcp/dhcpd.conf /etc/dhcp/dhcpd.conf.$(date +%F) #备份,其实没有内容,养成习惯很重要 ################################默认################################ [root@PXE ~]# cp /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample /etc/dhcp/dhcpd.conf #把模板拷贝过来 [root@PXE ~]# egrep -v "#" /etc/dhcp/dhcpd.conf option domain-name "example.org"; option domain-name-servers ns1.example.org, ns2.example.org; default-lease-time 600; max-lease-time 7200; log-facility local7; subnet 10.152.187.0 netmask 255.255.255.0 { } subnet 10.254.239.0 netmask 255.255.255.224 { range 10.254.239.10 10.254.239.20; option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org; } subnet 10.254.239.32 netmask 255.255.255.224 { range dynamic-bootp 10.254.239.40 10.254.239.60; option broadcast-address 10.254.239.31; option routers rtr-239-32-1.example.org; } 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; option broadcast-address 10.5.5.31; default-lease-time 600; max-lease-time 7200; } host passacaglia { hardware ethernet 0:0:c0:5d:bd:95; filename "vmunix.passacaglia"; server-name "toccata.fugue.com"; } host fantasia { hardware ethernet 08:00:07:26:c0:a5; fixed-address fantasia.fugue.com; } class "foo" { match if substring (option vendor-class-identifier, 0, 4) = "SUNW"; } shared-network 224-29 { subnet 10.17.224.0 netmask 255.255.255.0 { option routers rtr-224.example.org; } subnet 10.0.29.0 netmask 255.255.255.0 { option routers rtr-29.example.org; } pool { allow members of "foo"; range 10.17.224.10 10.17.224.250; } pool { deny members of "foo"; range 10.0.29.10 10.0.29.230; } } ################################默认################################ [root@PXE ~]# cat /etc/dhcp/dhcpd.conf # # DHCP Server Configuration file. # see /usr/share/doc/dhcp*/dhcpd.conf.sample # see 'man 5 dhcpd.conf' # default-lease-time 600; #缺省租用时间 max-lease-time 7200; #最大租用时间 ddns-update-style none; #配置不使用DHCP-DNS动态更新模式,ddns-update-style interim; subnet 1.1.1.0 netmask 255.255.255.0 { #作用域 range dynamic-bootp 1.1.1.50 1.1.1.120; #租用IP地址的范围 option routers 1.1.1.2; #网关地址 option subnet-mask 255.255.255.0; #子网掩码 filename "pxelinux.0"; #如果不是在TFTP根目录下,要写上目录 next-server 1.1.1.13; #tftp服务器地址 } [root@PXE ~]# /etc/init.d/dhcpd start Starting dhcpd: [FAILED] [root@PXE ~]# setenforce 0 #临时关闭selinux [root@PXE ~]# /etc/init.d/dhcpd start Starting dhcpd: [ OK ] [root@PXE ~]# netstat -panu|grep dhc* udp 0 0 0.0.0.0:67 0.0.0.0:* 1445/dhcpd [root@PXE ~]# netstat -tunlp|grep dhc* udp 0 0 0.0.0.0:67 0.0.0.0:* 1445/dhcpd [root@PXE ~]# /etc/init.d/iptables stop or [root@PXE ~]# -A INPUT -m state –state NEW -m udp -p udp –dport 67 -j ACCEPT [root@PXE ~]# -A INPUT -m state –state NEW -m udp -p udp –dport 68 -j ACCEPT [root@PXE ~]# cat /var/lib/dhcpd/dhcpd.leases [root@PXE ~]# grep DHCPOFFER /var/log/messages Jan 22 20:10:37 PXE dhcpd: DHCPOFFER on 1.1.1.50 to 00:0c:29:92:de:53 via eth0 [root@PXE ~]# cat /etc/sysconfig/dhcpd #这个参数貌似没有关系。可以不修改 # Command line options here DHCPDARGS= |
客户端:
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
[root@DHCP-client ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 TYPE=Ethernet ONBOOT=yes NM_CONTROLLED=yes [root@DHCP-client ~]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:92:DE:53 inet addr:1.1.1.50 Bcast:1.1.1.255 Mask:255.255.255.0 lo Link encap:Local Loopback inet addr:127.0.0.1 Mask:255.0.0.0 [root@DHCP-client ~]# cat /var/lib/dhclient/dhclient-eth0.leases lease { interface "eth0"; fixed-address 1.1.1.50; filename "pxelinux.0"; option subnet-mask 255.255.255.0; option routers 1.1.1.2; option dhcp-lease-time 600; option dhcp-message-type 5; option dhcp-server-identifier 1.1.1.13; renew 5 2016/01/22 12:15:36; rebind 5 2016/01/22 12:19:22; expire 5 2016/01/22 12:20:37; } lease { interface "eth0"; fixed-address 1.1.1.50; filename "pxelinux.0"; option subnet-mask 255.255.255.0; option routers 1.1.1.2; option dhcp-lease-time 600; option dhcp-message-type 5; option dhcp-server-identifier 1.1.1.13; renew 5 2016/01/22 12:20:30; rebind 5 2016/01/22 12:24:21; expire 5 2016/01/22 12:25:36; } [root@DHCP-client ~]# |
dhcpd.conf配置文件的详细说明:
全局设置:
0 1 2 3 4 |
ddns-update-style参数:设置DHCP服务器与DNS服务器的动态信息更新模式,一般的DHCP服务器可以不考虑设置该项,但是全局设置中一定要包括ddns-update-style的设置dhcpd才可以正常启动。设置为:interim 表示与DNS互动更新,设置为:none 表示不自动更新。 default-lease-time参数:设置默认租约时间,参数值单位是秒。默认租约时间表示客户端从服务器租用一个IP地址的默认时间,到大时间后客户端会向服务器提出继续租用该IP地址的请求。 max-lease-time参数:设置最大租约时间,参数值单位是秒。当客户端租约的地址到大这个时间,就不能继续租用该IP地址。 option domain-name参数:设置主机所在域的名称,设置的域名和主机名称一起组成主机全名。 option domain-name-servers参数:设置DNS服务器地址,设置后客户机DNS会使用该地址,如果要设置多个DNS地址,用逗号隔开。 |
使用subnet声明设置子网属性:
0 1 2 3 |
subnet后面设置网络地址,netmask后面设置子网掩码。 range参数:是设置subnet中可供动态分配的IP地址范围,参数值一定要是subnet设置的子网之内,否则不能启动。 subnet-mask参数:设置子网掩码,设置子网掩码之后一般不需要再设置网络地址和广播地址。 routers参数:是设置默认网关。 |
使用host声明设置主机属性,通常用于为服务器分配好固定使用的IP地址:
0 1 2 |
host后面需要为DHCP客户端主机设置主机名称。 hardware参数:是设置客户端主机的物理地址(MAC地址),因为通常使用的都是以太网,所以hardware参数类型设置为ethernet。 fixed-address参数:设置在host声明中指定的客户端分配固定使用的IP地址。 |
参考资料:https://www.isc.org/downloads/dhcp/
参数转载:http://www.centoscn.com/image-text/config/2015/0420/5219.html SourceByrd's Weblog-https://note.t4x.org/basic/centos-config-dhcp/
申明:除非注明Byrd's Blog内容均为原创,未经许可禁止转载!详情请阅读版权申明!
Trackbacks