应用场景描述:
某企业划分多个VLAN,连接在接入层交换机上,为了实现VLAN之间的通信,采用了三层交换机。企业需要与远程机构连接,三层交换机连接到路由器上,路由起连接到远
程机构。
使用到的相关知识点总结:
1.启动路由功能: ip routing
2.配置VLANIP地址:  
  Int vlan vlan-id
  Ip  address ip-address subnet-mask
  No shut
3.查看FIB  show ip cef
4.查看邻接关系表 show  adjacency  detail 
5.在三层交换机上配置路由接口: no  switchport
6.在三层交换机上配置静态或动态路由:
在三层交换机上配置静态路由或动态路由的方法与在路由器上配置路由的方法相同。
7.配置DHCP中继转发:
  Int vlan  vlan-id
  Ip  helper-address  Dhcpserver-add
8.查看路由表: show  ip  route
9.释放IPipconfig /release
 重新获取IPipconfig /renew
10.show ip cef  ……………查看FIB
11.show adjacency detail …………查看邻接关系表
12.show ip route ……………查看路由表
步骤:
配置三层交换机VLAN信息,设置VTP的相关信息,配置三层交换机VLAN IP地址,配置三层交换机DHCP中继
配置命令
ena
 vlan data
 vtp dom abc
 vlan 2
 vlan 3
 vlan 4
 vlan 5
 exit
 conf  t
ip routing
hostname mls3
int range F0/1 -2
 switchport  mode  trunk
 exit
int F/15
swit  access  vlan 5
 exit
int  vlan 5
  ip address 10.0.0 .1 255.0.0.0
  no sh
  exit
int  Vlan 1
  ip address 192.168.10.1 255.255.255.0
  ip helper-address 192.168.30.2
  no sh
  exit
int  Vlan 2
  ip address 192.168.20.1 255.255.255.0
  ip helper-address 192.168.30.2
  no sh
  exit
int  Vlan 3
  ip address 192.168.30.1 255.255.255.0
  no sh
  exit
int  Vlan 4
  ip address 192.168.40.1 255.255.255.0
  ip helper-address 192.168.30.2
  no sh
  exit
router rip
version 2
no auto-summary
 network 10.0.0 .0
 network 192.168.10.0
 network 192.168.20.0
 network 192.168.30.0
 network 192.168.40.0
 exit
 exit
 wri
验证结果
mls3#sh vlan b
*Mar  1 01:02:52.851: %CDP-4-DUPLEX_MISMATCH: duplex mismatch discovered on FastEthernet0/2 (not half duplex), with pc2 Ethernet0/0 (half duplex).s
 
VLAN Name                             Status    Ports
1    default                          active    Fa0/0, Fa0/3, Fa0/4, Fa0/5
                                                Fa0/6, Fa0/7, Fa0/8, Fa0/9
                                                Fa0/10, Fa0/11, Fa0/12, Fa0/13
                                                Fa0/14
2    VLAN0002                         active   
3    VLAN0003                         active   
4    VLAN0004                         active   
5    VLAN0005                         active    Fa0/15
1002 fddi-default                     active   
1003 token-ring-default               active   
1004 fddinet-default                  active   
1005 trnet-default                    active   
mls3#sh ip route
Codes: C - connected, S - static, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF , IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
C    192.168.30.0/24 is directly connected, Vlan3
C    192.168.10.0/24 is directly connected, Vlan1
C    192.168.40.0/24 is directly connected, Vlan4
C    192.168.20.0/24 is directly connected, Vlan2
     10.0.0 .0/24 is subnetted, 1 subnets
C       10.0.0 .0 is directly connected, Vlan5
mls3#sh ip int b
Interface                  IP-Address      OK? Method Status                Protocol
FastEthernet0/0            unassigned      YES unset  up                    down   
FastEthernet0/1            unassigned      YES unset  up                    up     
FastEthernet0/2            unassigned      YES unset  up                    up     
FastEthernet0/3            unassigned      YES unset  up                    down   
FastEthernet0/4            unassigned      YES unset  up                    down   
FastEthernet0/5            unassigned      YES unset  up                    down   
FastEthernet0/6            unassigned      YES unset  up                    down   
FastEthernet0/7            unassigned      YES unset  up                    down   
FastEthernet0/8            unassigned      YES unset  up                    down   
FastEthernet0/9            unassigned      YES unset  up                    down   
FastEthernet0/10           unassigned      YES unset  up                    down   
FastEthernet0/11           unassigned      YES unset  up                    down   
FastEthernet0/12           unassigned      YES unset  up                    down   
FastEthernet0/13           unassigned      YES unset  up                    down   
FastEthernet0/14           unassigned      YES unset  up                    down   
FastEthernet0/15           unassigned      YES unset  up                    up     
Vlan1                      192.168.10.1    YES manual up                    up     
Vlan2                      192.168.20.1    YES manual up                    up     
Vlan3                      192.168.30.1    YES manual up                    up     
Vlan4                      192.168.40.1    YES manual up                    up     
Vlan5                      10.0.0 .1        YES manual up
--More--
*Mar  1 01:07:52.731: %CDP-4-DUPLEX_MISMATCH: duplex mismatch discovered on FastEthernet0/2 (not half duplex), with pc2 Ethernet0/0 (halinterface FastEthernet0/15
 switchport access vlan 5
!        
interface Vlan1
 ip address 192.168.10.1 255.255.255.0
 ip helper-address 192.168.30.2
!        
interface Vlan2
 ip address 192.168.20.1 255.255.255.0
 ip helper-address 192.168.30.2
!        
interface Vlan3
 ip address 192.168.30.1 255.255.255.0
!        
interface Vlan4
 ip address 192.168.40.1 255.255.255.0
 ip helper-address 192.168.30.2
*Mar  1 01:07:58.347: %CDP-4-DUPLEX_MISMATCH: duplex mismatch discovered on FastEthernet0/15 (not half duplex), with r4 Ethernet0/0 (halinterface Vlan5
 ip address 10.0.0 .1 255.255.255.0
router rip
 version 2
 network 10.0.0 .0
 network 192.168.10.0
 network 192.168.20.0
 network 192.168.30.0
 network 192.168.40.0
 no auto-summary
   配置路由器
ena
conf  t
hostname r4
  int  e0/0
  ip add 10.0.0 .2 255.0.0.0
  no sh
  exit
  ip route 0.0.0 .0 0.0.0.0  e0/1
  router rip
  network 10.0.0 .0
  version 2
  no auto-summary
  exit
exit
wri
验证结果
r4#sh ip route
Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
       D - EIGRP, EX - EIGRP external, O - OSPF , IA - OSPF inter area
       N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
       E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
       i - IS-IS, su - IS-IS summary, L1 - IS-IS level-1, L2 - IS-IS level-2
       ia - IS-IS inter area, * - candidate default, U - per-user static route
       o - ODR, P - periodic downloaded static route
Gateway of last resort is not set
 R    192.168.30.0/24 [120/1] vi a 10.0.0 .1, 00:00:14, Ethernet0/0
R    192.168.10.0/24 [120/1] vi a 10.0.0 .1, 00:00:14, Ethernet0/0
R    192.168.40.0/24 [120/1] vi a 10.0.0 .1, 00:00:14, Ethernet0/0
R    192.168.20.0/24 [120/1] vi a 10.0.0 .1, 00:00:14, Ethernet0/0
C    10.0.0 .0/8 is directly connected, Ethernet0/0
配置接入层交换机BC
ena
vlan  database
vtp  domain abc
vtp  client
exit
conf  t
hostname  sw2
  int   f0/15
  swit  mode  tru
  exit
  int  f0/1
  swit  access  vlan 2
  exit
exit
wri
****************************
ena
vlan database
vtp  domain abc
vtp  client
exit
conf t
hostname sw3
  int F0/1
  switchport access vlan 4
  exit
  int F0/10
  switchport access vlan 3
  exit
  interface FastEthernet0/15
  switchport mode trunk
  exit
exit
wri
*************************
3.2:验证结果
w2# sh  vlan  b
*Mar  1 01:12:42.443: %CDP-4-DUPLEX_MISMATCH: duplex mismatch discovered on FastEthernet0/15 (not half duplex), with pc3 Ethernet0/0 (half duplex)
VLAN Name                             Status    Ports
1    default                          active    Fa0/0, Fa0/2, Fa0/3, Fa0/4
                                                Fa0/5, Fa0/6, Fa0/7, Fa0/8
                                                Fa0/9, Fa0/10, Fa0/11, Fa0/12
                                                Fa0/13, Fa0/14
2    VLAN0002                         active    Fa0/1
3    VLAN0003                         active   
4    VLAN0004                         active   
5    VLAN0005                         active   
1002 fddi-default                     active   
1003 token-ring-default               active   
1004 fddinet-default                  active   
1005 trnet-default                    active   
sw3#sh vlan b
VLAN Name                             Status    Ports
1    default                          active    Fa0/0, Fa0/2, Fa0/3, Fa0/4
                                                Fa0/5, Fa0/6, Fa0/7, Fa0/8
                                                Fa0/9, Fa0/11, Fa0/12, Fa0/13
                                                Fa0/14
2    VLAN0002                         active   
3    VLAN0003                         active    Fa0/10
4    VLAN0004                         active    Fa0/1
5    VLAN0005                         active   
1002 fddi-default                     active   
1003 token-ring-default               active   
1004 fddinet-default                  active   
1005 trnet-default                    active
*************************************
实验结果:
pc1#sh ip int b
Interface                  IP-Address      OK? Method Status                Protocol
Ethernet0/0                192.168.20.5    YES DHCP   up                    up     
Ethernet0/1                unassigned      YES unset  administratively down down   
Ethernet0/2                unassigned      YES unset  administratively down down   
Ethernet0/3                unassigned      YES unset  administratively down down  
pc1#ping 192.168.30.2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.30.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 72/120/172 ms
pc1#ping 192.168.20.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.30.2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 240/298/456 ms
pc1#ping 192.168.10.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.10.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 72/111/124 ms
pc1#ping 192.168.40.1
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 192.168.40.1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 96/135/220 ms
pc1#ping 10.0.0 .1   
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.0 .1, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 148/207/312 ms
pc1#ping 10.0.0 .2
Type escape sequence to abort.
Sending 5, 100-byte ICMP Echos to 10.0.0 .2, timeout is 2 seconds:
!!!!!
Success rate is 100 percent (5/5), round-trip min/avg/max = 144/216/288 ms
总结:
1. 把路由器模拟成一个PC。使用命令no  ip routing
2. 三层交换机上可以把接入路由器的端口设置no swit
也可以把端口加入到一个VLAN 里,这样还可以做备份
3. ip add dhcp 这是自动获取IP地址命令
4. 如果是把三层交换机端口设置成路由接口,当配置了IP地址后不需要 no sh
5. 在三层交换机上设置路由信息和路由器上一样。
6. ip routing 配置三层交换机启动路由功能。
7.    在路由器上设置下一跳地址时,只要是可以pingIP地址,都可以作为下一跳地址.
8.    在路由器上设置DHCP服务:
ip dhcp excluded-address 192.168.30.1 .........去除不给分配的IP地址
service dhcp ………………启用DHCP服务
ip dhcp pool v1 ……………创建DHCP池名字为V1
  network 192.168.10.0 255.255.255.0 ……DHCP池的网段
  dns-server 100.0.0.1  …………地址池的DNS地址
  default-router 192.168.10.1 ………地址池网关