Linux,DHCP伺服器配置
阿新 • • 發佈:2018-12-07
Linux,DHCP伺服器配置
配置環境,redhat5.8(適用於linux新手練手)
安裝
如果用rpm安裝無法自動安裝依賴包。
有yum源的情況下直接安裝,沒有yum源先配置/etc/yum.repos.d/local.repo
:
yum install dhcp
檢視安裝檔案:
[[email protected] ~]# rpm -q dhcp dhcp-3.0.5-31.el5 [[email protected] ~]# rpm -ql dhcp /etc/dhcpd.conf /etc/rc.d/init.d/dhcpd /etc/rc.d/init.d/dhcrelay /etc/sysconfig/dhcpd /etc/sysconfig/dhcrelay /usr/bin/omshell /usr/sbin/dhcpd /usr/sbin/dhcrelay /usr/share/doc/dhcp-3.0.5 /usr/share/doc/dhcp-3.0.5/IANA-arp-parameters /usr/share/doc/dhcp-3.0.5/README /usr/share/doc/dhcp-3.0.5/RELNOTES /usr/share/doc/dhcp-3.0.5/api+protocol /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-authentication-14.txt /usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-dhcp-dns-12.txt /usr/share/doc/dhcp-3.0.5/draft-ietf-dhc-failover-07.txt /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient-script.8 /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.8 /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.conf.5 /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhclient.leases.5 /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhcp-eval.5 /usr/share/doc/dhcp-3.0.5/ja_JP.eucJP/dhcp-options.5 /usr/share/doc/dhcp-3.0.5/rfc1542.txt /usr/share/doc/dhcp-3.0.5/rfc2131.txt /usr/share/doc/dhcp-3.0.5/rfc2132.txt /usr/share/doc/dhcp-3.0.5/rfc2485.txt /usr/share/doc/dhcp-3.0.5/rfc2489.txt /usr/share/doc/dhcp-3.0.5/rfc951.txt /usr/share/man/man1/omshell.1.gz /usr/share/man/man5/dhcp-eval.5.gz /usr/share/man/man5/dhcp-options.5.gz /usr/share/man/man5/dhcpd-eval.5.gz /usr/share/man/man5/dhcpd-options.5.gz /usr/share/man/man5/dhcpd.conf.5.gz /usr/share/man/man5/dhcpd.leases.5.gz /usr/share/man/man8/dhcpd.8.gz /usr/share/man/man8/dhcrelay.8.gz /var/lib/dhcpd /var/lib/dhcpd/dhcpd.leases
配置
開啟dhcp伺服器的主配置檔案/etc/dhcpd.conf
:
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.sample
#
初次安裝根據他的提示參考/usr/share/doc/dhcp*/dhcpd.conf.sample
:
[[email protected] ~]# cat /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample ddns-update-style interim; ignore client-updates; subnet 192.168.0.0 netmask 255.255.255.0 { # --- default gateway option routers 192.168.0.1; option subnet-mask 255.255.255.0; option nis-domain "domain.org"; option domain-name "domain.org"; option domain-name-servers 192.168.1.1; option time-offset -18000; # Eastern Standard Time # option ntp-servers 192.168.1.1; # option netbios-name-servers 192.168.1.1; # --- Selects point-to-point node (default is hybrid). Don't change this unless # -- you understand Netbios very well # option netbios-node-type 2; range dynamic-bootp 192.168.0.128 192.168.0.254; default-lease-time 21600; max-lease-time 43200; # we want the nameserver to appear at a fixed address host ns { next-server marvin.redhat.com; hardware ethernet 12:34:56:78:AB:CD; fixed-address 207.175.42.254; } }
直接將該檔案copy並重命名為/etc/dhcpd.conf
覆蓋原有檔案:
# cp /usr/share/doc/dhcp-3.0.5/dhcpd.conf.sample /etc/dhcpd.conf
cp:是否覆蓋“/etc/dhcpd.conf”? y
You have new mail in /var/spool/mail/root
/etc/dhcpd.conf
主要更改以下引數:
-
有幾個不同的dhcp需求的區域就寫幾個,花括號裡是關於此dhcp伺服器的配置
-
預設閘道器地址和掩碼配置
-
指定NIS(網路資訊服務)域名
-
時區設定
-
DHCP的地址池
-
ip地址租約設定
-
用來繫結固定ip
啟動伺服器測試
前情提要:設定的ip為192.168.19.0/24
service dhcpd restart
啟動DHCP服務
在另外一臺主機上修改IP地址設定模式為DHCP(動態),命令操作如下:
vi /etc/sysconfig/network-scripts/ifcfg-eth0
再開啟的配置檔案中,修改為BOOTPROTO=dhcp
service network restart
客戶端通過檢視/var/lib/dhclient/dhclient-eth0.leases
,可以知道是從哪臺dhcp伺服器分配的地址。
server可以通過/var/lib/dhcpd/dhcpd.leases
檢視ip分配情況。