CentOS 7 下搭建 DHCP

來源:互聯網
上載者:User
聲明下啊:第一次發帖,菜鳥一枚,忘大牛多指點一二啊。


1.1.  安裝篇

# mkdir  /mnt/cdrom/

# mount  /dev/cdrom  /mnt/cdrom

# cd/mnt  /cdrom/Packages/

# ls dhcp*

dhcp-4.2.5-27.el7.centos.x86_64.rpm 

dhcp-common-4.2.5-27.el7.centos.x86_64.rpm  

dhcp-libs-4.2.5-27.el7.centos.x86_64.rpm

 

# rpm -Uvhdhcp-4.2.5-27.el7.centos.x86_64.rpm

Preparing...                                   ################################# [100%]

Updating / installing...

  1:dhcp-12:4.2.5-27.el7.centos     ################################# [100%]

 

   Tips:如果你是高手或者電腦能連網,建議用yum安裝,特別方便啊!  # yum  -y  install dhcpd 
1.2.  配置

 

# rpm -qc  dhcp   //查詢和DHCP相關的設定檔

/etc/dhcp/dhcpd.conf

/etc/dhcp/dhcpd6.conf

/etc/openldap/schema/dhcp.schema

/etc/sysconfig/dhcpd

/var/lib/dhcpd/dhcpd.leases

/var/lib/dhcpd/dhcpd6.leases

 

# cd  /etc/dhcp/

# cp  dhcpd.conf   dhcpd.conf.origin   //更改之前新備份,以備不測,

 

# cat  /etc/dhcp/dhcpd.conf 

#

# DHCP Server Configuration file.

#   see /usr/share/doc/dhcp*/dhcpd.conf.example

#   see dhcpd.conf(5) man page

#

 

查看樣本檔案 //我們可以根據這個example 快速的產生一個設定檔,而且不容易有錯

# more   /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example

根據例子檔案我們可以產生一個設定檔,可以配置兩個網段的,一個網段就是一個subnet  


# vi/etc/dhcp/dhcpd.conf

option domain-name "lee.local";

option domain-name-servers 192.168.188.11, 192.168.188.12;

default-lease-time 691200;

max-lease-time 691200;

 

subnet 192.168.188.0 netmask 255.255.255.0 {

  range 192.168.188.100 192.168.188.159;

  range 192.168.188.170 192.168.188.253;

  default-lease-time 259200;

  max-lease-time 259200;

  option routers 192.168.188.2;

}

 

subnet 192.168.189.0 netmask 255.255.255.0 {

  range 192.168.189.100 192.168.189.253;

  option routers 192.168.189.2;

}

 

host printer1 {

  hardware ethernet 00:12:34:56:78:90;

  fixed-address 192.168.188.111;

}

 Tips :default-lease-timetime;

                                 Time should be the length in seconds thatwill be assigned to a lease if the client requesting the leasedoes not ask fora  specific  expiration time.  This is used for both DHCPv4 and DHCPv6leases (it is also              known as the "valid lifetime" in DHCPv6).  The default is 43200 seconds.

                

max-lease-timetime; Time  should be  the  maximum length in seconds that will beassigned to a lease.  If not defined,thedefault maximum lease time is 86400.  Theonly exception to this is that Dynamic BOOTP lease lengths,which are notspecified by the client, are not limited by this maximum.


# systemctl    start  dhcpd.service //啟動服務,和以前的service dhcpd start的效果等同,

查看記錄檔

Internet Systems Consortium DHCP Server 4.2.5

Copyright 2004-2013 Internet Systems Consortium.

All rights reserved.

For info, please visit https://www.isc.org/software/dhcp/

Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file

Wrote 0 deleted host decls to leases file.

Wrote 0 new dynamic host decls to leases file.

Wrote 0 leases to leases file.

Listening on LPF/eno16777728/00:0c:29:a4:2e:39/192.168.188.0/24

Sending on   LPF/eno16777728/00:0c:29:a4:2e:39/192.168.188.0/24

Sending on   Socket/fallback/fallback-net


配置DHCPD為自動啟動, 這在CentOS 7上的新的變化 了 #systemctl  enable dhcpd.service  // 原來的是   chkconfig  dhcpd on 

# systemctlis-enabled dhcpd

enabled   //出現這個單詞,證明已經設定為開機啟動了。


1.3.  測試    

在一台Windows客戶機上進行測試

 




Tips:這個dns是我先前設定的,方便上網。


# tail   /var/lib/dhcpd/dhcpd.leases    //當客戶機租用IP地址時,會在日誌中看到    

DHCPINFORM from 192.168.188.100 via eno16777728: not authoritative for subnet 192.168.188.0

DHCPREQUEST for 192.168.188.100 from 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728

DHCPACK on 192.168.188.100 to 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728

DHCPREQUEST for 192.168.188.100 from 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728

DHCPACK on 192.168.188.100 to 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728

DHCPREQUEST for 192.168.188.100 from 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728

DHCPACK on 192.168.188.100 to 00:0c:29:b3:a2:60 (TOMSRV1) via eno16777728


1.4.  總結           DHCP的安裝不是那麼複雜,但是要注意,如果在虛擬機器上安裝的,記得把虛擬機器的DHCP服務停了,要不然會出現和預期不一樣的結果喲。
         DHCP伺服器是一個比較特殊的伺服器,要是在單位做實驗的話,一定要小心啊,因為你一啟動這個伺服器,單位的互動機就會很生氣喲。
          好了,不囉嗦了,就這麼多吧,歡迎留言、轉載、共同討論  ~_~    ~_~












相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.