您的当前位置:首页正文

【网络基础技术】DHCP 技术

2022-05-12 来源:意榕旅游网


四.DHCP服务 占用67号端口

1.检查是否安装DHCP软件包 如果没有则插入光盘后 进入media/的光盘目录安装DHCP

注意:光盘的路经,mount 查看 到vim/yum.re/C-M 设置光盘路经

2.vim /etc/dhcpd.conf 复制dhcp范本文件到/etc目录下,册除原文件,将范本文件重命名

为dhcpd.conf ,然后进行编辑 vim /etc/dhcpd.conf 进入设置dhcp地址范围.子网掩

码.DNS .默认网关.ip地址作用域

3.service dhcpd start 开启dhcp服务

简单的dhcp 服务器(多vlan)

安装

1. yum install dhcp

占用的端口

dhcp服务器使用 UDP协议的 67 端口!

1. netstat -anulp | grep 67

2. udp 0 0 0.0.0.0:67 0.0.0.0:*

11634/dhcpd

配置文件,可以这样 cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf,每个subnet对应一个vlan 一共10个subnet,192.168.50.1-192.168.59.1

1. # cat /etc/dhcpd.conf 2. ddns-update-style interim; 3. ignore client-updates; 4. default-lease-time 86400;

5. max-lease-time 86400; 6.

7. subnet 192.168.0.0 netmask 255.255.255.0 { 8.

9. # --- default gateway

10. range 192.168.0.10 192.168.0.126; 11. option routers 192.168.0.1; 12. option subnet-mask 255.255.255.0; 13.

14. option nis-domain \"domain.org\"; 15. option domain-name \"test\";

16. option domain-name-servers 202.106.46.151,202.106.0.20; 17.

18. option time-offset -18000; # Eastern Standard Time 19. # option ntp-servers 192.168.1.1; 20. # option netbios-name-servers 192.168.1.1;

21. # --- Selects point-to-point node (default is hybrid). Don't change

this unless

22. # -- you understand Netbios very well 23. # option netbios-node-type 2; 24.

25. #range dynamic-bootp 192.168.0.128 192.168.0.254; 26. default-lease-time 21600; 27. max-lease-time 43200; 28.

29. # we want the nameserver to appear at a fixed address 30. host ns {

31. next-server marvin.redhat.com; 32. hardware ethernet 12:34:56:78:AB:CD; 33. fixed-address 207.175.42.254; 34. } 35. } 36.

37. subnet 192.168.51.0 netmask 255.255.255.0 { 38. range 192.168.51.10 192.168.51.99; 39. option routers 192.168.51.1; 40. option subnet-mask 255.255.255.0;

41. option domain-name-servers 202.106.46.151,202.106.0.20; 42. #option netbios-name-ser7ers 192.168.6.10,10.20.6.10; 43. option time-offset -18000; 44. default-lease-time 86400; 45. max-lease-time 86400; 46. }

参数详解 参考了这篇文章

1. ddns-update-style interim; //配置使用过渡性DHCP-DNS互动更新模式 2.

3. ignore client-updates; //忽略客户端更新 4.

5. subnet 192.168.0.0 netmask 255.255.255.0 { //为192.168.0.0子网分配

地址 6.

7. option routers 192.168.0.1; //为客户机指定默认网关 8.

9. option subnet-mask 255.255.255.0; //为客户机指定子网掩码 10.

11. option nis-domain \"domain.org\";//为客户机分配NIS域 12.

13. option domain-name \"domain.org\";//为客户机分配DNS域 14.

15. option domain-name-servers 192.168.1.1;//分配的DNS地址 16.

17. range dynamic-bootp 192.168.0.128 192.168.0.254; //地址池 18.

19. default-lease-time 21600; //默认租约时间(秒) 20.

21. max-lease-time 43200; //最大租约时间(秒) 22. 23. } 24. 25. 26.

27. 注:1)无论您创建一个还是多个作用域,其中必须要有一个作用域在subnet 之后的申明是

该DHCP服务器的IP所在的子网地址,否则DHCP将无法启动,比如DHCP服务器的IP地址是192.168.1.1/24,那么必须有一个这样的作用域: 28.

29. subnet 192.168.1.0 mask 255.255.255.0 { 30. 31. } 32.

33. 2)若有多个DNS,需要用逗号分开,一一列出,如 34.

35. Option domain-name-servers 192.168.1.1,192.168.1.2; 36.

37. 3)若为某一网段分配的地址并不是连续的,我们只需创建多条地址池记录,如: 38.

39. Range dynamic-bootp 192.168.1.1 192.168.1.40; 40.

41. Range dynamic-bootp 192.168.1.61 192.168.1.254; 42.

43. 此时,便可分配192.168.1.0网段中的除去192.168.1.41-192.168.1.60范围的地址。 44. 45. 46.

47. (2)主机的绑定 48.

49. 对于有些客户机,我们总希望它们每次获取的IP都是固定的,这时可以进行主机绑定设

置, 50.

51. host ns{ 52.

53. next-server marvin.redhat.com; //设置用于定义服务器从引

导文件中装入的主机名,用于无盘工作站 54.

55. hardware ethernet 12:34:56:78:AB:CD; //要绑定的DHCP客

户机的MAC地址 56.

57. fixed-address 207.175.42.254; //要固定分配给DHCP客户机

的IP地址 58.

59. } 60. 61. 62.

63. (3)超级作用域 64.

65. 超级作用域主要用在给不同网段的客户机分配地址的情况,配置时,只需要将多个作用域放在

shared-network中即可,其形式如下: 66.

67. shared-network 名称{ 68.

69. subnet 子网地址 netmask 子网掩码 {}; 70.

71. subnet 子网地址 netmask 子网掩码 {}; 72. 73. ...... 74. 75. }

76. 77. 78.

79. (4)服务器选项 80.

81. 如果dhcp中存在多个作用域,而且每个作用域均有一些相同的配置,这时我们可以减少配置

工作量,将那些相同的配置统一放在超级作用域之外,如: 82.

83. shared-network 名称 {}; 84.

85. default-lease-time 21600; 86.

87. max-lease-time 43200; 88.

89. 这样会为不同作用域的主机均设置相同的租约。 90. 91. 92.

93. (5)按照客户机的类别分配IP地址 94.

95. 将客户机按照某种属性分类,根据不同的属性类分配不同范围的地址,如: 96.

97. subnet 192.168.10.0 network 255.255.255.0 { 98.

99. class \"vm\" { 100. 101. 102. 103. 104. 105. 106. 107. 108. 109. 110. 111. 112. 113. 114. 115. 116. 117. 118.

match if substring (hardware,1,3)=00:0c:29

} //根据MAC定义匹配虚拟机的类 pool {

allow members of \"vm\";

range 192.168.10.10 192.168.10.50;

} //为匹配\"vm\"的客户机分配IP pool {

deny members of \"vm\";

range 192.168.10.100 192.168.10.110;

119. 120. 121. 122. 123. 124. 125. 126. 127. 128. 129. 130. 131. 132.

}

} //为不匹配\"vm\"的客户机分配IP

4、语法检查

#service dhcpd configtest

5、启动DHCP服务

#service dhcpd start

dhcpd 日志

相关日志记录在 /var/log/messages,比如下面的!

1. tail /var/log/messages

2. Sep 22 19:29:08 gw-new dhcpd: DHCPDISCOVER from 00:16:d3:46:0b:38 vi

a 192.168.50.1

3. Sep 22 19:29:09 gw-new dhcpd: DHCPOFFER on 192.168.50.99 to 00:16:d3

:46:0b:38 (BJBXHH) via 192.168.50.1

4. Sep 22 19:29:09 gw-new dhcpd: DHCPREQUEST for 192.168.50.99 (192.168

.0.1) from 00:16:d3:46:0b:38 (BJBXHH) via 192.168.50.1

5. Sep 22 19:29:09 gw-new dhcpd: DHCPACK on 192.168.50.99 to 00:16:d3:4

6:0b:38 (BJBXHH) via 192.168.50.1

6. Sep 22 19:44:04 gw-new dhcpd: DHCPREQUEST for 192.168.0.125 from 00:

22:68:1c:83:c3 (KevinChia) via 192.168.58.1: ignored (not authoritative).

使用 dhcpd.log 记录日志

1. vim /etc/syslog.conf

2. local0.* /var/log/dhcpd.log #添加此行 3.

4. vim /etc/dhcpd.conf

5. log-facility local0; #添加此行 6.

7. touch /var/log/dhcpd.log #建立一个空文件 8.

9. /etc/init.d/syslog restart #重启syslog

10. Shutting down kernel logger: [ OK ] 11. Shutting down system logger: [ OK ] 12. Starting system logger: [ OK ] 13. Starting kernel logger: [ OK ] 14. /etc/init.d/dhcpd restart #重启dhcpd

15. Starting dhcpd: [ OK ] 16.

17. tail /var/log/dhcpd.log

18. Sep 23 16:28:20 one dhcpd: Internet Systems Consortium DHCP Server V

3.0.5-RedHat

19. Sep 23 16:28:20 one dhcpd: Copyright 2004-2006 Internet Systems Cons

ortium.

20. Sep 23 16:28:20 one dhcpd: All rights reserved.

21. Sep 23 16:28:20 one dhcpd: For info, please visit http://www.isc.org

/sw/dhcp/

22. Sep 23 16:28:20 one dhcpd: Wrote 10 leases to leases file.

23. Sep 23 16:28:20 one dhcpd: Listening on LPF/eth0/e2:ab:72:55:e2:e2/1

92.168.6/24

24. Sep 23 16:28:20 one dhcpd: Sending on LPF/eth0/e2:ab:72:55:e2:e2/1

92.168.6/24

25. Sep 23 16:28:20 one dhcpd: Sending on Socket/fallback/fallback-net

因篇幅问题不能全部显示,请点此查看更多更全内容