佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > 超詳細講解Linux DHCP服務(wù)

超詳細講解Linux DHCP服務(wù)

熱門標(biāo)簽:美圖手機 網(wǎng)站建設(shè) 阿里云 智能手機 百度競價點擊價格的計算公式 檢查注冊表項 硅谷的囚徒呼叫中心 使用U盤裝系統(tǒng)

一、DHCP服務(wù)(動態(tài)主機配置協(xié)議)

1.背景

1.手動設(shè)置工作量大且容易沖突

2.用DHCP可以減少工作量和避免地址沖突

2.概述

  • 作用:為局域網(wǎng)內(nèi)的電腦分配IP地址
  • 架構(gòu) C/S;客戶端/服務(wù)器模式
  • 實現(xiàn)方式:

1.為相同網(wǎng)段的電腦分配IP地址—DHCP

2.跨網(wǎng)段為另一網(wǎng)段的電腦分配IP地址—DHCP中繼

  • DHCP使用UDP協(xié)議,67號是客戶機使用的,68號是服務(wù)器端的端口號

3.優(yōu)點

1.減少管理員的工作量

2.避免輸入錯誤的可能

3.避免IP地址沖突

4.當(dāng)更改IP地址段時,不需要重新配置每個用戶的IP地址

5.提高了IP地址的利用率

6.方便客戶端的配置

4.DHCP報文類型

以找工作為例:

DHCP Discover——客戶端用來尋找DHCP服務(wù)器的報文
我向公司投簡歷來找工作

DHCP Offer——DHCP服務(wù)器用來響應(yīng)DHCP Discover報文的報文。該報文攜帶了各種配置信息,例如IP地址,DNS等
公司收到我的求職簡歷后給我發(fā)了一份offer

DHCP Request——客戶端請求配置確認,或者續(xù)借租期
我收到offer之后跟公司確認

DHCP ACK——服務(wù)器對Request報文的確認響應(yīng)
公司說我ok沒問題,可以過來上班 ,我找到工作了

5.DHCP 的分配方式

①自動分配:
當(dāng)DHCP客戶機第一次成功地從DHCP服務(wù)器獲取到一個IP地址后,就永久的使用這個IP地址
②手動分配:
由DHCP服務(wù)器管理員專門指定IP地址
③動態(tài)分配:
當(dāng)DHCP客戶機第一次從DHCP服務(wù)器獲得IP地址后,并非永久的使用該地址,而是在每次使用完后,DHCP客戶機就會釋放這個IP地址,供其他客戶機使用

二、安裝 DHCP 服務(wù)器

1.DHCP 服務(wù)軟件

  • CentOS光盤中的 dhcp-4.2.5-47.el7.centos.x86_64.rpm
  • 一般都有,沒有的話 RPM 去安裝一下

  • DHCP 軟件包的主要文件

主配置文件:/etc/dhcpd.conf

執(zhí)行程序:/usr/sbin/dhcpd、usr/sbin/dhcrelay

2.主配置文件

  • dhcpd.conf 的內(nèi)容構(gòu)成
ddns-update-style  interim;     #全局配置參數(shù)
......
subnet  192.168.0.0  netmask  255.255.255.0 {       #subnet以上的都是全局配置參數(shù);網(wǎng)段聲明(網(wǎng)段、子網(wǎng)掩碼、默認網(wǎng)關(guān)地址)
   option routers 192.168.0.1;       #配置選項
   ......
   default-lease-time 21600;   #配置參數(shù)
   host ns {
      ......    
      fixed-address 207.175.42.254;    #主機聲明(固定一個IP給主機用的)
   }
}        
  • Subnet網(wǎng)段聲明,作用于整個子網(wǎng)段

range參數(shù):設(shè)置用于分配的IP地址池

option subnet-mask參數(shù):設(shè)置客戶機的子網(wǎng)掩碼

option routers參數(shù):設(shè)置客戶機的默認網(wǎng)關(guān)地址

三、配置步驟

1.使用 DHCP 動態(tài)的給 PC 機分配 IP 地址

① eNSP

實驗拓撲圖如下

注:配置完“Cloud”之后才能用串口線連接

  • 配置Cloud

  • SW1基本配置
<Huawei>undo terminal monitor 
<Huawei>system-view 
[L2-SW1]user-interface console 0
[L2-SW1-ui-console0]idle-timeout 0 0
[L2-SW1-ui-console0]quit 
[L2-SW1]vlan batch 10 20 100
[L2-SW1]interface Ethernet 0/0/1	
[L2-SW1-Ethernet0/0/1]port link-type access 	
[L2-SW1-Ethernet0/0/1]port default vlan 10
[L2-SW1-Ethernet0/0/1]quit
[L2-SW1]interface Ethernet 0/0/2	
[L2-SW1-Ethernet0/0/2]port link-type access 	
[L2-SW1-Ethernet0/0/2]port default vlan 20
[L2-SW1-Ethernet0/0/2]quit
[L2-SW1]interface Ethernet 0/0/3	
[L2-SW1-Ethernet0/0/3]port link-type access 	
[L2-SW1-Ethernet0/0/3]port default vlan 100
[L2-SW1-Ethernet0/0/3]quit
[L2-SW1]interface Ethernet 0/0/4	
[L2-SW1-Ethernet0/0/4]port link-type access 	
[L2-SW1-Ethernet0/0/4]port default vlan 100
[L2-SW1-Ethernet0/0/4]quit
[L2-SW1]interface GigabitEthernet0/0/1
[L2-SW1-GigabitEthernet0/0/1]port link-type trunk
[L2-SW1-GigabitEthernet0/0/1]port trunk allow-pass vlan 10 20 100
[L2-SW1-GigabitEthernet0/0/1]quit
  • SW2基本配置
<Huawei>undo terminal monitor 
<Huawei>system-view 
[Huawei]sysname L3-SW2
[L3-SW2]user-interface console 0
[L3-SW2-ui-console0]idle-timeout 0 0
[L3-SW2-ui-console0]quit
[L3-SW2]vlan batch 10 20 100
[L3-SW2]interface GigabitEthernet0/0/1
[L3-SW2-GigabitEthernet0/0/1]port link-type trunk
[L3-SW2-GigabitEthernet0/0/1]port trunk allow-pass vlan 10 20 100
[L3-SW2-GigabitEthernet0/0/1]quit
[L3-SW2]interface Vlanif 10	
[L3-SW2-Vlanif10]ip address 192.168.10.1 255.255.255.0	
[SW2-Vlanif20]un sh
[L3-SW2]interface Vlanif 20	
[L3-SW2-Vlanif20]ip address 192.168.20.1 255.255.255.0	
[SW2-Vlanif20]un sh
[L3-SW2]interface Vlanif 100
[L3-SW2-Vlanif100]ip address 192.168.100.1 255.255.255.0	
[SW2-Vlanif20]un sh
[SW2-Vlanif100]int g0/0/1
[SW2-GigabitEthernet0/0/1]port link-type trunk 
[SW2-GigabitEthernet0/0/1]port trunk allow-pass vlan all 
  • 配置DHCP中繼(三層交換機)
[L3-SW2]dhcp enable               ##開啟DHCP功能
[L3-SW2]interface Vlanif 10	      ##配置虛接口ip,選擇dhcp中繼模式,請求指向dhcp服務(wù)器ip
[L3-SW2-Vlanif10]dhcp select relay 	
[L3-SW2-Vlanif10]dhcp relay server-ip 192.168.100.100	
[L3-SW2-Vlanif10]quit 	
[L3-SW2]interface Vlanif 20	
[L3-SW2-Vlanif20]dhcp select relay 
[L3-SW2-Vlanif20]dhcp relay server-ip 192.168.100.100	
[L3-SW2-Vlanif20]quit 	
[L3-SW2]interface Vlanif 100	
[L3-SW2-Vlanif100]dhcp select relay 
[L3-SW2-Vlanif100]dhcp relay server-ip 192.168.100.100
[L3-SW2-Vlanif100]quit 

②虛擬機

  • 選擇虛擬機網(wǎng)絡(luò)類型

  • 配置網(wǎng)卡IP

  • 安裝dhcp軟件包,并查看和找到配置文件
[root@xjj ~]# yum -y install dhcp
已加載插件:fastestmirror, langpacks
Loading mirror speeds from cached hostfile
軟件包 12:dhcp-4.2.5-58.el7.centos.x86_64 已安裝并且是最新版本
無須任何處理

[root@xjj ~]# cd /etc/dhcp/        ##dhcp的配置文件是/etc/dhcp/dhcpd.conf
[root@xjj dhcp]# ls
dhclient.d  dhclient-exit-hooks.d  dhcpd6.conf  dhcpd.conf  scripts
[root@xjj dhcp]# less dhcpd.conf        ##查看一下內(nèi)容

[root@xjj ~]# cd /usr/share/doc/dhcp-4.2.5/        到該目錄下去尋找dhcp配置模板
[root@xjj dhcp-4.2.5]# ls        ##“dhcpd.conf.example”
dhcpd6.conf.example  dhcpd.conf.example  ldap
[root@xjj dhcp-4.2.5]# cp dhcpd.conf.example /etc/dhcp/dhcpd.conf        ##將模板覆蓋到/etc/dhcp/dhcpd.conf中
cp:是否覆蓋"/etc/dhcp/dhcpd.conf"? y

[root@xjj ~]# cd /etc/dhcp/        ##回到/etc/dhcp目錄下
[root@xjj dhcp]# ls
dhclient.d  dhclient-exit-hooks.d  dhcpd6.conf  dhcpd.conf  scripts
[root@xjj dhcp]# less dhcpd.conf        ##查看配置文件并進行下一步編輯

編輯dhcp配置文件

  • [root@xjj dhcp]# vim dhcpd.conf

  • 關(guān)閉防火墻,重啟網(wǎng)卡,再去“ping”進行驗證網(wǎng)絡(luò)
[root@xjj dhcp]# systemctl stop firewalld
se[root@jj dhcp]# setenforce 0
##記得重啟一下網(wǎng)卡!
[root@xjj dhcp]# systemctl restart dhcpd


[root@xjj dhcp]# ping 192.168.100.1
...略
[root@xjj dhcp]# ping 192.168.10.1
...略
[root@xjj dhcp]# ping 192.168.20.1
...略

③驗證

  • 到eNSP中驗證一下
  • 首先開啟兩臺PC的DHCP來自動獲取一下IP地址

④進入命令行“ipconfig”測試

  • pc1

  • pc2

pc1和pc2成功?。?!

以上就是超詳細講解Linux DHCP服務(wù)的詳細內(nèi)容,更多關(guān)于Linux DHCP服務(wù)的資料請關(guān)注腳本之家其它相關(guān)文章!

標(biāo)簽:懷化 煙臺 湘潭 賀州 山南 黃山 通遼 湖北

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《超詳細講解Linux DHCP服務(wù)》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    大同市| 茶陵县| 讷河市| 天全县| 庆安县| 图木舒克市| 宜春市| 浮山县| 庄浪县| 富顺县| 定州市| 龙口市| 青海省| 饶平县| 宁夏| 台南县| 龙川县| 秦皇岛市| 永川市| 洪湖市| 涞水县| 玛曲县| 岢岚县| 抚松县| 锡林郭勒盟| 乐平市| 青田县| 沛县| 花莲市| 和平县| 类乌齐县| 车致| 平阴县| 龙胜| 台北市| 通海县| 乳源| 潞城市| 武冈市| 汉阴县| 庆阳市|