网络地址转换:NAT
随着全球IPV4地址的日益减少,中小型企业,甚至是拥有几百台电脑的企业,也很难申请到几个公网IP,因此,所分配的地址数量远远满足不了网络用户的需求。为了解决这个问题,就产生了网络地址转换NAT技术。
今天,我就给大家以实例的方式,来演示通过命令将内部网络私有IP地址转换成全球唯一的公网IP地址,来达到内部用户访问Internet网的目的。这也是在实际网络环境中应用最多的实例。
 
一,静态NAT配置:
例:将内部地址192.168.100.2~192.168.100.6转换为外部地址61.159.62.130~61.159.12.134。
1,设置外部端口IP
#int s0/0
#ip add 61.159.62.129 255.255.255.248
2,设置内部端口IP
#int f0/0
#ip add 192.168.100.1 255.255.255.0
3,在内部本地和内部合法地址之间建立地址转换。
#ip nat inside source static 192.168.100.2 61.159.62.130 
#ip nat inside source static 192.168.100.3 61.159.62.131
#ip nat inside source static 192.168.100.4 61.159.62.132
#ip nat inside source static 192.168.100.5 61.159.62.133
#ip nat inside source static 192.168.100.6 61.159.62.134
4,在内部和外部端口上启用NAT。
#int s0/0
#ip nat outside
#int f0/0
#ip nat inside
二,动态NAT配置
例:将内部网络地址172.16.100.1~172.16.100.254转换为61.159.62.130~61.159.62.190
1,设置外部端口IP
#int s0/0
#ip add 61.159.62.129 255.255.255.192
2,设置内部端口IP
#int f0/0
#ip add 172.16.100.1 255.255.255.0
3,定义内部网络中允许访问外部的ACL
#access-list 1 permit 172.168.100.0 0.0.0.255
4,定义合法IP地址池
#ip nat pool text1 61.159.62.130 61.159.62.190 netmask 255.255.255.192
5,指定网络地址转换映射
#ip nat inside source list 1 pool test1
6,在内部和外部端口上启用NAT
#int s0/0
#ip nat outside
#int f0/0
#ip nat inside
三,PAT配置(复用内部LAN地址)
例1:将内部网络地址10.1.1.1~10.1.1.254转换为合法的外部地址61.159.62.130。
1,设置外部端口IP
#int s0/0
#ip add 61.159.62.129 255.255.255.192
2,设置内部IP
#int f0/0
#ip add 10.1.1.1 255.255.255.0
3,定义内部网络中允许访问外部的ACL
#access-list 1 permit 10.1.1.0 0.0.0.255
4,定义合法IP地址池
#ip nat pool test2 61.159.62.130 netmask 255.255.255.248
5,指定网络地址转换映射
#ip nat inside source list 1 pool test2 overload
6,在内部和外部端口上启用NAT
#int s0/0
#ip nat outside
#int f0/0
#in nat inside
例2:将内部网络地址10.1.1.1~10.1.1.254转换为路由器的接口地址61.159.62.129。
1,设置外部端口IP
#int s0/0
#ip add 61.159.62.129 255.255.255.252
2,设置内部端口IP
#int f0/0
#ip add 10.1.1.1 255.255.255.0
3,定义内部网络中允许访问外部的ACL
#access-list 1 permit 10.1.1.1 0.0.0.255
4,定义合法IP地址池
这里注意,直接使用路由器的接口地址,不用定义地址池。
5,指定网络地址转换映射
#ip nat inside source text3 int s0/0 overload
6,在内部和外部端口上启用NAT
#int s0/0
#ip nat outside
#int f0/0
#ip nat inside
最后,另附上:
清除NAT转换表中所有条目的命令:
#clear ip nat translation *
测试网络连通性命令:
#show ip nat translations
#show ip nat statistics
希望以上实例配置,对大家实际工作中在路由器上的应用配置有所帮助。