不同vlan通过配置DHCP中继自动获取IP且互通

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了不同vlan通过配置DHCP中继自动获取IP且互通相关的知识,希望对你有一定的参考价值。

实验名称:不同vlan通过配置DHCP中继自动获取IP且互通
实验目的:配置DHCP使DHCP客户端自动获取到IP并保证pc机互通
实验拓扑:
技术分享图片
实验需求:四台 PC机,四台交换机,一台三层交换机,一台路由器,一台服务器
实验思路:
1、配置 DHCP 客户端
确保每个 PC 为 自动获取IP地址的方式;
2、配置交换机,确保DHCP客户端与服务器之间的 DHCP 报文互通;

将相关的端口,放入到对应的 VLAN ;

# 配置交换机之间的互联链路 - Trunk ; 

3、配置三层交换机
—配置与交换机之间的互联链路 - Trunk ;
—配置为 每个 VLAN 的网关
&开启路由功能
&配置每个VLAN对应的 SVI ;
&配置DHCP中继
&配置与 Router 的互联网段为三层端口
&配置与 Router 的互联端口的 IP 地址 - 192.168.88.0/24
&配置去往 DHCP 服务器网段的路由
4、配置 Router 的相关接口地址以及去往各个vlan的路由;
5、配置 DHCP-Server 的IP地址池
实验步骤:

  1. 配置DHCP客户端为“自动获取”
    技术分享图片
    Pc全部以上配置。
  2. 确保DHCP客户端与服务器之间的 DHCP 报文互通
    1) 创建vlan,将接口加入相应vlan,
    2) 交换机与交换机之间配置trunk模式
    Sw1:
    Switch>en
    Switch#configure terminal
    Enter configuration commands, one per line. End with CNTL/Z.
    Switch(config)#hostname sw1
    sw1(config)#vlan 10
    sw1(config-vlan)#vlan 20
    sw1(config-vlan)#vlan 30
    sw1(config-vlan)#vlan 40
    sw1(config-vlan)#exit
    sw1(config)#interface fastEthernet 0/1
    sw1(config-if)#switchport mode access
    sw1(config-if)#switchport access vlan 10
    sw1(config-if)#exit
    sw1(config)#interface fastEthernet 0/2
    sw1(config-if)#switchport mode access
    sw1(config-if)#switchport access vlan 20
    sw1(config-if)#exit
    sw1(config)#int
    sw1(config)#interface f
    sw1(config)#interface fastEthernet 0/3
    sw1(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 up
    sw1(config-if)#switchport trunk allowed vlan all
    sw1(config-if)#exit
    sw1(config)#interface fastEthernet 0/4
    sw1(config-if)#switchport mode trunk
    %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/4, changed state to down
    %LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/4, changed state to up
    sw1(config-if)#switchport trunk allowed vlan all
    sw1(config-if)#exit
    sw1(config)#interface fastEthernet 0/5
    sw1(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 up
    sw1(config-if)#switchport trunk allowed vlan all
    sw1(config-if)#exit

Sw2:
Switch>en
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname sw2
Sw2(config)#vlan 10
Sw2(config-vlan)#vlan 20
Sw2(config-vlan)#vlan 30
Sw2(config-vlan)#vlan 40
Sw2(config-vlan)#exit
Sw2(config)#interface fastEthernet 0/1
Sw2(config-if)#switchport mode access
Sw2(config-if)#switchport access vlan 30
Sw2(config-if)#exit
Sw2(config)#interface fastEthernet 0/2
Sw2(config-if)#switchport mode access
Sw2(config-if)#switchport access vlan 40
Sw2(config-if)#exit
Sw2(config)#int
Sw2(config)#interface f
Sw2(config)#interface fastEthernet 0/3
Sw2(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 up
Sw2(config-if)#switchport trunk allowed vlan all
Sw2(config-if)#exit
Sw2(config)#interface fastEthernet 0/4
Sw2(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 up
Sw2(config-if)#switchport trunk allowed vlan all
Sw2(config-if)#exit
Sw2(config)#interface fastEthernet 0/5
Sw2(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 up
Sw2(config-if)#switchport trunk allowed vlan all
Sw2(config-if)#exit

Sw3:
Switch>en
Switch#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname sw3
sw3(config)#vlan 10
sw3(config-vlan)#vlan 20
sw3(config-vlan)#vlan 30
sw3(config-vlan)#vlan 40
sw3(config-vlan)#exit
sw3(config)#interface fastEthernet 0/1
sw3(config-if)#switchport mode trunk
sw3(config-if)#switchport trunk allowed vlan all
sw3(config-if)#exit
sw3(config)#interface fastEthernet 0/2
sw3(config-if)#switchport mode trunk
sw3(config-if)#switchport trunk allowed vlan all
sw3(config-if)#exit
sw3(config)#interface fastEthernet 0/3
sw3(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 up
sw3(config-if)#switchport trunk allowed vlan all
sw3(config-if)#exit

Sw4:
Switch>en
Switch#configure
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname sw4
sw4(config)#vlan 10
sw4(config-vlan)#vlan 20
sw4(config-vlan)#vlan 30
sw4(config-vlan)#vlan 40
sw4(config-vlan)#exit
sw4(config)#interface fastEthernet 0/1
sw4(config-if)#switchport mode trunk
sw4(config-if)#switchport trunk allowed vlan all
sw4(config-if)#exit
sw4(config)#interface fastEthernet 0/2
sw4(config-if)#switchport mode trunk
sw4(config-if)#switchport trunk allowed vlan all
sw4(config-if)#exit
sw4(config)#interface fastEthernet 0/3
sw4(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 up
sw4(config-if)#switchport trunk allowed vlan all
sw4(config-if)#exit
sw4(config)#
3.配置三层交换机
1)配置与交换机之间的互联链路 为 Trunk模式 ;
Switch>enable
Switch#configure
Configuring from terminal, memory, or network [terminal]?
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#hostname gateway
gateway(config)#vlan 10
gateway(config-vlan)#vlan 20
gateway(config-vlan)#vlan 30
gateway(config-vlan)#vlan 40
gateway(config-vlan)#exit
gateway(config)#interface fastEthernet 0/1
gateway(config-if)#switchport trunk encapsulation dot1q
gateway(config-if)#switchport mode trunk
gateway(config-if)#switchport trunk allowed vlan all
gateway(config-if)#exit
gateway(config)#interface fastEthernet 0/2
gateway(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 all
gateway(config-if)#exit
2)配置每个vlan的网关
&开启路由功能
gateway(config)#ip routing
&配置每个VLAN对应的 SVI ;
gateway(config)#interface vlan 10
gateway(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
gateway(config-if)#no shutdown
gateway(config-if)#ip address 192.168.10.254 255.255.255.0
gateway(config-if)#exit
gateway(config)#interface vlan 20
%LINK-5-CHANGED: Interface Vlan20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
gateway(config-if)#no shutdown
gateway(config-if)#ip address 192.168.20.254 255.255.255.0
gateway(config-if)#exit
gateway(config)#interface vlan 30
%LINK-5-CHANGED: Interface Vlan30, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to up
gateway(config-if)#no shutdown
gateway(config-if)#ip address 192.168.30.254 255.255.255.0
gateway(config-if)#exit
gateway(config)#interface vlan 40
%LINK-5-CHANGED: Interface Vlan40, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan40, changed state to up
gateway(config-if)#no shutdown
gateway(config-if)#ip address 192.168.40.254 255.255.255.0
gateway(config-if)#exit
&配置与 Router 的互联网段为三层端口
gateway(config)#interface fastEthernet 0/3
&配置与 Router 的互联端口的 IP 地址 - 192.168.88.0/24
gateway(config-if)#no switchport
gateway(config-if)#no shutdown
gateway(config-if)#ip address 192.168.50.1 255.255.255.0
gateway(config-if)#exit
&配置去往 DHCP 服务器网段的路由
gateway(config)#ip route 192.168.60.0 255.255.255.0 192.168.50.2
gateway(config)#
3)配置DHCP中继
gateway(config)#interface vlan 10
gateway(config-if)#ip helper-address 192.168.60.1
gateway(config-if)#exit
gateway(config)#interface vlan 20
gateway(config-if)#ip help
gateway(config-if)#ip helper-address 192.168.60.1
gateway(config-if)#exit
gateway(config)#interface vlan 30
gateway(config-if)#ip helper-address 192.168.60.1
gateway(config-if)#exit
gateway(config)#interface vlan 40
gateway(config-if)#ip helper-address 192.168.60.1
gateway(config-if)#exit
gateway(config)#
4.配置router路由器
配置接口ip
Router>en
Router#configure terminal
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#interface gigabitEthernet 0/0
RRouter(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 up
Router(config-if)#ip address 192.168.50.2 255.255.255.0
Router(config-if)#exit
Router(config)#interface gigabitEthernet 0/1
Router(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 up
Router(config-if)#ip address 192.168.60.254 255.255.255.0
Router(config-if)#exit
配置去往 DHCP 客户器网段的路由
Router(config)#ip route 0.0.0.0 0.0.0.0 192.168.50.1
Router(config)#

5.配置DHCP服务端
配置DHCP服务端ip
技术分享图片
配置DHCP服务端的IP地址池
技术分享图片
验证与测试:
自动获取到IP地址:
Pc1:
技术分享图片
Pc2:
技术分享图片
Pc3:
技术分享图片
Pc4:
技术分享图片
四台PC机互通:
技术分享图片
技术分享图片

实验总结:
1.保证全网互通才能正常获取到IP。
2.配置三层交换机时,一定要记得IP routing。
3.想让DHCP客户端获取到DHCP服务端分配的IP地址,在三层交换机一定要配置DHCP中继。

以上是关于不同vlan通过配置DHCP中继自动获取IP且互通的主要内容,如果未能解决你的问题,请参考以下文章

不同VLAN通过配置DHCP自动获取IP

不同vlan间配置DHCP实现互通

DHCP中继配置

ENSP环境中不同vlan实现DHCP功能以及DHCP中继的配置

DHCP中继

第八期拓扑-三层交换机作为中继器服务器作为DHCP思科