H3C防火墙地址转换大全

一、 NAT(网络地址转换)

1、 作用:通过将内部网络的私有IP地址翻译成全球唯一的公网IP地址,使内部网络可以连接到互联网等外部网络上。

2、 优点:

节省公有合法IP地址

处理地址重叠

增强灵活性

安全性

3、NAT的缺点

延迟增大

配置和维护的复杂性

不支持某些应用,可以通过静态NAT映射来避免

4、NAT实现方式

1) 静态转换

IP地址的对应关系是一对一,而且是不变的,借助静态转换,能实现外部网络对内部网络中某些特设定服务器的访问。

静态NAT配置:

配置接口IP及路由

全局:

Ip nat inside source static 192.168.1.1 61.159.62.131

在内外接口上启用NAT:

进入出口配置:ip nat outside

进入入口配置:ip nat inside 

端口映射:

ip nat inside source static tcp 192.168.1.6 80 61.159.62.133 80 

2) 动态转换

IP地址的对应关系是不确定的,而是随机的,所有被授权访问互联网的私有地址可随机转换为任何指定的合法的外部IP地址。(内部网络同时访问Internet的主机数少于配置的合法地址中的IP个数时适用)

动态NAT的配置:

全局:access-list 1 permit 192.168.1.0 0.0.0.255

全局:ip nat pool nsd 61.159.62.131 61.159.62.132 netmask 255.255.255.248(定义地址池名称为nsd,地址池IP范围61.159.62.131 到61.159.62.132)

全局:ip nat inside source list 1 pool nsd

3) 端口多路复用(PAT)

通过改变外出数据包的源IP地址和源端口并进行端口转换,内部网络的所有主机均可共享一个合法IP地址实现互联网的访问,节约IP。

PAT的配置:

全局:ip nat inside source list 1 interface f0/1 overload

 

动态转换NAT配置步骤:

1.配置ACL,用于限定可以做地址转换的内网范围

2.配置合法地址池

3.设置ACL和地址池的映射关系

4.指定内外部接口

5、NAT三种实现方式的区别:

静态转换的对应关系一对一且不变,并且没有节约公用IP,只隐藏了主机的真实地址。

动态转换虽然在一定情况下节约了公用IP,但当内部网络同时访问Internet的主机数大于合法地址池中的IP数量时就不适用了。

端口多路复用可以使所有内部网络主机共享一个合法的外部IP地址,从而最大限度地节约IP地址资源。

二、 查看NAT转换条目

特权:show  ip  nat  translations显示当前存在的转换

三、 清除NAT转换条目

1、特权: clear ip nat translation * 清除NAT转换条目中的所有所条目

注:静态NAT条目不会被清除

四、 NAT常见问题

ACL阻止转换后的流量

进行地址转换的ACL不全

overload参数漏配

不对称路由问题

动态地址池IP地址范围配置错误

动态地址池与静态转换地址重叠

Inside和outside接口配置错误

五、 显示每个转换的数据包

特权:debug  ip  nat 

Undebug all

S表示源地址

D表示目的地址

192.168.1.2->61.159.62.130表示将192.168.1.2转换为61.159.62.130

Nslookup www.tedu.com

Clear ip nat translation *

动态NAT配置步骤

1、配置ACL,用于限定可以做地址转换的内网范围

R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255

2、配置合法地址池

R1(config)#ip nat pool mylan 201.1.1.2 201.1.1.8 netmask 255.255.255.0

3、设置ACL和地址池的映射关系

R1(config)#ip nat inside source list 1 pool mylan

4、指定内部接口和外部接口

R1(config)#int f0/0

R1(config-if)#ip nat inside

R1(config-if)#int f0/1

R1(config-if)#ip nat outside

R1#sho ip nat translations    查看NAT转换表

R1#clear ip nat translation * 清除动态转换的NAT表

将内网服务器发布到互联网,可以采用静态NAT

1、配置将哪个内网IP映射为哪个合法地址

R1(config)#ip nat inside source static 192.168.1.100 201.1.1.9

2、指定内部接口和外部接口

R1(config)#int f0/0

R1(config-if)#ip nat inside

R1(config-if)#int f0/1

R1(config-if)#ip nat outside

R1#sho ip nat translations

NAT:将一个网络的地址转换成另一个网络地址

端口映射

当互联网用户访问发布的IP地址+端口号,才能找到相应的内网服务器

1、清除上一步的静态映射

R1(config)#no ip nat inside source static 192.168.1.100 201.1.1.9

2、映射192.168.1.100的80端口到201.1.1.9的80端口

R1(config)#ip nat inside source static tcp 192.168.1.100 80 201.1.1.9 80 

3、将192.168.1.101的DNS服务发布到互联网

R1(config)#ip nat inside source static udp 192.168.1.101 53 201.1.1.9 53 

4、指定内部接口和外部接口

R1(config)#int f0/0

R1(config-if)#ip nat inside

R1(config-if)#int f0/1

R1(config-if)#ip nat outside

R1#sho ip nat translations

5、内网增加一台server3,ip地址是192.168.1.101,网关指向192.168.1.1。在services选项卡中选择左侧的DNS,右侧name填www.tedu.cn,Address填201.1.1.1,点击add,设置DNS Service为On的状态

6、在互联网服务器上添加它使用的DNS服务器是201.1.1.9,然后运行命令行工具,输入nslookup www.tedu.cn

PAT:如果外网地址只有一个,配置在路由器的外端口上了,那么可以让内网所有的地址都转换成外网端口的地址,进行互联网访问

1、清除前面所做的动态转换

R1#clear ip nat translation *

R1(config)#no ip nat inside source list 1 

R1(config)#no ip nat pool mylan

2、定义ACL,限制可以进行PAT转换的内网地址

R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255

3、配置ACL和路由器外端口的映射

R1(config)#ip nat inside source list 1 interface fastEthernet 0/1 overload 

4、指定内部接口和外部接口

R1(config)#int f0/0

R1(config-if)#ip nat inside

R1(config-if)#int f0/1

R1(config-if)#ip nat outside

R1#sho ip nat translations

调试(相当于是在路由器上进行抓包)

R1#debug ip nat 

R1#undebug all     关闭所有存在的抓包操作

最后的综合实验

1、IP地址

server2: 192.168.1.10

pc2: 192.168.2.10

pc3: 192.168.3.10

pc4: 192.168.4.10

server1: 201.1.2.10

ms1:

f0/24: 172.16.0.1  255.255.0.0

vlan1: 192.168.1.1

vlan2: 192.168.2.1

vlan3: 192.168.3.1

vlan4: 192.168.4.1

router1:

f0/0: 172.16.0.2  255.255.0.0

f0/1: 201.1.1.1

router2: 

f0/0 : 201.1.1.2

f0/1 : 201.1.2.1

2、配置vlan

sw1-sw4配置vlan,并将端口加入到指定VLAN

与三层交换机相边的端口配置中继

ms1配置vlan,开启三层交换

3、配置路由

ms1配置缺省路由

ip route 0.0.0.0 0.0.0.0 172.16.0.2

router1配置路由

ip route 0.0.0.0 0.0.0.0 201.1.1.2

ip route 192.168.0.0 255.255.0.0 172.16.0.1

正式笔记:

  1. 案例1:配置静态NAT
  2. 案例2:配置端口映射
  3. 案例3:配置动态NAT
  4. 案例4:PAT配置
  5. 案例5:办公区Internet的访问

1 案例1:配置静态NAT

1.1 问题

随着接入Internet的计算机数量的不断猛增,IP地址资源也就愈加显得捉襟见肘。事实上,除了中国教育和科研计算机网(CERNET)外,一般用户几乎申请不到整段的C类IP地址。在其他ISP那里,即使是拥有几百台计算机的大型局域网用户,当他们申请IP地址时,所分配的地址也不过只有几个或十几个IP地址。显然,这样少的IP地址根本无法满足网络用户的需求。

  • 在R1上配置静态NAT使192.168.1.1转换为61.159.62.131,192.168.1.2转换为61.159.62.132,实现外部网络访问。

1.2 方案

借助于NAT,私有(保留)地址的"内部"网络通过路由器发送数据包时,私有地址被转换成合法的IP地址,一个局域网只需使用少量IP地址(甚至是1个)即可实现私有地址网络内所有计算机与Internet的通信需求。

这种通过使用少量的公有IP 地址代表较多的私有IP 地址的方式,将有助于减缓可用IP地址空间的枯竭。而且还能够有效地避免来自网络外部的攻击,隐藏并保护网络内部的计算机。

网络拓扑如图-1所示:

图-1

1.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:通用配置

1)配置R1端口IP地址,以及默认路由

 
  1. tarena-R1(config)#interface f0/0
  2. tarena-R1(config-if)#ip address 192.168.1.254 255.255.255.0
  3. tarena-R1(config-if)#no shutdown
  4. tarena-R1(config-if)#interface f0/1
  5. tarena-R1(config-if)#ip address 61.159.62.129 255.255.255.248
  6. tarena-R1(config-if)#no shutdown
  7. tarena-R1(config-if)#exit
  8. tarena-R1(config)#ip route 0.0.0.0 0.0.0.0 f0/1

2)配置R2端口IP地址

不需要在R2上配置到企业内网的静态路由,因为NAT的存在,企业内部的地址都将被转换、隐藏。

 
  1. tarena-R2(config)#interface f0/0
  2. tarena-R2(config-if)#ip address 61.159.62.130 255.255.255.248
  3. tarena-R2(config-if)#no shutdown
  4. tarena-R2(config-if)#interface f0/1
  5. tarena-R2(config-if)#ip address 192.168.2.254 255.255.255.0
  6. tarena-R2(config-if)#no shutdown

步骤二:静态NAT配置

1)在R1上将192.168.1.1映射到61.159.62.131,将192.168.1.2映射到61.159.62.132

静态映射有唯一对应的关系。

通过静态NAT,可以把内网服务器发布到外网。

 
  1. tarena-R1(config)#ip nat inside source static 192.168.1.1 61.159.62.131
  2. tarena-R1(config)#ip nat inside source static 192.168.1.2 61.159.62.132

2)在R1上配置NAT内、外端口

 
  1. tarena-R1(config)#interface f0/0
  2. tarena-R1(config-if)#ip nat inside
  3. tarena-R1(config-if)#interface f0/1
  4. tarena-R1(config-if)#ip nat outside

3)分别在两台PC机上测试到外网主机的通信

PC1测试如下所示:

 
  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::2D0:FFFF:FE45:CACC
  4. IP Address......................: 192.168.1.1
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Reply from 192.168.2.1: bytes=32 time=1ms TTL=126
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  17. PC>

PC2的测试如下所示:

 
  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::200:CFF:FEEA:DE30
  4. IP Address......................: 192.168.1.2
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Request timed out.
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 0ms, Average = 0ms
  17. PC>

4)在R1上查看NAT转换表

 
  1. tarena-R1#show ip nat translations
  2. Pro Inside global Inside local Outside local Outside global
  3. icmp 61.159.62.131:10 192.168.1.1:10 192.168.2.1:10 192.168.2.1:10
  4. icmp 61.159.62.131:11 192.168.1.1:11 192.168.2.1:11 192.168.2.1:11
  5. icmp 61.159.62.131:12 192.168.1.1:12 192.168.2.1:12 192.168.2.1:12
  6. icmp 61.159.62.131:9 192.168.1.1:9 192.168.2.1:9 192.168.2.1:9
  7. icmp 61.159.62.132:27 192.168.1.2:27 192.168.2.1:27 192.168.2.1:27
  8. icmp 61.159.62.132:28 192.168.1.2:28 192.168.2.1:28 192.168.2.1:28
  9. icmp 61.159.62.132:29 192.168.1.2:29 192.168.2.1:29 192.168.2.1:29
  10. icmp 61.159.62.132:30 192.168.1.2:30 192.168.2.1:30 192.168.2.1:30

2 案例2:配置端口映射

2.1 问题

通过端口映射技术将内部服务器发布向Internet。

2.2 方案

在R1上配置端口映射将192.168.1.3的80端口映射为61.159.62.133的80端口,将web服务器发布到Internet。网络拓扑如图-2所示:

图-2

2.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:通用配置

1)在案例一基础上取消静态转换条目,在192.168.1.0网络新增一台web服务器IP为192.168.1.3。将192.168.1.3的80端口映射为61.159.62.133的80端口

 
  1. tarena-R1(config)#no ip nat inside source static 192.168.1.1 61.159.62.131
  2. tarena-R1(config)#no ip nat inside source static 192.168.1.2 61.159.62.132
  3. tarena-R1 (config)#ip nat inside source static tcp 192.168.1.3 80 61.159.62.133 80

步骤二:PC3上访问web服务器进行验证

1)外部主机PC4上访问61.159.62.133进行验证,如图-3所示

图-3

3 案例3:配置动态NAT

3.1 问题

  • 在R1通过动态NAT实现企业内网192.168.1.0/24转换为公网地址61.159.62.131-61.159.62.134,访问192.168.2.1

3.2 方案

网络拓扑如图-4所示:

图-4

3.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:动态NAT配置

1)删除案例2中的端口映射

 
  1. tarena-R1 (config)#no ip nat inside source static tcp 192.168.1.3 80 61.159.62.133 80

2)在R1上配置ACL

 
  1. tarena-R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255

3)在R1上配置可转换的公网IP地址池

地址池是向ISP(Internet服务提供商,如电信、联通)申请得到的,内网主机(上一步ACL中所包含的IP地址)到外网的访问,内网地址将被动态的、随机的转换为这些合法地址。

 
  1. tarena-R1(config)#ip nat pool natpool 61.159.62.131 61.159.62.134 netmask 255.255.255.248

4)关联ACL和公网的IP地址池

 
  1. tarena-R1(config)#ip nat inside source list 1 pool natpool

5)在R1上配置NAT内、外端口

 
  1. tarena-R1(config)#interface f0/0
  2. tarena-R1(config-if)#ip nat inside
  3. tarena-R1(config-if)#interface f0/1
  4. tarena-R1(config-if)#ip nat outside

6)分别在两台PC机上测试到外网主机的通信

PC1测试如下所示:

 
  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::2D0:FFFF:FE45:CACC
  4. IP Address......................: 192.168.1.1
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Reply from 192.168.2.1: bytes=32 time=1ms TTL=126
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  17. PC>

PC2测试如下所示:

 
  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::2D0:FFFF:FE45:CACC
  4. IP Address......................: 192.168.1.2
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Reply from 192.168.2.1: bytes=32 time=1ms TTL=126
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 1ms, Average = 0ms

7)在R1上查看NAT转换表

转换表中的对应关系是动态的,如192.168.1.1被转换为61.159.62.131,但是下一次对外网的访问很有可能被转换为其他地址。

 
  1. tarena-R1#show ip nat translations
  2. Pro Inside global Inside local Outside local Outside global
  3. icmp 61.159.62.131:1362192.168.1.1:1362 192.168.2.1:1362 192.168.2.1:1362
  4. icmp 61.159.62.131:1392192.168.1.1:1392 192.168.2.1:1392 192.168.2.1:1392
  5. icmp 61.159.62.131:1393192.168.1.1:1393 192.168.2.1:1393 192.168.2.1:1393
  6. icmp 61.159.62.131:1394192.168.1.1:1394 192.168.2.1:1394 192.168.2.1:1394
  7. icmp 61.159.62.132:13 192.168.1.2:13 192.168.2.1:13 192.168.2.1:13
  8. icmp 61.159.62.132:14 192.168.1.2:14 192.168.2.1:14 192.168.2.1:14
  9. icmp 61.159.62.132:15 192.168.1.2:15 192.168.2.1:15 192.168.2.1:15
  10. icmp 61.159.62.132:16 192.168.1.2:16 192.168.2.1:16 192.168.2.1:16

4 案例4:PAT配置

4.1 问题

在R1配置PAT端口多路复用使企业内网192.168.1.0/24复用f0/1端口的IP,实现外部网络的访问。

4.2 方案

网络拓扑如图-5所示:

图-5

4.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:基于端口的PAT配置限制

1)删除案例3中动态NAT配置

 
  1. tarena-R1(config)#no ip nat inside source list 1
  2. tarena-R1(config)#no ip nat pool natpool
  3. tarena-R1(config)#no access-list 1

2)在R1上配置ACL

 
  1. tarena-R1(config)#access-list 1 permit 192.168.1.0 0.0.0.255

3)关联ACL和路由器连接互联网的端口

该命令最后加上的overload表示复用。

 
  1. tarena-R1(config)#ip nat inside source list 1 interface f0/1 overload

4)在R1上配置NAT内、外端口

 
  1. tarena-R1(config)#interface f0/0
  2. tarena-R1(config-if)#ip nat inside
  3. tarena-R1(config-if)#interface f0/1
  4. tarena-R1(config-if)#ip nat outside

5)分别在两台PC机上测试到外网主机的通信

PC1测试如下所示:

 
  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::2D0:FFFF:FE45:CACC
  4. IP Address......................: 192.168.1.1
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Reply from 192.168.2.1: bytes=32 time=1ms TTL=126
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  17. PC>

PC2测试如下所示:

 
  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::2D0:FFFF:FE45:CACC
  4. IP Address......................: 192.168.1.2
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7. PC>ping 192.168.2.1
  8. Pinging 192.168.2.1 with 32 bytes of data:
  9. Reply from 192.168.2.1: bytes=32 time=1ms TTL=126
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=126
  13. Ping statistics for 192.168.2.1:
  14. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  15. Approximate round trip times in milli-seconds:
  16. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  17. PC>

6)在R1上查看NAT转换表

 
  1. tarena-R1#show ip nat translations
  2. Pro Inside global Inside local Outside local Outside global
  3. icmp 61.159.62.129:2029192.168.1.1:2029 192.168.2.1:2029 192.168.2.1:2029
  4. icmp 61.159.62.129:2030192.168.1.1:2030 192.168.2.1:2030 192.168.2.1:2030
  5. icmp 61.159.62.129:2031192.168.1.1:2031 192.168.2.1:2031 192.168.2.1:2031
  6. icmp 61.159.62.129:2032192.168.1.1:2032 192.168.2.1:2032 192.168.2.1:2032
  7. icmp 61.159.62.129:2033192.168.1.1:2033 192.168.2.1:2033 192.168.2.1:2033
  8. icmp 61.159.62.129:2034192.168.1.1:2034 192.168.2.1:2034 192.168.2.1:2034
  9. icmp 61.159.62.129:2035192.168.1.1:2035 192.168.2.1:2035 192.168.2.1:2035

输出结果显示,所有的内网IP地址在访问外网前均被转换成了路由器端口的IP地址。

5 案例5:办公区Internet的访问

5.1 问题

在R1配置PAT端口多路复用使企业内网192.168.1.0/24复用f0/1端口的IP,实现外部网络的访问。

5.2 方案

网络拓扑如图-6所示:

图-6

5.3 步骤

实现此案例需要按照如下步骤进行。

步骤一:在SM1划分vlan2、vlan3、vlan4 并给SM1配置虚端口IP并开启路由功能,1-4接口开启trunk

1)创建vlan并设置管理IP,开启路由功能,并把相应的接口划分到vlan下

 
  1. SM1 (config)ip routing
  2. SM1 (config)#vlan 2
  3. SM1 (config-vlan)#vlan 3
  4. SM1 (config-vlan)#vlan 4
  5. SM1 (config-vlan)#
  6. SM1 (config-vlan)#exit
  7. SM1 (config)#interface vlan 1
  8. SM1 (config-if)#ip address 192.168.1.254 255.255.255.0
  9. SM1 (config-if)#eixt
  10. SM1 (config-if)#no shutdown
  11. SM1 (config-if)#exit
  12. SM1 (config)#interface vlan 2
  13. SM1 (config-if)#ip address 192.168.2.254 255.255.255.0
  14. SM1 (config-if)#no shutdown
  15. SM1 (config-if)#exit
  16. SM1 (config)#interface vlan 3
  17. SM1 (config-if)#ip address 192.168.3.254 255.255.255.0
  18. SM1 (config-if)#no shutdown
  19. SM1 (config-if)#exit
  20. SM1 (config)#interface vlan 4
  21. SM1 (config-if)#ip address 192.168.4.254 255.255.255.0
  22. SM1 (config-if)#no shutdown
  23.  
  24. sw2(config)#vlan 2
  25. sw2(config-vlan)#exit
  26. sw2(config)#interface fastEthernet 0/1
  27. sw2(config-if)#switchport access vlan 2
  28.  
  29. sw3(config)#vlan 3
  30. sw3(config-vlan)#exit
  31. sw3(config)#interface fastEthernet 0/1
  32. sw3(config-if)#switchport access vlan 3
  33.  
  34. sw4(config)#vlan 4
  35. sw4(config-vlan)#exit
  36. sw4(config)#interface fastEthernet 0/1
  37. sw4(config-if)#switchport access vlan 4

2)交换机之间所连接的接口开启trunk

 
  1. SM1(config)#interface range f0/1 - 4
  2. SM1 (config-if-range)#switchport trunk encapsulation dot1q
  3. SM1 (config-if-range)#switchport mode trunk
  4.  
  5. sw1(config)#interface fastEthernet 0/3
  6. sw1(config-if)#switchport mode trunk
  7.  
  8. sw2(config)#interface fastEthernet 0/3
  9. sw2(config-if)#switchport mode trunk
  10.  
  11. sw3(config)#interface fastEthernet 0/3
  12. sw3(config-if)#switchport mode trunk
  13.  
  14. sw4(config)#interface fastEthernet 0/3
  15. sw4(config-if)#switchport mode trunk

3)测试vlan之间的连通性

 
  1. PC>ipconfig
  2. FastEthernet0 Connection:(default port)
  3. Link-local IPv6 Address.........: FE80::290:21FF:FEC2:1A50
  4. IP Address......................: 192.168.1.1
  5. Subnet Mask.....................: 255.255.255.0
  6. Default Gateway.................: 192.168.1.254
  7.  
  8. PC>ping 192.168.2.1
  9. Pinging 192.168.2.1 with 32 bytes of data:
  10. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  11. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  12. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  13. Reply from 192.168.2.1: bytes=32 time=1ms TTL=12
  14. Ping statistics for 192.168.2.1:
  15. Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
  16. Approximate round trip times in milli-seconds:
  17. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  18.  
  19. PC>ping 192.168.3.1
  20. Pinging 192.168.3.1 with 32 bytes of data:
  21. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  22. Reply from 192.168.3.1: bytes=32 time=0ms TTL=127
  23. Reply from 192.168.3.1: bytes=32 time=0ms TTL=127
  24. Reply from 192.168.3.1: bytes=32 time=1ms TTL=127
  25. Ping statistics for 192.168.3.1:
  26. Packets: Sent = 4, Received = 3, Lost = 1 (25% loss),
  27. Approximate round trip times in milli-seconds:
  28. Minimum = 0ms, Maximum = 1ms, Average = 0ms
  29.  
  30. PC>ping 192.168.4.1
  31. Pinging 192.168.4.1 with 32 bytes of data:
  32. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  33. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  34. Reply from 192.168.2.1: bytes=32 time=0ms TTL=127
  35. Reply from 192.168.4.1: bytes=32 time=0ms TTL=127
  36. Ping statistics for 192.168.4.1:
  37. Packets: Sent = 4, Received = 1, Lost = 3 (75% loss),
  38. Approximate round trip times in milli-seconds:
  39. Minimum = 0ms, Maximum = 0ms, Average = 0ms

4)为SM1与路由器连接的接口和路由器配置IP并启用动态路由RIP协议.

 
  1. SM1(config)#interface fastEthernet 0/5
  2. SM1(config-if)#no switchport
  3. SM1(config-if)#ip add 192.168.5.1 255.255.255.0
  4. SM1(config-if)#no shutdown
  5. SM1(config-if)#exit
  6. SM1(config)#router rip
  7. SM1(config-router)#version 2
  8. SM1(config-router)#no auto-summary
  9. SM1(config-router)#network 192.168.1.0
  10. SM1(config-router)#network 192.168.2.0
  11. SM1(config-router)#network 192.168.3.0
  12. SM1(config-router)#network 192.168.4.0
  13. SM1(config-router)#network 192.168.5.0
  14.  
  15. Router(config)#interface fastEthernet 0/0
  16. Router(config-if)#ip address 192.168.5.2 255.255.255.0
  17. Router(config-if)#no shutdown
  18. Router(config-if)#exit
  19. Router(config)#interface fastEthernet 0/1
  20. Router(config-if)#ip address 61.159.62.129 255.255.255.248
  21. Router(config-if)#exit
  22. Router(config)#router rip
  23. Router(config-router)#version 2
  24. Router(config-router)#no auto-summary
  25. Router(config-router)#network 192.168.5.0

5)在路由器上配置默认路由并发布到RIP协议里并在三成交换机SM1上查看路由表

 
  1. Router(config)#ip route 0.0.0.0 0.0.0.0 f0/1
  2. Router(config)#router rip
  3. Router(config-router)#default-information originate

SM路由表如下所示:

 
  1. SM1# show ip route
  2. Codes: C - connected, S - static, I - IGRP, R - RIP, M - mobile, B - BGP
  3. D - EIGRP, EX - EIGRP external, O - OSPF, IA - OSPF inter area
  4. N1 - OSPF NSSA external type 1, N2 - OSPF NSSA external type 2
  5. E1 - OSPF external type 1, E2 - OSPF external type 2, E - EGP
  6. i - IS-IS, L1 - IS-IS level-1, L2 - IS-IS level-2, ia - IS-IS inter area
  7. * - candidate default, U - per-user static route, o - ODR
  8. P - periodic downloaded static route
  9. Gateway of last resort is 192.168.5.2 to network 0.0.0.0
  10. C 192.168.1.0/24 is directly connected, Vlan1
  11. C 192.168.2.0/24 is directly connected, Vlan2
  12. C 192.168.3.0/24 is directly connected, Vlan3
  13. C 192.168.4.0/24 is directly connected, Vlan4
  14. C 192.168.5.0/24 is directly connected, FastEthernet0/5
  15. R* 0.0.0.0/0 [120/1] via 192.168.5.2, 00:00:18, FastEthernet0/5

6)在路由器上配置PAT

 
  1. Router(config)#access-list 1 permit 192.168.4.0 0.0.0.255
  2. Router(config)#ip nat inside source list 1 interface f0/1
  3. Router(config)#interface fastEthernet 0/0
  4. Router(config-if)#ip nat inside
  5. Router(config-if)#exit
  6. Router(config)#interface fastEthernet 0/1
  7. Router(config-if)#ip nat outside

7)用192.168.4.0和192.168.1.0测试网络连通性

PC1

 
  1. PC>ping 61.159.62.130
  2. Pinging 61.159.62.130 with 32 bytes of data:
  3. Request timed out.
  4. Request timed out.
  5. Request timed out.
  6. Request timed out.
  7. Ping statistics for 61.159.62.130:
  8. Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

PC4

 
  1. PC>ping 61.159.62.130
  2.  
  3. Pinging 61.159.62.130 with 32 bytes of data:
  4.  
  5. Reply from 61.159.62.130: bytes=32 time=0ms TTL=126
  6. Reply from 61.159.62.130: bytes=32 time=0ms TTL=126
  7. Reply from 61.159.62.130: bytes=32 time=0ms TTL=126
  8. Reply from 61.159.62.130: bytes=32 time=0ms TTL=126
  9.  
  10. Ping statistics for 61.159.62.130:
  11. Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
  12. Approximate round trip times in milli-seconds:
  13. Minimum = 0ms, Maximum = 0ms, Average = 0ms

猜你喜欢

转载自blog.csdn.net/wsasy12345/article/details/83104067