交换机
接入层交换机:连接PC机
enable
config t
1、创建相应的vlan
vlan 10
2、连接终端的端口加入到相应的VLAN
interface range f0/1-2
switchport access vlan 10
exit
3、将交换机与交换机的端口配置成TRUNK
interface f0/3
switchport mode trunk
end
汇聚层交换机:
1、交换机与交换机相连的端口配置成trunk
Switch(config)#interface range f0/1-2
Switch(config-if-range)#sw m t
2、创建相应的vlan(本汇聚层交换机以下所有vlan)
Switch(config)#vlan 10
核心层交换机:
enable
conf t
vlan 10
vlan 20
vlan 30
interface range f0/1-3
switchport trunk en do
switchport mode trunk
exit
interface vlan 10
ip address 192.168.10.254 255.255.255.0
exit
interface vlan 20
ip address 192.168.20.254 255.255.255.0
exit
interface vlan 30
ip address 192.168.30.254 255.255.255.0
exit
ip routing //启用ip路由功能
interface f0/1
no switchport
ip address 192.168.40.2 255.255.255.0
end
write
enable
conf t
vlan 40
vlan 50
int rang f0/2
switchport trunk en do
switchport mode trunk
exit
interface vlan 40
ip address 100.100.100.1 255.255.255.0
exit
interface vlan 50
ip address 110.110.110.1 255.255.255.0
ip routing
interface f0/1
no switchport
ip address 54.1.1.2 255.255.255.0
end
write
三层
router rip
network 54.1.1.0
network 100.100.100.0
network 110.110.110.0
路由5
conf t
router rip
network 45.1.1.0
network 54.1.1.0
路由4
en
show ip route
conf t
router rip
network 45.1.1.0
network 64.1.1.0
路由6
en
show ip route
conf t
router rip
network 64.1.1.0
路由6
en
conf t
access-list 1 permit 192.168.10.0 0.0.0.255
access-list 1 permit 192.168.20.0 0.0.0.255
ip nat inside source list 1 interface f0/1
interface f0/0
ip nat inside
exit
interface f0/1
ip nat outside
路由6
Router(config)#ip route 192.168.20.0 255.255.255.0 192.168.40.2
Router(config)#ip route 192.168.10.0 255.255.255.0 192.168.40.2
Router(config)#ip route 192.168.30.0 255.255.255.0 192.168.40.2
access-list 1 permit 192.168.30.0 0.0.0.255
RIP
RIP(Routing Information Protocol,路由信息协议)是一种内部网关协议(IGP),是一种动态路由选择协议,用于自治系统(AS)内的路由信息的传递。
如何配置动态路由协议RIP(内网三层设备都要rip,边界路由器)
Switch#show 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, 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
54.0.0.0/24 is subnetted, 1 subnets
C 54.1.1.0 is directly connected, FastEthernet0/1
100.0.0.0/24 is subnetted, 1 subnets
C 100.100.100.0 is directly connected, Vlan40
110.0.0.0/24 is subnetted, 1 subnets
C 110.110.110.0 is directly connected, Vlan50
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#router rip (将C网段添加到RIP)
Switch(config-router)#network 54.1.1.0
Switch(config-router)#network 100.100.100.0
Switch(config-router)#network 110.110.110.0
- candidate default, U - per-user static route, o - ODR
端口映射
端口映射:Router(config)#ip nat inside source static tcp 192.168.10.1 80 64.1.1.1 80
NAT
NAT上网的思路
1、内网做通(ok)
2、外网做通(ok)
3、采用NAT将内外网连通
NAT配置的位置:内网与外网相交的三层设备上进行配置
1、控制内网要上网的网段。
Router(config)#access-list 1 permit 192.168.10.0 0.0.0.255
Router(config)#access-list 1 permit 192.168.20.0 0.0.0.255
2、实现内网到外网的转换
Router(config)#ip nat inside source list 1 interface f0/1
inside source list 1 :内网要上网的网段
interface f0/1 (本路由器的外网接口)
3、指定本路由器内外网接口
Router(config)#interface f0/0
Router(config-if)#ip nat inside
Router(config-if)#exit
Router(config)#interface f0/1
Router(config-if)#ip nat outside
注意:内网所有的三层设备需要配置一个默认路由到公网:
Switch(config)#ip route 0.0.0.0 0.0.0.0 192.168.40.1
端口映射:Router(config)#ip nat inside source static tcp 192.168.10.1 80 64.1.1.1 80
路由器
路由器端口设置ip
1.规划网段
2.配置ip
3.配路由协议(让路由层面互通)
en
conf t
interface f0/0
no shutdown
ip address 192.168.50.2 255.255.255.0
exit
interface f0/1
no shutdown
ip address 192.168.50.1 255.255.255.0
exit
DHCP
en
conf t
ip dhcp pool pc0
network 192.168.10.0 255.255.255.0
default-router 192.168.10.254
exit
设置DNS
dns-server 192.168.110.2
OSPF
Open Shortest Path First 开放最短路径优化路由协议
show ip route
en
conf t
router ospf 1 //进程号
network 192.168.10.0 0.0.0.255 area 0
network 192.168.20.0 0.0.0.255 area 0
// network 直连网段 反子网掩码 直连网段所处区域
虚拟链路
虚拟路配置方法二:(企业里面标准做法)
R2
创建回环接口,ip随便
interface loopback 1
ip address 2.2.2.2 255.255.255.0
将回环接口指定为路由的身份证
show ip protocols
router ospf 1
router-id 2.2.2.2
write
clear ip ospf process #重启OSPF路由协议,让配置生效
将回环接口所在网段network到两个区域之间区域
rouer ospf 1
network 2.2.2.0 0.0.0.255 area 2
创建虚链路
router ospf 1
area 2(两个区域之间的区域) virtual-link 4.4.4.4(对方的身份证)
R4
创建回环接口
interface loopback 1
ip address 4.4.4.4 255.255.255.0
将回环接口指定为路由的身份证
router ospf 1
router-id 4.4.4.4
write
clear ip ospf process
将回环接口所在网段network到两个区域之间区域
rouer ospf 1
network 4.4.4.0 0.0.0.255 area 2
创建虚链路
router ospf 1
area 2(两个区域之间的区域) virtual-link 2.2.2.2(对方的身份证)
检查是否成功
Router#show ip ospf neighbor
Neighbor ID Pri State Dead Time Address Interface
12.1.1.1 1 FULL/DR 00:00:35 12.1.1.1 FastEthernet0/0
34.1.1.3 1 FULL/DR 00:00:32 23.1.1.3 FastEthernet0/1
4.4.4.4 0 FULL/ - 00:00:38 34.1.1.4 OSPF_VL0
R1 ping R5能 ping通
HSRF
两个交换机都要配
en
conf t
int vlan 10
standby 2 ip 192.168.20.253
修改pc的网关为192.168.10.253
VPN
router0
Router(config)#interface tunnel 1
Router(config-if)#tunnel source f0/1 (接口给本路由器的公网接口)
Router(config-if)#tunnel destination 110.110.110.2(给对方的公网地址)
router2
interface tunnel 1
tunnel source f0/0
tunnel destination 100.100.100.1
Router0
Router(config)#interface tunnel 1
Router(config-if)#ip address 1.1.1.1 255.255.255.0
Router2
Router(config)#interface tunnel 1
Router(config-if)#ip address 1.1.1.2 255.255.255.0
测试隧道是否能够通信。
Router#ping 1.1.1.1
第六部:将隧道接口所有的网段network到总部与分部所有的路由协议(rip\ospf)里面去。
Router0
Router(config)#router ospf 1
Router(config-router)#network 1.1.1.0 0.0.0.255 area 0
Router2
Router(config)#router ospf 1
Router(config-router)#network 1.1.1.0 0.0.0.255 area 0
或者
Router0
Router(config)#router rip
Router(config-router)#network 1.1.1.0
Router2
Router(config)#router rip
Router(config-router)#network 1.1.1.0