本文共 9351 字,大约阅读时间需要 31 分钟。
实验名称:不同vlan通过配置DHCP中继自动获取IP且互通
实验目的:配置DHCP使DHCP客户端自动获取到IP并保证pc机互通实验拓扑:实验需求:四台 PC机,四台交换机,一台三层交换机,一台路由器,一台服务器实验思路:1、配置 DHCP 客户端 确保每个 PC 为 自动获取IP地址的方式; 2、配置交换机,确保DHCP客户端与服务器之间的 DHCP 报文互通;# 配置交换机之间的互联链路 - Trunk ;
3、配置三层交换机
—配置与交换机之间的互联链路 - Trunk ; —配置为 每个 VLAN 的网关&开启路由功能&配置每个VLAN对应的 SVI ;&配置DHCP中继&配置与 Router 的互联网段为三层端口&配置与 Router 的互联端口的 IP 地址 - 192.168.88.0/24&配置去往 DHCP 服务器网段的路由4、配置 Router 的相关接口地址以及去往各个vlan的路由;5、配置 DHCP-Server 的IP地址池实验步骤:Sw2:
Switch>enSwitch#configure terminal Enter configuration commands, one per line. End with CNTL/Z.Switch(config)#hostname sw2Sw2(config)#vlan 10Sw2(config-vlan)#vlan 20Sw2(config-vlan)#vlan 30Sw2(config-vlan)#vlan 40Sw2(config-vlan)#exitSw2(config)#interface fastEthernet 0/1Sw2(config-if)#switchport mode access Sw2(config-if)#switchport access vlan 30Sw2(config-if)#exitSw2(config)#interface fastEthernet 0/2Sw2(config-if)#switchport mode access Sw2(config-if)#switchport access vlan 40Sw2(config-if)#exitSw2(config)#intSw2(config)#interface fSw2(config)#interface fastEthernet 0/3Sw2(config-if)#switchport mode trunk %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to upSw2(config-if)#switchport trunk allowed vlan all Sw2(config-if)#exitSw2(config)#interface fastEthernet 0/4Sw2(config-if)#switchport mode trunk %LNEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/4, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/4, changed state to upSw2(config-if)#switchport trunk allowed vlan allSw2(config-if)#exitSw2(config)#interface fastEthernet 0/5Sw2(config-if)#switchport mode trunk %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/5, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/5, changed state to upSw2(config-if)#switchport trunk allowed vlan allSw2(config-if)#exitSw3:
Switch>en Switch#configure terminal Enter configuration commands, one per line. End with CNTL/Z.Switch(config)#hostname sw3sw3(config)#vlan 10sw3(config-vlan)#vlan 20sw3(config-vlan)#vlan 30sw3(config-vlan)#vlan 40sw3(config-vlan)#exitsw3(config)#interface fastEthernet 0/1sw3(config-if)#switchport mode trunk sw3(config-if)#switchport trunk allowed vlan allsw3(config-if)#exitsw3(config)#interface fastEthernet 0/2sw3(config-if)#switchport mode trunk sw3(config-if)#switchport trunk allowed vlan allsw3(config-if)#exitsw3(config)#interface fastEthernet 0/3sw3(config-if)#switchport mode trunk %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to upsw3(config-if)#switchport trunk allowed vlan allsw3(config-if)#exitSw4:
Switch>enSwitch#configure Configuring from terminal, memory, or network [terminal]? Enter configuration commands, one per line. End with CNTL/Z.Switch(config)#hostname sw4sw4(config)#vlan 10sw4(config-vlan)#vlan 20sw4(config-vlan)#vlan 30sw4(config-vlan)#vlan 40sw4(config-vlan)#exitsw4(config)#interface fastEthernet 0/1sw4(config-if)#switchport mode trunk sw4(config-if)#switchport trunk allowed vlan allsw4(config-if)#exitsw4(config)#interface fastEthernet 0/2sw4(config-if)#switchport mode trunk sw4(config-if)#switchport trunk allowed vlan allsw4(config-if)#exitsw4(config)#interface fastEthernet 0/3sw4(config-if)#switchport mode trunk sw4(config-if)#%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to down%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/3, changed state to upsw4(config-if)#switchport trunk allowed vlan allsw4(config-if)#exitsw4(config)#3.配置三层交换机1)配置与交换机之间的互联链路 为 Trunk模式 ;Switch>enableSwitch#configure Configuring from terminal, memory, or network [terminal]? Enter configuration commands, one per line. End with CNTL/Z.Switch(config)#hostname gatewaygateway(config)#vlan 10gateway(config-vlan)#vlan 20gateway(config-vlan)#vlan 30gateway(config-vlan)#vlan 40gateway(config-vlan)#exitgateway(config)#interface fastEthernet 0/1gateway(config-if)#switchport trunk encapsulation dot1q gateway(config-if)#switchport mode trunk gateway(config-if)#switchport trunk allowed vlan allgateway(config-if)#exitgateway(config)#interface fastEthernet 0/2gateway(config-if)#switchport trunk encapsulation gateway(config-if)#switchport trunk encapsulation dot1q gateway(config-if)#switchport mode trunk gateway(config-if)#switchport trunk allowed vlan allgateway(config-if)#exit2)配置每个vlan的网关&开启路由功能gateway(config)#ip routing &配置每个VLAN对应的 SVI ;gateway(config)#interface vlan 10gateway(config-if)#%LINK-5-CHANGED: Interface Vlan10, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to upgateway(config-if)#no shutdown gateway(config-if)#ip address 192.168.10.254 255.255.255.0gateway(config-if)#exitgateway(config)#interface vlan 20%LINK-5-CHANGED: Interface Vlan20, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to upgateway(config-if)#no shutdown gateway(config-if)#ip address 192.168.20.254 255.255.255.0gateway(config-if)#exitgateway(config)#interface vlan 30%LINK-5-CHANGED: Interface Vlan30, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to upgateway(config-if)#no shutdown gateway(config-if)#ip address 192.168.30.254 255.255.255.0gateway(config-if)#exitgateway(config)#interface vlan 40%LINK-5-CHANGED: Interface Vlan40, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan40, changed state to upgateway(config-if)#no shutdown gateway(config-if)#ip address 192.168.40.254 255.255.255.0gateway(config-if)#exit&配置与 Router 的互联网段为三层端口gateway(config)#interface fastEthernet 0/3&配置与 Router 的互联端口的 IP 地址 - 192.168.88.0/24gateway(config-if)#no switchport gateway(config-if)#no shutdown gateway(config-if)#ip address 192.168.50.1 255.255.255.0gateway(config-if)#exit&配置去往 DHCP 服务器网段的路由gateway(config)#ip route 192.168.60.0 255.255.255.0 192.168.50.2gateway(config)#3)配置DHCP中继gateway(config)#interface vlan 10gateway(config-if)#ip helper-address 192.168.60.1gateway(config-if)#exitgateway(config)#interface vlan 20gateway(config-if)#ip helpgateway(config-if)#ip helper-address 192.168.60.1gateway(config-if)#exitgateway(config)#interface vlan 30gateway(config-if)#ip helper-address 192.168.60.1gateway(config-if)#exitgateway(config)#interface vlan 40gateway(config-if)#ip helper-address 192.168.60.1gateway(config-if)#exitgateway(config)#4.配置router路由器配置接口ipRouter>enRouter#configure terminal Enter configuration commands, one per line. End with CNTL/Z.Router(config)#interface gigabitEthernet 0/0RRouter(config-if)#no shutdown %LINK-5-CHANGED: Interface GigabitEthernet0/0, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/0, changed state to upRouter(config-if)#ip address 192.168.50.2 255.255.255.0Router(config-if)#exitRouter(config)#interface gigabitEthernet 0/1Router(config-if)#no shutdown Router(config-if)#%LINK-5-CHANGED: Interface GigabitEthernet0/1, changed state to up%LINEPROTO-5-UPDOWN: Line protocol on Interface GigabitEthernet0/1, changed state to upRouter(config-if)#ip address 192.168.60.254 255.255.255.0Router(config-if)#exit配置去往 DHCP 客户器网段的路由Router(config)#ip route 0.0.0.0 0.0.0.0 192.168.50.1Router(config)#5.配置DHCP服务端
配置DHCP服务端ip配置DHCP服务端的IP地址池验证与测试:自动获取到IP地址:Pc1:Pc2:Pc3:Pc4:四台PC机互通:实验总结:
1.保证全网互通才能正常获取到IP。2.配置三层交换机时,一定要记得IP routing。3.想让DHCP客户端获取到DHCP服务端分配的IP地址,在三层交换机一定要配置DHCP中继。转载于:https://blog.51cto.com/13557013/2059596