下面来配置二层交换机s1:
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10 #命令vlan
Switch(config-vlan)#name Employee
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#name service
Switch(config-vlan)#exit
Switch(config)#int ra f0/1-10 #加上range(缩写为ra)一次编辑多个端口
Switch(config-if-range)#swi access vlan 10 #将0-10端口接入vlan10
Switch(config-if-range)#exit
Switch(config)#int ra f0/11-20
Switch(config-if-range)#swi access vlan 20
Switch(config-if-range)#exit
Switch(config)#int ra f0/23-24 #将f23和f24设为trunk
Switch(config-if-range)#sw mo tr
s2三层交换机vlan配置:
Switch>en
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#vlan 10
Switch(config-vlan)#name v10
Switch(config-vlan)#exit
Switch(config)#vlan 20
Switch(config-vlan)#name v20
Switch(config-vlan)#exit
Switch(config)#vlan 30
Switch(config-vlan)#name v30
Switch(config-vlan)#exit
Switch(config)#int vlan 10
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan10, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan10, changed state to up
Switch(config-if)#ip addr 192.168.1.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#int vlan 20
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan20, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan20, changed state to up
Switch(config-if)#ip addr 192.168.2.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#int vlan 30
Switch(config-if)#
%LINK-5-CHANGED: Interface Vlan30, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface Vlan30, changed state to up
Switch(config-if)#ip addr 192.168.3.1 255.255.255.0
Switch(config-if)#exit
Switch(config)#int f0/1
Switch(config-if)#sw access vlan 30
Switch(config-if)#exit
Switch(config)#ip routing
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int f0/0
Router(config-if)#ip addr 192.168.3.2 255.255.255.0 #为端口设置ip和掩码
Router(config-if)#no sh #打开端口
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#int se0/2/0
Router(config-if)#ip addr 202.101.1.1 255.255.255.0
Router(config-if)#no sh
%LINK-5-CHANGED: Interface Serial0/2/0, changed state to down
Router(config-if)#exit
Router(config)#
S2交换机:
Switch#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Switch(config)#router rip
Switch(config-router)#network 192.168.1.0 #将与自己直连的网段
Switch(config-router)#network 192.168.2.0
Switch(config-router)#network 192.168.3.0
Switch(config-router)#exit
Switch(config)#
R1路由器:
Router(config)#router rip
Router(config-router)#network 192.168.3.0
Router(config-router)#exit
Router(config)#
我们配置好后,可以使用pc机ping一下R1的F0/0端口,结果是通的话表示完成。
先来设置R1的se端口ip:
Router(config)#int se0/2/0
Router(config-if)#ip addr 202.101.1.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#exit
Router(config)#
接下来设置R2的端口:
Router>en
Router#conf t
Enter configuration commands, one per line. End with CNTL/Z.
Router(config)#int se0/2/0
Router(config-if)#ip addr 202.101.1.2 255.255.255.0
Router(config-if)#no sh
Router(config-if)#
%LINK-5-CHANGED: Interface Serial0/2/0, changed state to up
Router(config-if)#exit
Router(config)#
%LINEPROTO-5-UPDOWN: Line protocol on Interface Serial0/2/0, changed state to up
Router(config)#int f0/0
Router(config-if)#ip addr 221.98.1.1 255.255.255.0
Router(config-if)#no sh
Router(config-if)#
%LINK-5-CHANGED: Interface FastEthernet0/0, changed state to up
%LINEPROTO-5-UPDOWN: Line protocol on Interface FastEthernet0/0, changed state to up
Router(config-if)#exit
Router(config)#
配置R1的OSPF协议:
Router(config)#router ospf 1
Router(config-router)#network 202.101.1.0 0.0.0.255 area 0
Router(config-router)#exit
Router(config)#
配置R2的OSPF协议:
Router(config)#router ospf 1
Router(config-router)#network 202.101.1.0 0.0.0.255 area 0
Router(config-router)#network 221.98.1.0 0.0.0.255 area 0
Router(config-router)#exit
Router(config)#
Router(config)#router rip
Router(config-router)#default-information originate
Router(config-router)#exit
Router(config)#
对R1进行操作,先给vlan10的两台主机配置动态NAT:
Router(config)#access-list 1 permit 192.168.1.0 0.0.0.255 #在R1上配置包括内网所有vlan10地址的ACL
Router(config)#ip nat pool natpool 202.101.1.10 202.101.1.12 netmask 255.255.255.0 #在R1上配置合法的IP地址池
Router(config)#ip nat inside source list 1 pool natpool #关联ACL和合法的IP地址池
Router(config)#int f0/0 #将f0/0设置为内端口
Router(config-if)#ip nat inside
Router(config-if)#exit
Router(config)#int se0/2/0 #将se0/2/2设置为外端口
Router(config-if)#ip nat outside
Router(config-if)#exit
尝试用pc1 ping pc4:
接下来给pc3配置静态NAT:
Router(config)#ip nat inside source static 192.168.2.2 202.101.1.20