centos7之dhcp服務為多個網段分配ip位址

2022-09-23 02:24:11 字數 2530 閱讀 3403

實驗目的:通過一台dhcp伺服器實現給多網段分配ip位址

在gns3上構建如上圖的拓撲結構圖配置:在sw2二層交換機上:sw2#conf tsw2(config)#no ip routing //關閉路由功能sw2(config)#vlan 10,20,80 //建立10,20,80的vlansw2(config-vlan)#int f1/1 sw2(config-if)#switchport mode accesssw2(config-if)#switchport access vlan 10 sw2(config-if)#int f1/2sw2(config-if)#switchport mode access //設定為允許模式sw2(config-if)#switchport access vlan 20sw2(config-if)#int f1/3sw2(config-if)#switchport mode access //設定為允許模式sw2(config-if)#switchport access vlan 30sw2(config-if)#int f1/15sw2(config-if)#switchport mode trunk //設定中繼口sw2(config-if)#switchport trunk encapsulation dot1q //封裝為dot1qsw2(config-if)#do show vlan-sw //檢視

在sw1三層交換機上:(配置閘道器)sw1#conf tsw1(config)#int f1/15sw1(config-if)#switchport mode trunksw1(config-if)#switchport trunk encapsulation dot1qsw1(config-if)#vlan 10,20,80sw1(config-vlan)#int vlan 10sw1(config-if)#ip add 192.168.10.1 255.255.255.0sw1(config-if)#no shutsw1(config-if)#int vlan 20sw1(config-if)#ip add 192.168.20.1 255.255.255.0sw1(config-if)# no shutsw1(config-if)#int vlan 30sw1(config-if)#ip add 192.168.30.1 255.255.255.0sw1(config-if)# no shutsw1(config-if)#int vlan 80sw1(config-if)#ip add 192.168.80.1 255.255.255.0sw1(config-if)# no shutsw1(config-if)#do show ip int b

到此,我們在網路裝置上的配置先告一段落我們開始在linux上搭建dhcp服務,來為c1和c2分配ip位址

首先關閉防火牆和selinux,不然之後請求分配ip位址的時候會被拒絕阻止systemctl stop firewalldsetenforce 0rpm -q dhcp //檢視有木有安裝dhcp軟體沒有的話,直接yum install -y dhcp 安裝dhcp服務安裝完成後vi /etc/dhcp/dhcpd.conf //去配置它的配置檔案

如上圖,當我們進去配置的時候只有以上內容,我可以直接在下面配置也可以,複製乙份模版過來進行修改,模版可以從上圖看到,/usr/share/doc/dhcp/dhcpd.conf.example 這就是dhcp配置檔案模版我們可以使用一下命令進行使用cp /usr/share/doc/dhcp/dhcpd.conf.example /etc/dhcp/dhcpd.conf

這裡呢,我就不使用模版了,就直接新增配置了

首先,我們要注意一點,一定一定一定要把虛擬機器本身的網段寫在第乙個,不然的話會報錯,無法啟動。然後我們來解釋一下,這些**的含義subnet 192.168.80.0 netmask 255.255.255.0 注意了,大括號裡的內容每段以分號結尾。所以說別忘了分號,忘了也會在啟動的時候報錯

好了,配置這些我們就可以了,我們有三個網段,所以我們要配置三段這樣的內容,可以直接4yy複製,然後按p貼上,然後進行修改

然後儲存退出

啟動服務systemctl start dhcpd 啟動dhcp服務時,dhcp後面跟個d

這裡還有乙個注意點我們的網絡卡配置一定要指定我們在gns3中設定的閘道器,不然無法分配ip位址,報錯,dhcp伺服器找不到

然後回到我們的gns3中:在我們的sw1三層交換機上:sw1(config)#int vlan10sw1(config-if)#ip helper-address 192.168.80.100 //為vlan10指定dhcp伺服器sw1(config)#int vlan20sw1(config-if)#ip helper-address 192.168.80.100 //為vlan20指定dhcp伺服器sw1(config-if)#int vlan 30sw1(config-if)#ip helper-address 192.168.80.100到此,我們的配置就全部配置完了現在我們進行測試

進入字元命令介面

輸入ip dhcp 來請求獲取分配ip位址如上圖出現ddora或者dora 的話,說明我們能請求到dhcp伺服器如果是ddd的話,恭喜你,排錯吧。

我們也可以通過ping全網ip位址來檢查是否全網互通。

如上圖,我們成功的全網互通了。實驗成功了。

centos7安裝DHCP伺服器

1檢查防火牆和selinux 關閉 關閉防火牆和selinux,這邊不多說 2檢查dhcp狀態 3安裝dhcp軟體包 4把系統預設的樣例複製 5修改配置檔案 option domain name example.org dns網域名稱 option domain name servers ns1.e...

centos7下搭建NAT和DHCP伺服器

nat network address translation 即網路位址轉換,作為一種過渡解決手段,可以用來減少對全球合法ip位址的需求。簡單的說,nat就是在內部專用網路中使用內部位址,而當內部節點要與外界網路發生聯絡時,就在邊緣路由器或者防火牆處,將內部位址轉換成全域性位址,從而使得在外部公共...

Centos7下搭建DHCP伺服器

dhcp服務的安裝與基本配置 1 安裝dhcp服務 yum install dhcp2 服務名稱 dhcpd 3 主配置檔案 etc dhcp dhcpd.conf預設設定 vim etc dhcp dhcpd.conf檔案內容 dhcp server configuration file.see ...