1. 组网需求
Switch的端口(属于VLAN 1)连接一个局域网,局域网中的计算机分别属于2个网段:172.16.1.0/24和172.16.2.0/24。要求这两个网段的主机都可以通过Switch与外部网络通信,且这两个网段中的主机能够互通。
2. 组网图
3. 配置步骤
Switch system-view
[Switch] interface vlan-interface 1
[Switch-Vlan-interface1] ip address 172.16.1.1 255.255.255.0
[Switch-Vlan-interface1] ip address 172.16.2.1 255.255.255.0 sub
# 在172.16.1.0/24网段中的主机上配置网关为172.16.1.1;在172.16.2.0/24网段中的主机上配置网关为172.16.2.1。
4. 验证配置
# 使用ping命令检测Switch与网络172.16.1.0/24内主机的连通性。
Switch ping 172.16.1.2
PING 172.16.1.2 (172.16.1.2): 56 data bytes
56 bytes from 172.16.1.2: icmp_seq=0 ttl=254 time=7.000 ms
56 bytes from 172.16.1.2: icmp_seq=1 ttl=254 time=0.000 ms
56 bytes from 172.16.1.2: icmp_seq=2 ttl=254 time=1.000 ms
56 bytes from 172.16.1.2: icmp_seq=3 ttl=254 time=1.000 ms
56 bytes from 172.16.1.2: icmp_seq=4 ttl=254 time=2.000 ms
--- 172.16.1.2 ping statistics ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/stddev = 0.000/2.200/7.000/2.482 ms
显示信息表示Switch与网络172.16.1.0/24内的主机可以互通。
# 使用ping命令检测Switch与网络172.16.2.0/24内主机的连通性。
Switch ping 172.16.2.2
PING 172.16.2.2 (172.16.2.2): 56 data bytes
56 bytes from 172.16.2.2: icmp_seq=0 ttl=255 time=2.000 ms
56 bytes from 172.16.2.2: icmp_seq=1 ttl=255 time=7.000 ms
56 bytes from 172.16.2.2: icmp_seq=2 ttl=255 time=1.000 ms
56 bytes from 172.16.2.2: icmp_seq=3 ttl=255 time=2.000 ms
56 bytes from 172.16.2.2: icmp_seq=4 ttl=255 time=1.000 ms
--- 172.16.2.2 ping statistics ---
5 packet(s) transmitted, 5 packet(s) received, 0.0% packet loss
round-trip min/avg/max/stddev = 1.000/2.600/7.000/2.245 ms
显示信息表示Switch与网络172.16.2.0/24内的主机可以互通。
# 使用ping命令检测网络172.16.1.0/24和网络172.16.2.0/24内主机的连通性。在Host A上可以ping通Host B。