CentOS7 DHCP 服務搭建

来源:https://www.cnblogs.com/iceblues/archive/2018/12/09/10094051.html
-Advertisement-
Play Games

一、實驗環境 1、VMware12、倆台Linux(Ser 和 Client )、DHCP安裝包。 二、操作流程 1、安裝DHCP 2、配置DHCP的配置文件: /etc/dhcp/dhcpd.conf 3、測試服務 三、實操如下 1、# yum -y install dhcp* //安裝DHCP, ...


一、實驗環境

1、VMware12、倆台Linux(Ser  和  Client )、DHCP安裝包。

二、操作流程

1、安裝DHCP

2、配置DHCP的配置文件:  /etc/dhcp/dhcpd.conf

3、測試服務

三、實操如下

1、# yum -y install dhcp*            //安裝DHCP,註意要帶上*   在Ser上操作。

2、# vim /etc/sysconfig/network-scripts/ifcfg-ens33-1           //在Ser上配置網路IP地址,一般都是ens33

3、網路IP設置如下:

HWADDR=00:0C:29:03:EA:35
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static                   //改為static,表示靜態地址
IPADDR=192.168.1.20                //改為和subnet 同網段的地址(此地址最好選擇range之外的地址)
PREFIX=24                                  //改為和網路IP地址對應的子網掩碼
GATEWAY=192.168.1.1              //註意:此處網關必須設置和DHCP作用域裡面的網關相同
DNS1=8.8.8.8                             //DNS設置正常的就可以
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=ens33
UUID=2d5fde3e-2e83-49af-b7d7-f326fc3a7001
ONBOOT=yes                             //保證網卡處於yes 啟動狀態

⏩按鍵esc 輸入:wq    保存退出。

#systemctl restart network         //重啟網卡  (建議重啟系統)

4、配置DHCP的配置文件: vim /etc/dhcp/dhcpd.conf

打開配置文件按照提示 #cp /usr/share/doc/dhcp*/dhcpd.conf.example /etc/dhcp/dhcpd.conf       //用示例文件覆蓋配置文件

#vim /etc/dhcp/dhcpd.conf          //正式開始編輯配置文件,加底色的保留,其他的全部dd

# dhcpd.conf
#
# Sample configuration file for ISC dhcpd
# # option definitions common to all supported networks...
option domain-name "example.org";                                                                             //作用功能變數名稱
option domain-name-servers ns1.example.org, ns2.example.org;                                //DNS default-lease-time 600;                                                                                                  //預設租約時間
max-lease-time 7200;                                                                                                    //最大租約時間 # Use this to enble / disable dynamic dns updates globally.
#ddns-update-style none; # If this DHCP server is the official DHCP server for the local
# network, the authoritative directive should be uncommented.
#authoritative; # Use this to send dhcp log messages to a different log file (you also
# have to hack syslog.conf to complete the redirection). log-facility local7; # No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology. subnet 10.152.187.0 netmask 255.255.255.0 {
}                                                                                                                       //聲明網路拓撲 # This is a very basic subnet declaration. subnet 10.254.239.0 netmask 255.255.255.224 {
  range 10.254.239.10 10.254.239.20;
  option routers rtr-239-0-1.example.org, rtr-239-0-2.example.org;
} # This declaration allows BOOTP clients to get dynamic addresses,
# which we don't really recommend. subnet 10.254.239.32 netmask 255.255.255.224 {
  range dynamic-bootp 10.254.239.40 10.254.239.60;
  option broadcast-address 10.254.239.31;   option routers rtr-239-32-1.example.org;
} # A slightly different configuration for an internal subnet.
subnet 10.5.5.0 netmask 255.255.255.224 {                                                 //作用域網段
  range 10.5.5.26 10.5.5.30;                                                                          //地址池範圍
  option domain-name-servers ns1.internal.example.org;                          //DNS
  option domain-name "internal.example.org";                                          //作用功能變數名稱
  option routers 10.5.5.1;                                                                             //網關,Ser上面配置的網關和此網關要一致
  option broadcast-address 10.5.5.31;                                                        //廣播地址
  default-lease-time 600;                                                                            //預設租約時間
  max-lease-time 7200;                                                                              //最大租約時間
}                                                                                                                      //創建一個子網地址池 # Hosts which require special configuration options can be listed in
# host statements.   If no address is specified, the address will be
# allocated dynamically (if possible), but the host-specific information
# will still come from the host declaration. host passacaglia {
  hardware ethernet 0:0:c0:5d:bd:95;
  filename "vmunix.passacaglia";
  server-name "toccata.fugue.com";
} # Fixed IP addresses can also be specified for hosts.   These addresses
# should not also be listed as being available for dynamic assignment.
# Hosts for which fixed IP addresses have been specified can boot using
# BOOTP or DHCP.   Hosts for which no fixed address is specified can only
# be booted with DHCP, unless there is an address range on the subnet
# to which a BOOTP client is connected which has the dynamic-bootp flag
# set.
host fantasia {
  hardware ethernet 08:00:07:26:c0:a5;
  fixed-address fantasia.fugue.com;
} # You can declare a class of clients and then do address allocation
# based on that.   The example below shows a case where all clients # in a certain class get addresses on the 10.17.224/24 subnet, and all
# other clients get addresses on the 10.0.29/24 subnet. class "foo" {
  match if substring (option vendor-class-identifier, 0, 4) = "SUNW";
} shared-network 224-29 {
  subnet 10.17.224.0 netmask 255.255.255.0 {
    option routers rtr-224.example.org;
  }
  subnet 10.0.29.0 netmask 255.255.255.0 {
    option routers rtr-29.example.org;
  }
  pool {
    allow members of "foo";
    range 10.17.224.10 10.17.224.250;
  }
  pool {
    deny members of "foo"; range 10.0.29.10 10.0.29.230;
  }
}

⏩按鍵esc 輸入:wq    保存退出。

#systemctl start dhcpd         //啟動DHCP服務  

5、測試地址分發

首先將倆台虛擬系統Ser 和 Client 的網卡配置在同一個虛擬網路環境中,如下圖

 

然後在Client 上 修改網卡配置文件,BOOTPROTO=dhcp   刪除靜態地址後保存 重啟網卡(也重啟電腦)

同樣在Client 上安裝DHCP服務

驗證如下:

ifconfig 查看獲取情況

route -n        //查看路由信息

也可以在Ser上執行status 命令

#systemctl status dhcpd

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • 網上普遍使用的化學方程式的格式普遍如下 例: KMnO4+FeSO4+H2SO4=Fe2(SO4)3+MnSO4+K2SO4+H2O 要把化學方程式格式化,單單一個正則表達式是非常反人類的,故可選用 C++ 實現化學方程式的格式化。 首先,寫一個 for 迴圈,傳入字元數組 input[] ,依次地 ...
  • 正式開始 首先我在這介紹兩個新的小知識,要在下麵用到。一個是函數 id() ,另一個是運算符 is。id() 函數就是返回對象的記憶體地址;is 是比較兩個變數的對象引用是否指向同一個對象,在這裡請不要和 == 混了,== 是比較兩個變數的值是否相等。 copy 這個詞有兩種叫法,一種是根據它的發音音 ...
  • 這裡主要介紹ANSI C的特性:當執行算術運算時,操作數的類型如果不同,就會發生轉換。數據類型一般朝著精度更高、長度更長的方向轉換,整型數如果轉換為signed不會丟失信息,就轉換為signed,否則轉換為unsigned。 一、算術轉換(K&R C) 首先: 任何類型為char或short的操作數 ...
  • using System; namespace ConsoleApp1 { interface IInterface1 { void ft(); } interface IInterface2 { void ft(); } class MyClass : IInterface1, IInterfa.... ...
  • 本周終於發佈了.NET Core 2.2,ASP.NET Core 2.2以及Entity Framework Core 2.2,雖然更大的新聞可能是.NET Core 3.0的特性公佈,但不妨先將現有的.NET Core版本升級到2.2,及時體驗一下新的功能。 .NET Core 2.2 分層編譯 ...
  • 1、錯誤案例: Index:1 Uncaught ReferenceError: 系統管理 is not defined at HTMLAnchorElement.onclick (Index:1) 2、錯誤寫法 3、正確寫法(加入轉義符號 ' \ ' ) ...
  • 在 Asp.Net Core 1.0 時代,由於設計上的問題, HttpClient 給開發者帶來了無盡的困擾,用 Asp.Net Core 開發團隊的話來說就是:我們註意到,HttpClient 被很多開發人員不正確的使用。得益於 .Net Core 不斷的版本快速升級;解決方案也一一浮出水面,本... ...
  • 一、緩存機制介紹 在Linux系統中,為了提高文件系統性能,內核利用一部分物理記憶體分配出緩衝區,用於緩存系統操作和數據文件,當內核收到讀寫的請求時,內核先去緩存區找是否有請求的數據,有就直接返回,如果沒有則通過驅動程式直接操作磁碟。緩存機制優點:減少系統調用次數,降低CPU上下文切換和磁碟訪問頻率。 ...
一周排行
    -Advertisement-
    Play Games
  • 示例項目結構 在 Visual Studio 中創建一個 WinForms 應用程式後,項目結構如下所示: MyWinFormsApp/ │ ├───Properties/ │ └───Settings.settings │ ├───bin/ │ ├───Debug/ │ └───Release/ ...
  • [STAThread] 特性用於需要與 COM 組件交互的應用程式,尤其是依賴單線程模型(如 Windows Forms 應用程式)的組件。在 STA 模式下,線程擁有自己的消息迴圈,這對於處理用戶界面和某些 COM 組件是必要的。 [STAThread] static void Main(stri ...
  • 在WinForm中使用全局異常捕獲處理 在WinForm應用程式中,全局異常捕獲是確保程式穩定性的關鍵。通過在Program類的Main方法中設置全局異常處理,可以有效地捕獲並處理未預見的異常,從而避免程式崩潰。 註冊全局異常事件 [STAThread] static void Main() { / ...
  • 前言 給大家推薦一款開源的 Winform 控制項庫,可以幫助我們開發更加美觀、漂亮的 WinForm 界面。 項目介紹 SunnyUI.NET 是一個基於 .NET Framework 4.0+、.NET 6、.NET 7 和 .NET 8 的 WinForm 開源控制項庫,同時也提供了工具類庫、擴展 ...
  • 說明 該文章是屬於OverallAuth2.0系列文章,每周更新一篇該系列文章(從0到1完成系統開發)。 該系統文章,我會儘量說的非常詳細,做到不管新手、老手都能看懂。 說明:OverallAuth2.0 是一個簡單、易懂、功能強大的許可權+可視化流程管理系統。 有興趣的朋友,請關註我吧(*^▽^*) ...
  • 一、下載安裝 1.下載git 必須先下載並安裝git,再TortoiseGit下載安裝 git安裝參考教程:https://blog.csdn.net/mukes/article/details/115693833 2.TortoiseGit下載與安裝 TortoiseGit,Git客戶端,32/6 ...
  • 前言 在項目開發過程中,理解數據結構和演算法如同掌握蓋房子的秘訣。演算法不僅能幫助我們編寫高效、優質的代碼,還能解決項目中遇到的各種難題。 給大家推薦一個支持C#的開源免費、新手友好的數據結構與演算法入門教程:Hello演算法。 項目介紹 《Hello Algo》是一本開源免費、新手友好的數據結構與演算法入門 ...
  • 1.生成單個Proto.bat內容 @rem Copyright 2016, Google Inc. @rem All rights reserved. @rem @rem Redistribution and use in source and binary forms, with or with ...
  • 一:背景 1. 講故事 前段時間有位朋友找到我,說他的窗體程式在客戶這邊出現了卡死,讓我幫忙看下怎麼回事?dump也生成了,既然有dump了那就上 windbg 分析吧。 二:WinDbg 分析 1. 為什麼會卡死 窗體程式的卡死,入口門檻很低,後續往下分析就不一定了,不管怎麼說先用 !clrsta ...
  • 前言 人工智慧時代,人臉識別技術已成為安全驗證、身份識別和用戶交互的關鍵工具。 給大家推薦一款.NET 開源提供了強大的人臉識別 API,工具不僅易於集成,還具備高效處理能力。 本文將介紹一款如何利用這些API,為我們的項目添加智能識別的亮點。 項目介紹 GitHub 上擁有 1.2k 星標的 C# ...