电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 1787 人浏览分享

centos6.8搭建dhcp服务器

[复制链接]
1787 0
本帖最后由 zhaorong 于 2017-3-7 17:17 编辑

一、安装dhcp软件


  1. [root@dns-server ~]# yum install dhcp -y
复制代码

二、配置dhcp参数


  1. [root@dns-server ~]# cat /etc/dhcp/dhcpd.conf   
  2. #
  3. # DHCP Server Configuration file.
  4. #   see /usr/share/doc/dhcp*/dhcpd.conf.sample
  5. #   see 'man 5 dhcpd.conf'
  6. #
复制代码

  1. subnet 192.168.3.0 netmask 255.255.255.0 {  #这个是设置ip网段和子网掩码
  2.   range 192.168.3.10 192.168.3.40;              #自动分配的ip地址段
  3.   option domain-name-servers 192.168.3.1;       #dns服务器地址
  4.   option domain-name "dns.test.com";            #dns服务器名字
  5.   option routers 192.168.3.254;                 #网关
  6.   option broadcast-address 192.168.3.255;       #广播地址
  7.   default-lease-time 600;                       
  8.   max-lease-time 7200;              
复制代码
           
}

  1. [root@dns-server ~]# /etc/init.d/dhcpd start
复制代码


三、在客户端测试



  1. C:\Documents and Settings\Administrator>ipconfig


  2. Windows IP Configuration


  3. Ethernet adapter 本地连接:
复制代码


   
  1.    Connection-specific DNS Suffix  . : dns.test.com
  2.         IP Address. . . . . . . . . . . . : 192.168.3.10
  3.         Subnet Mask . . . . . . . . . . . : 255.255.255.0
  4.         Default Gateway . . . . . . . . . : 192.168.3.254


  5. C:\Documents and Settings\Administrator>
复制代码



四、dhcp参数模板


[
  1. root@dns-server ~]# cat /usr/share/doc/dhcp-4.1.1/dhcpd.conf.sample
  2. # dhcpd.conf
  3. #
  4. # Sample configuration file for ISC dhcpd
  5. #


  6. # option definitions common to all supported networks...
  7. option domain-name "example.org";
  8. option domain-name-servers ns1.example.org, ns2.example.org;

  9. default-lease-time 600;
  10. max-lease-time 7200;
复制代码


  1. # Use this to enble / disable dynamic dns updates globally.
  2. #ddns-update-style none;


  3. # If this DHCP server is the official DHCP server for the local
  4. # network, the authoritative directive should be uncommented.
  5. #authoritative;

  6. # Use this to send dhcp log messages to a different log file (you also
  7. # have to hack syslog.conf to complete the redirection).
  8. log-facility local7;


  9. # No service will be given on this subnet, but declaring it helps the
  10. # DHCP server to understand the network topology.

  11. subnet 10.152.187.0 netmask 255.255.255.0 {
  12. }
复制代码


  1. # This is a very basic subnet declaration.

  2. subnet 10.254.239.0 netmask 255.255.255.224 {
  3.   range 10.254.239.10 10.254.239.20;
  4.   option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
  5. }
复制代码


  1. # This declaration allows BOOTP clients to get dynamic addresses,
  2. # which we don't really recommend.

  3. subnet 10.254.239.32 netmask 255.255.255.224 {
  4.   range dynamic-bootp 10.254.239.40 10.254.239.60;
  5.   option broadcast-address 10.254.239.31;
  6.   option routers rtr-239-32-1.example.org;
  7. }
复制代码


  1. # A slightly different configuration for an internal subnet.
  2. subnet 10.5.5.0 netmask 255.255.255.224 {

  3.   range 10.5.5.26 10.5.5.30;
  4.   option domain-name-servers ns1.internal.example.org;
  5.   option domain-name "internal.example.org";
  6.   option routers 10.5.5.1;
  7.   option broadcast-address 10.5.5.31;
  8.   default-lease-time 600;
  9.   max-lease-time 7200;
  10. }
复制代码


  1. # Hosts which require special configuration options can be listed in
  2. # host statements.   If no address is specified, the address will be
  3. # allocated dynamically (if possible), but the host-specific information
  4. # will still come from the host declaration.

  5. host passacaglia {
  6.   hardware ethernet 0:0:c0:5d:bd:95;
  7.   filename "vmunix.passacaglia";
  8.   server-name "toccata.fugue.com";
  9. }
复制代码

  1. # Fixed IP addresses can also be specified for hosts.   These addresses
  2. # should not also be listed as being available for dynamic assignment.
  3. # Hosts for which fixed IP addresses have been specified can boot using
  4. # BOOTP or DHCP.   Hosts for which no fixed address is specified can only
  5. # be booted with DHCP, unless there is an address range on the subnet
  6. # to which a BOOTP client is connected which has the dynamic-bootp flag
  7. # set.
  8. host fantasia {

  9.   hardware ethernet 08:00:07:26:c0:a5;
  10.   fixed-address fantasia.fugue.com;
  11. }


  12. [code]# You can declare a class of clients and then do address allocation
  13. # based on that.   The example below shows a case where all clients
  14. # in a certain class get addresses on the 10.17.224/24 subnet, and all
  15. # other clients get addresses on the 10.0.29/24 subnet.

  16. class "foo" {
  17.   match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
  18. }

复制代码
  1. shared-network 224-29 {
  2.   subnet 10.17.224.0 netmask 255.255.255.0 {
  3.     option routers rtr-224.example.org;
复制代码

  1.   }
  2.   subnet 10.0.29.0 netmask 255.255.255.0 {
  3.     option routers rtr-29.example.org;
  4.   }
复制代码

  pool {[/code]
  
  1. allow members of "foo";
  2.     range 10.17.224.10 10.17.224.250;
  3.   }
复制代码

  pool {
  
  1. deny members of "foo";
  2.     range 10.0.29.10 10.0.29.230;
  3.   }
复制代码

}

  1. [root@dns-server ~]#
复制代码




您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.