一、动态NAT
拓扑如图,配置好接口的地址,R1和R2配置静态路由,R3无静态路由
步骤:
1、编写ACL规则表明内网需要转换地址的网段
2、建立NAT地址池
3、R2各接口标明内网外网范围
4、开启动态NAT
R2(config)#access-list 1 permit 12.0.0.0 0.0.0.255
R2(config)#access-list 1 permit host 1.1.1.1
R2(config)#ip nat pool DTNAT 22.0.0.10 22.0.0.30 netmask 255.255.255.0
R2(config)#int f0/0
R2(config-if)#ip nat inside
R2(config-if)#int f1/0
R2(config-if)#ip nat outside
R2(config)#ip nat inside source list 1 pool DTNAT
查看命令:
show ip nat translations //查看NAT翻转表
show ip nat statistics //查看NAT状态
debug ip nat //调试NAT翻转
在R1带源ping外网然后在R2查看信息
二、端口NAT
继续动态NAT的拓扑
端口NAT配置
R2(config)#ip nat pool ADDNAT 22.0.0.1 22.0.0.1 netmask 255.255.255.0
R2(config)#int f0/0
R2(config-if)#ip nat inside
R2(config-if)#int f1/0
R2(config-if)#ip nat outside
R2(config)#ip nat inside source list 1 pool ADDNAT overload
或者下面这条配置命令
R2(config)#ip nat source list 1 int f1/0 overload
三、静态NAT
拓扑如图,在各个接口配置好如图地址
静态NAT配置方法:
方法一(最不安全):内网IP-公网IP
R2(config)#ip nat inside source static 172.16.1.4 23.1.1.40
R2(config)#ip nat inside source static 172.16.1.5 23.1.1.50
方法二(常规):内网IP+PORT - 公网IP+PORT
R2(config)#ip nat inside source static tcp 172.16.1.4 23 23.1.1.40 23
R2(config)#ip nat inside source static tcp 172.16.1.4 80 23.1.1.40 80
方法三(安全):内网IP+PORT - 公网IP+PORT
R2(config)#ip nat inside source static tcp 172.16.1.4 23 23.1.1.40 2323
方法一:
R2配置:
R2(config)#int f0/0
R2(config-if)#ip nat inside
R2(config-if)#int f2/0
R2(config-if)#ip nat inside
R2(config-if)#int f1/0
R2(config-if)#ip nat outside
R2(config)#ip nat inside source static 172.16.0.1 22.0.0.10 //将内部服务器的地址转换为22.0.0.10
R4配置:
R4(config)#ip route 0.0.0.0 0.0.0.0 172.16.0.2 //设置默认路由
R4(config)#line vty 0 15
R4(config-line)#no login
R4(config-line)#privilege level 15
R3pingR4,R3远程登陆R4
方法二:
R2
R2(config)#ip nat inside source static tcp 172.16.0.1 23 22.0.0.20 23
R2(config)#ip nat inside source static tcp 172.16.0.1 80 22.0.0.20 80