CentOS 安裝DHCP Server

因客戶需求,所以趕快學習一下Linux 安裝及設定DHCP服務,其實Linux DHCP Server 並不難,主要是設定檔的語法不要寫錯,以下為安裝及設定紀錄。

主要步驟如下:
1. DHCP 環境架構圖
2. Install dhcp
3. 設定dhcpd.conf
4. 設定Firewall DHCP Relay
5. 查看dhcp log
6. Install webmin

1. 環境架構圖
簡易說明:
Firewall: Pfsense DHCP Relay
DHCP: CentOS DHCP Server
目的: 每個網段User 必須透過CentOS DHCP Server 自動取得IP

2. Install dhcp
預設這些套件在CentOS 6.3上都已經有了,可直接使用yum安裝

#yum install dhcp

確認版本

#rpm -qa dhcp


2. 設定dhcpd.conf

#vi /etc/dhcp/dhcpd.conf
# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
#
ddns-update-style interim;
ignore client-updates;

subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.101 192.168.10.200;
option routers                  192.168.10.254;
option subnet-mask              255.255.255.0;
option domain-name              "test.com";
option domain-name-servers      192.168.10.30;
default-lease-time 21600;
max-lease-time 43200;
}

subnet 192.168.30.0 netmask 255.255.255.0 {
range 192.168.30.101 192.168.30.200;
option routers                  192.168.30.254;
option subnet-mask              255.255.255.0;
option domain-name              "test.com";
option domain-name-servers      192.168.10.30;
default-lease-time 21600;
max-lease-time 43200;
}

subnet 192.168.40.0 netmask 255.255.255.0 {
range 192.168.40.101 192.168.40.200;
option routers                  192.168.40.254;
option subnet-mask              255.255.255.0;
option domain-name              "test.com";
option domain-name-servers      192.168.10.30;
default-lease-time 21600;
max-lease-time 43200;
}

subnet 192.168.1.0 netmask 255.255.255.0 {
range 192.168.1.101 192.168.1.200;
option routers                  192.168.1.254;
option subnet-mask              255.255.255.0;
option domain-name              "test.com";
option domain-name-servers      192.168.1.254;
}

subnet 192.168.51.0 netmask 255.255.255.0 {
range 192.168.51.101 192.168.51.200;
option routers                  192.168.51.254;
option subnet-mask              255.255.255.0;
option domain-name              "test.com";
option domain-name-servers      192.168.10.30;
default-lease-time 21600;
max-lease-time 43200;
}

 

若DHCP Server 上有多張網卡,則指定DHCP Server Interface
#vi /etc/sysconfig/dhcpd
# Command line options here
DHCPDARGS="eth1"

4. 設定Firewall DHCP Relay
Source: User DHCP 的網段
Destination: DHCP Server

5. 查看dhcp log

啟動服務
#/etc/init.d/dhcpd start
檢查Log
#tail -f /var/log/messages | grep dhcpd
Mar 30 14:30:48 localhost dhcpd: Internet Systems Consortium DHCP Server 4.1.1-P1
Mar 30 14:30:48 localhost dhcpd: Copyright 2004-2010 Internet Systems Consortium.
Mar 30 14:30:48 localhost dhcpd: All rights reserved.
Mar 30 14:30:48 localhost dhcpd: For info, please visit https://www.isc.org/software/dhcp/
Mar 30 14:30:48 localhost dhcpd: Not searching LDAP since ldap-server, ldap-port and ldap-base-dn were not specified in the config file
Mar 30 14:30:48 localhost dhcpd: Wrote 15 leases to leases file.
Mar 30 14:30:48 localhost dhcpd: Listening on LPF/eth1/00:50:56:83:76:15/192.168.10.0/24
Mar 30 14:30:48 localhost dhcpd: Sending on   LPF/eth1/00:50:56:83:76:15/192.168.10.0/24
Mar 30 14:30:48 localhost dhcpd: Sending on   Socket/fallback/fallback-net
 
User DHCP 192.168.51.0/24 Log

Mar 30 19:40:58 localhost dhcpd: Unable to add forward map from Fred-PC.test.com to 192.168.51.107: connection refused

Mar 30 19:40:58 localhost dhcpd: Wrote 17 leases to leases file.
Mar 30 19:40:58 localhost dhcpd: DHCPREQUEST for 192.168.51.107 from 90:94:e4:f8:ee:f7 (Fred-PC) via 192.168.51.254
Mar 30 19:40:58 localhost dhcpd: DHCPACK on 192.168.51.107 to 90:94:e4:f8:ee:f7 (Fred-PC) via 192.168.51.254
DHCP Client

6. Install webmin
為了查看DHCP Log 還要得SSH登入查看,實在有點麻煩,透過Webmin 來安裝DHCP 並且在Webmin上看Log 還比較簡單一些

Webmin 官網
http://www.webmin.com/
目前版本是1.620 RPM 安裝,非常容易

# wget http://downloads.sourceforge.net/project/webadmin/webmin/1.620/webmin-1.620-1.noarch.rpm?r=http%3A%2F%2Fwww.webmin.com%2F&ts=1364562853&use_mirror=nchc

rpm 安裝

#rpm -ivh webmin-1.620-1.noarch.rpm

安裝完成後透過web ui登入 (本機帳號密碼)
http://192.168.10.188:10000
大功告成

















Refer:
http://linux.vbird.org/linux_server/0340dhcp.php
http://www.webmin.com/

Facebook Comments