一.实验涉及技术
vlan(虚拟局域网)、 svi(三层交换) 、nat(网络地址转换)、static router(静态路由)
三.实验目的:
通过配置过载NAT从而实现企业内网正常访问公网,PC2可以正常ping通server,但是无法访问server的HTTP服务器,PC1正常。
二.实验拓扑图
三.实验过程
首先给PC1、PC2 添加ip、子网、网关、DNS 给server配置ip、子网、网关
配置二层交换机S1:
Switch>enable
Switch#configure terminal
Switch(config)#hostname S1
S1(config)#no ip domain-lookup
S1(config)#vlan 10
S1(config-vlan)#exit
S1(config)#vlan 20
S1(config-vlan)#exit
S1(config)#int f0/1
S1(config-if)#switchport mode access
S1(config-if)#switchport access vlan 10
S1(config-if)#exit
S1(config)#int f0/2
S1(config-if)#switchport mode access
S1(config-if)#switchport access vlan 20
S1(config-if)#exit
S1(config)#int f0/3
S1(config-if)#switchport mode trunk
S1(config-if)#switchport trunk allowed vlan all
S1(config-if)#end
S1#write
配置三层交换机S2:
Switch>enable
Switch#configure terminal
Switch(config)#hostname S2
S2(config)#no ip domain-lookup
S2(config)#vlan 10
S2(config-vlan)#exit
S2(config)#vlan 20
S2(config-vlan)#exit
S2(config)#int f0/1
S2(config-if)#switchport trunk encapsulation dot1q #指明接口的封装类型为802.1Q协议
S2(config-if)#switchport mode trunk
S2(config-if)#switchport trunk allowed vlan all
S2(config-if)#exit
S2(config)#int vlan 10
S2(config-if)#ip address 192.168.1.254 255.255.255.0
S2(config-if)#exit
S2(config)#int vlan 20
S2(config-if)#ip address 192.168.2.254 255.255.255.0
S2(config-if)#exit
S2(config)#int vlan 1
S2(config-if)#ip address 192.168.3.1 255.255.255.0
S2(config-if)#no shutdown
S2(config-if)#exit
S2(config)#ip routing #打开路由器功能
S2(config)#ip route 0.0.0.0 0.0.0.0 192.168.3.3
S2(config)#end
S2#write
配置路由器Router0:
Router>enable
Router#configure terminal
Router(config)#no ip domain-lookup
Router0(config)#hostname Router0
Router0(config)#int f0/0
Router0(config-if)#ip address 192.168.3.3 255.255.255.0
Router0(config-if)#no shutdown
Router0(config-if)#exit
Router0(config)#int se0/3/0
Router0(config-if)#ip address 2.2.2.1 255.255.255.0
Router0(config-if)#clock rate 128000
Router0(config-if)#no shutdown
Router0(config-if)#exit
Router0(config)#ip route 192.168.0.0 255.255.0.0 192.168.3.1
Router0(config)#ip route 0.0.0.0 0.0.0.0 2.2.2.2
Router0(config)#int f0/0
Router0(config-if)#ip nat inside
Router0(config-if)#exit
Router0(config)#int se0/3/0
Router0(config-if)#ip nat outside
Router0(config-if)#exit
Router0(config)#ip nat pool lb 2.2.2.1 2.2.2.1 netmask 255.255.255.0 #定义公网地址池
Router0(config)#access-list 1 permit 192.168.0.0 0.0.255.255 #定义感兴趣流量
Router0(config)#ip nat inside source list 1 pool lb overload #实现nat,将感兴趣流量和公网地址池进行映射Router(config)#access-list 100 deny tcp 192.168.2.1 0.0.0.255 3.3.3.2 0.0.0.255 eq www #禁止源地址访问目的地址的tcp的www端口
Router(config)#access-list 100 permit ip any any
Router(config)#int f0/0
Router(config-if)#ip access-group 100 in #将ACL应用到端口
Router(config)#end
Router#write注意:overload表示启用过载nat,不加关键词就是动态nat
配置路由器Router1:
Router>enable
Router#configure terminal
Router(config)#no ip domain-lookup
Router1(config)#hostname Router1
Router1(config)#int se0/3/0
Router1(config-if)#ip address 2.2.2.2 255.255.255.0
Router1(config-if)#no shutdown
Router1(config-if)#exit
Router1(config)#int f0/0
Router1(config-if)#ip address 3.3.3.1 255.255.255.0
Router1(config-if)#no shutdown
Router1(config)#end
Router1#write