实验:通过DHCP能够使内网互通;配置骨干网络出口;
配置SW2的vlan
<Huawei>sys
[Huawei]sys SW2
[SW2]vlan batch 10 20
[SW2]int g0/0/1
[SW2-GigabitEthernet0/0/1]port link-type access
[SW2-GigabitEthernet0/0/1]port default vlan 10
[SW2-GigabitEthernet0/0/1]int g0/0/2
[SW2-GigabitEthernet0/0/2]port link-type access
[SW2-GigabitEthernet0/0/2]port default vlan 20
[SW2-GigabitEthernet0/0/2]int g0/0/3
[SW2-GigabitEthernet0/0/3]port link-type trunk
[SW2-GigabitEthernet0/0/3]port trunk allow-pass vlan 10 20
配置SW1的vlan 和 DHCP
<Huawei>sys
[Huawei]sys SW1
[SW1]vlan batch 10 20 30
[SW1]int g0/0/3
[SW1-GigabitEthernet0/0/3]port link-type trunk
[SW1-GigabitEthernet0/0/3]port trunk allow-pass vlan 10 20
[SW1-GigabitEthernet0/0/3]int vlanif 10
[SW1-Vlanif10]ip add 192.168.10.254 24
[SW1-Vlanif10]int vlanif 20
[SW1-Vlanif20]ip add 192.168.20.254 24
[SW1-Vlanif20]dhcp en //开启dhcp
[SW1]ip pool 10 //建立地址池名为10
[SW1-ip-pool-10]net 192.168.10.0 mask 24 //DHCP网段
[SW1-ip-pool-10]gateway-list 192.168.10.254 //网关
[SW1-ip-pool-10]dns 114.114.114.114 //dns地址
[SW1-ip-pool-10]lease day 1 //租期为一天
[SW1-ip-pool-10]int vlanif 10
[SW1-Vlanif10]dhcp select global //开启全局,从配置地址池中找到vlan 10的地址
[SW1-Vlanif10]int vlanif 20
[SW1-Vlanif20]ip pool 20
[SW1-ip-pool-20]network 192.168.20.0 mask 24
[SW1-ip-pool-20]gateway-list 192.168.20.254
[SW1-ip-pool-20]dns 8.8.8.8
[SW1-ip-pool-20]lease day 1
[SW1-ip-pool-20]excluded-ip-address 192.168.20.10 192.168.20.253 //排除地址10-253地址
[SW1-ip-pool-20]int vlanif 20
[SW1-Vlanif20]dhcp select global
通过在PC 1、PC2使用ipconfig查看是否可以获取IP地址。
配置骨干路由之间可以通信,SW1、R3
[SW1]int vlanif 30
[SW1-Vlanif30]ip add 192.168.30.254 24
[SW1-Vlanif30]int g0/0/1
[SW1-GigabitEthernet0/0/1]port link-type access
[SW1-GigabitEthernet0/0/1]port default vlan 30
查看R3是否与SW1之间能够通信,但是PC ping R3是不能ping通的,因为路由表里面没有路由10和20网段,R3没有回程。(可以在R3配置静态路由、动态路由、RIP)
这里就配置OSPF
[R3]ospf 1
[R3-ospf-1]area 0
[R3-ospf-1-area-0.0.0.0]network 192.168.10.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 192.168.20.0 0.0.0.255
[R3-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255
[SW1]ospf 1
[SW1-ospf-1]area 0
[SW1-ospf-1-area-0.0.0.0]network 192.168.10.0 0.0.0.255
[SW1-ospf-1-area-0.0.0.0]network 192.168.20.0 0.0.0.255
[SW1-ospf-1-area-0.0.0.0]network 192.168.30.0 0.0.0.255
此时PC都可以ping通10和20网段
配置出口地址(比较麻烦)
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]ip add 12.1.1.3 24
[R3-GigabitEthernet0/0/0]int g0/0/2
[R3-GigabitEthernet0/0/2]ip add 23.1.1.3 24
<dianxin>sys
[dianxin]int g0/0/1
[dianxin-GigabitEthernet0/0/1]ip add 100.1.1.2 24
[dianxin-GigabitEthernet0/0/1]int g0/0/2
[dianxin-GigabitEthernet0/0/2]ip add 23.1.1.2 24
[dianxin]int lo0
[dianxin-LoopBack0]ip add 2.2.2.2 24
<yidong>sys
[yidong]int g0/0/1
[yidong-GigabitEthernet0/0/1]ip add 100.1.1.1 24
[yidong-GigabitEthernet0/0/1]int g0/0/0
[yidong-GigabitEthernet0/0/0]ip add 12.1.1.1 24
[yidong-GigabitEthernet0/0/0]int lo0 //配置环回口
[yidong-LoopBack0]ip add 1.1.1.1 24
运营商这边使用RIP协议使他们能够互通互相交换“资料”。
[yidong]rip
[yidong-rip-1]version 2
[yidong-rip-1]network 100.0.0.0
[yidong-rip-1]network 12.0.0.0
[yidong-rip-1]network 1.0.0.0
[dianxin-rip-1]version 2
[dianxin-rip-1]net 100.0.0.0
[dianxin-rip-1]net 23.0.0.0
[dianxin-rip-1]net 2.0.0.0
出口路由器R3配置NAT转换
[R3]acl 2000
[R3-acl-basic-2000]rule 5 permit source 192.168.10.0 0.0.0.255
[R3-acl-basic-2000]rule 10 permit source 192.168.20.0 0.0.0.255
[R3]int g0/0/0
[R3-GigabitEthernet0/0/0]nat outbound 2000
[R3-GigabitEthernet0/0/1]int g0/0/2
[R3-GigabitEthernet0/0/2]nat outbound 2000
此时PC是ping不通运营商的,因为SW1没有目的IP路由,所以已经886了,要配置默认路由
<SW1>sys
[SW1]ip route-static 0.0.0.0 0 192.168.32.3