您好,登錄后才能下訂單哦!
自動分配
手動分配
客戶機從DHCP服務器獲得IP地址的工程稱為DHCP的租約過程
租約過程分為4個步驟
1、客戶機請求IP地址 Discover
2、響應服務 Offer
3、客戶機選擇IP地址 Request
4、服務器確定租約 ACK
DHCP客戶機每次重新登錄網絡時,不需要再發送DHCP Discover信息,而是直接發送包含前一次所分配的IP地址的DHCP Request請求信息
DHCP服務
為大量客戶機自動分配地址,提供集中管理
減輕管理和維護成本、提高網絡配置效率
可分配的地址信息主要包括
網卡的IP地址、子網掩碼
對應的網絡地址、廣播地址
默認網關地址
DNS服務器地址
[root@localhost ~]# yum install dhcp -y
主配置文件
/etc/dhcp/dhcpd.conf
/var/lib/dhcpd/dhcpd.lease
修改網卡配置文件
BOOTPROTO=dhcp
dhclient
命令
dhclient [-d] [網絡接口名]
使用VMware 15
下載鏈接 許可證密匙
:UY758-0RXEQ-M81WP-8ZM7Z-Y3HDA
c3725路由鏡像文件
下載鏈接使用GNS3 1.3.1
下載鏈接 使用方法
win 10 鏡像
下載鏈接win 7 鏡像
下載鏈接CentOS 7鏡像
下載鏈接1、在GNS3中搭建DHCP中繼服務的拓撲圖,方便我們搭建服務的時候理清思路。在這里我使用一臺win 10虛擬機、一臺win 7虛擬機、一臺CentOS 7虛擬機、兩臺c3725路由設備。首先添加兩臺路由設備,并在路由設備上添加磁盤空間方便我們創建vlan,添加2層交換接口,方便我們把路由設備做成一個3層交換設備與一個2層交換設備。添加三臺host主機,分別更名為DHC、win 10、win 7,這個時候還需要我們在VMware 15虛擬機設備中添加兩塊虛擬網卡,設知道僅主機模式,這個時候在重新回到GNS3中使用鏈接線將設備接起來,這個實驗中我們將劃分3個vlan,分別將3臺虛擬機劃分到不同的vlan中(vlan地址劃分:vlan10:192.168.10.1/24、vlan20:192.168.20.1/24、vlan100:192.168.100.1/24,給DHCP服務器指定靜態IP地址 192.168.100.100。如下圖所示:
2、打開VMware 15,開啟win 10、win 7、CentOS 7虛擬機,在CentOS 7虛擬機中安裝DHCP服務;安裝完成后分別給win 10、win 7、CentOS 7虛擬機綁定網卡,win 10綁定VMnet2網卡,win 7綁定VMnet3網卡CentOS 7綁定VMnet1網卡;然會回到CentOS 7中配置靜態路由、配置DHCP服務,完成后開啟服務,關閉防火墻,關閉增強性安全文件。
[root@localhost ~]# yum install dhcp -y //安裝DHCP服務
已加載插件:fastestmirror, langpacks
base | 3.6 kB 00:00:00
extras | 3.4 kB 00:00:00
updates | 3.4 kB 00:00:00
(1/4): base/7/x86_64/group_gz | 166 kB 00:00:00
(2/4): base/7/x86_64/primary_db | 6.0 MB 00:00:01
...//省略部分內容...
[root@localhost ~]# ifconfig //查看網卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //此時無法獲取IP地址
inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet)
RX packets 47 bytes 30451 (29.7 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 122 bytes 13596 (13.2 KiB)
...//省略部分內容...
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-ens33 //進入ens33網卡配置文件
TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=static //更改dhcp為static配置靜態IP地址
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=2ef6b862-5201-48c5-a450-23b3720ab3a0
DEVICE=ens33
ONBOOT=yes
IPADDR=192.168.100.100 //配置IP地址
NETMASK=255.255.255.0 //配置子網掩碼
GATEWAY=192.168.100.1 //配置網關
~
~
:wq //保存退出
[root@localhost ~]# service network restart //重新啟動網絡服務
Restarting network (via systemctl): [ 確定 ]
[root@localhost ~]# ifconfig //查看網卡信息
ens33: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 //獲取靜態IP地址
inet 192.168.100.100 netmask 255.255.255.0 broadcast 192.168.100.255
inet6 fe80::a85a:c203:e2e:3f3c prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:5b:d3:a0 txqueuelen 1000 (Ethernet)
RX packets 48 bytes 30694 (29.9 KiB)
...//省略部分內容...
[root@localhost ~]# vim /etc/dhcp/dhcpd.conf //進入dhcp服務主配置文件
#
# DHCP Server Configuration file.
# see /usr/share/doc/dhcp*/dhcpd.conf.example //顯示dhcp配置文件模板位置
# see dhcpd.conf(5) man page
#
~
...//省略部分內容...
~
:r /usr/share/doc/dhcp-4.2.5/dhcpd.conf.example //將dhcpd配置文件模板寫入主配置文件
//寫入的著配置文件:
#
# 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;
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;
}
//更改后的配置文件信息:
...//省略部分內容...
# No service will be given on this subnet, but declaring it helps the
# DHCP server to understand the network topology.
subnet 192.168.100.0 netmask 255.255.255.0 { //更改IP網段
range 192.168.100.100 192.168.100.200; //可以分配的IP地址范圍
option routers 192.168.100.1; //網關信息(注意,每段結束以;結尾)
} //注意最后的大括號不可刪除,否則服務無法開啟
subnet 192.168.10.0 netmask 255.255.255.0 {
range 192.168.10.100 192.168.10.200; //添加vlan 10網段的地址分配條目
option routers 192.168.10.1;
}
subnet 192.168.20.0 netmask 255.255.255.0 {
range 192.168.20.100 192.168.20.200; //添加vlan 20網段的地址分配條目
option routers 192.168.20.1;
}
# This is a very basic subnet declaration.
:wq //保存退出
//因為我們這邊設置了三個vlan,網段都不相同,所以三個網段都要添加
[root@localhost ~]# systemctl start dhcpd //開啟dhcp服務
[root@localhost ~]# systemctl status dhcpd //查看服務是否開啟
dhcpd.service - DHCPv4 Server Daemon
Loaded: loaded (/usr/lib/systemd/system/dhcpd.service; disabled; vendor preset: disabled)
Active: active (running) since 三 2019-09-04 22:56:05 CST; 14s ago //服務成功開啟
Docs: man:dhcpd(8)
man:dhcpd.conf(5)
Main PID: 5343 (dhcpd)
Status: "Dispatching packets..."
CGroup: /system.slice/dhcpd.service
└─5343 /usr/sbin/dhcpd -f -cf /etc/dhcp/dhcpd.conf -user dhcpd -group dhc...
9月 04 22:56:05 localhost.localdomain dhcpd[5343]: No subnet declaration for virbr....
...//省略部分內容...
9月 04 22:56:05 localhost.localdomain systemd[1]: Started DHCPv4 Server Daemon.
Hint: Some lines were ellipsized, use -l to show in full.
3、DHCP服務開啟后我們回到GNS3中,開啟添加的3層交換機與2層交換機,并雙擊進入3層交換設備與2層交換設備,在2層交換設備中配置vlan,并將接入鏈路分別接入相對應的vlan中,將f1/0接口配置為trunk鏈路,在3層交換設備中同樣設置vlan,然后進入vlan中配置IP地址,并指定IP地址192.168.100.100可以通過vlan在局域網中通信,最后將f1/0接口同樣配置為trunk鏈路。
sw2#conf t //在2層交換設備中進入全局模式
Enter configuration commands, one per line. End with CNTL/Z.
sw2(config)#vlan 10,20,100 //配置vlan10、20、100
sw2(config-vlan)#ex //退出vlan接口
sw2(config)#do show vlan-sw b //查看vlna是否配置成功
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa1/0, Fa1/1, Fa1/2, Fa1/3
Fa1/4, Fa1/5, Fa1/6, Fa1/7
Fa1/8, Fa1/9, Fa1/10, Fa1/11
Fa1/12, Fa1/13, Fa1/14, Fa1/15
10 VLAN0010 active
20 VLAN0020 active //配置的vlan
100 VLAN0100 active
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
sw2(config)#int f1/1 //進入f1/1接口
sw2(config-if)#sw m acc //進入配置鏈路
sw2(config-if)#sw acc vlan 100 //將鏈路接入vlan100
sw2(config-if)#ex //退出
sw2(config)#int f1/2 //進入f1/2接口
sw2(config-if)#sw m acc //進入配置鏈路
sw2(config-if)#sw acc vlan 10 //將鏈路接入vlan10
sw2(config-if)#ex //退出
sw2(config)#int f1/3 //進入f1/3接口
sw2(config-if)#sw m acc //進入配置鏈路
sw2(config-if)#sw acc vlan 20 //將鏈路接入vlan20
sw2(config-if)#ex //退出
sw2(config)#do show vlan-sw b //查看vlna
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa1/0, Fa1/4, Fa1/5, Fa1/6
Fa1/7, Fa1/8, Fa1/9, Fa1/10
Fa1/11, Fa1/12, Fa1/13, Fa1/14
Fa1/15
10 VLAN0010 active Fa1/2
20 VLAN0020 active Fa1/3 //鏈路成功接入vlan
100 VLAN0100 active Fa1/1
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
sw2(config)#int f1/0 //進入f1/0接口
sw2(config-if)#sw m t //將接口配置為trunk
sw2(config-if)#sw t en do //在trunk鏈路中封裝dot1q協議
sw2(config-if)#ex //退出
sw2(config)#do show int f1/0 switchport //查看接口是否配置成功
Name: Fa1/0
Switchport: Enabled
Administrative Mode: trunk //成功配置trunk鏈路
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: Disabled
Access Mode VLAN: 0 ((Inactive))
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Trunking VLANs Active: 1,10,20,100
Protected: false
Priority for untagged frames: 0
Override vlan tag priority: FALSE
Voice VLAN: none
Appliance trust: none
sw2(config)#no ip routing //關閉2層交換設備路由功能
sw3(config)#vlan 10,20,100 //在3層交換設備中配置vlan10、20、100
sw3(config-vlan)#ex //退出
sw3(config)#do show vlan-sw b //查看vlan
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Fa1/0, Fa1/1, Fa1/2, Fa1/3
Fa1/4, Fa1/5, Fa1/6, Fa1/7
Fa1/8, Fa1/9, Fa1/10, Fa1/11
Fa1/12, Fa1/13, Fa1/14, Fa1/15
10 VLAN0010 active
20 VLAN0020 active //配置成功
100 VLAN0100 active
1002 fddi-default act/unsup
1003 token-ring-default act/unsup
1004 fddinet-default act/unsup
1005 trnet-default act/unsup
sw3(config)#int vlan 10 //進入虛擬接口vlan10
sw3(config-if)#ip add 192.168.10.1 255.255.255.0 //在接口中添加IP地址
sw3(config-if)#ip helper-address 192.168.100.100 //指定IP地址192.168.100.100可通過接口
sw3(config-if)#no shut //開啟配置
sw3(config-if)#ex //退出
sw3(config)#int vlan 20 //進入虛擬接口vlan20
sw3(config-if)#ip add 192.168.20.1 255.255.255.0 //在接口中添加IP地址
sw3(config-if)#ip helper-address 192.168.100.100 //指定IP地址192.168.100.100可通過接口
sw3(config-if)#no shut //開啟配置
sw3(config-if)#ex //退出
sw3(config)#int vlan 100 //進入虛擬接口vlan100
sw3(config-if)#ip add 192.168.100.1 255.255.255.0 //在接口中添加IP地址
sw3(config-if)#ip helper-address 192.168.100.100 //指定IP地址192.168.100.100可通過接口
sw3(config-if)#no shut //開啟配置
sw3(config-if)#ex //退出
sw3(config)#int f1/0 //進入f1/0 接口
sw3(config-if)#sw m t //配置為trunk鏈路
*Mar 1 00:22:18.607: %DTP-5-TRUNKPORTON: Port Fa1/0 has become dot1q trunk
*Mar 1 00:22:19.111: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
*Mar 1 00:22:19.119: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
*Mar 1 00:22:19.127: %LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan100, changed state to up
sw3(config-if)#sw t en do //封裝協議
sw3(config-if)#ex //突出
sw3(config)#do show int f1/0 switchport //查看trunk是否配置成功
Name: Fa1/0
Switchport: Enabled
Administrative Mode: trunk //成功配置trunk鏈路
Operational Mode: trunk
Administrative Trunking Encapsulation: dot1q
Operational Trunking Encapsulation: dot1q
Negotiation of Trunking: Disabled
Access Mode VLAN: 0 ((Inactive))
Trunking Native Mode VLAN: 1 (default)
Trunking VLANs Enabled: ALL
Trunking VLANs Active: 1,10,20,100
Protected: false
Priority for untagged frames: 0
Override vlan tag priority: FALSE
Voice VLAN: none
Appliance trust: none
sw3(config)#do show ip int b //查看IP地址是否配入vlan,是否開啟
Interface IP-Address OK? Method Status Protocol
FastEthernet0/0 unassigned YES unset administratively down down
FastEthernet0/1 unassigned YES unset administratively down down
FastEthernet1/0 unassigned YES unset up up
FastEthernet1/1 unassigned YES unset up down
...//省略部分內容...
FastEthernet1/14 unassigned YES unset up down
FastEthernet1/15 unassigned YES unset up down
Vlan1 unassigned YES unset up up
Vlan10 192.168.10.1 YES manual up up
Vlan20 192.168.20.1 YES manual up up
Vlan100 192.168.100.1 YES manual up up
//成功配入,并開啟
4、完成配置后我們來查看虛擬機客戶端win 10、win 7是否自動獲取IP地址
5、下面我們來給win 10 客戶機指定固定的IP地址,首先在win 10客戶機中獲取win 10客戶機網卡的MAC地址,然后會的CentOS 7系統中進入DHCP配置文件中進行設置
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。