NAT设置可以分为静态地址转换、动态地址转换、复用动态地址转换。以下设置以Cisco路由器为例。
1.静态地址转换
静态地址转换将内部本地地址与内部合法地址进行一对一地转换,且需要指定和哪个合法地址进行转换。如果内部网络有WWW服务器或FTP服务器等可以为外部用户提供服务,则这些服务器的IP地址必须采用静态地址转换,以便外部用户可以使用这些服务。
1.静态地址转换
静态地址转换将内部本地地址与内部合法地址进行一对一地转换,且需要指定和哪个合法地址进行转换。如果内部网络有WWW服务器或FTP服务器等可以为外部用户提供服务,则这些服务器的IP地址必须采用静态地址转换,以便外部用户可以使用这些服务。
ip nat pool nat-pool 218.27.84.252 218.27.84.254 netmask 255.255.255.248
ip nat inside source list 1 pool nat-pool overload
ip nat inside source static 192.168.2.254 218.27.84.249
ip route 0.0.0.0 0.0.0.0 Serial0/0
access-list 1 permit 192.168.2.0 0.0.0.255
ip nat inside source list 1 pool nat-pool overload
ip nat inside source static 192.168.2.254 218.27.84.249
ip route 0.0.0.0 0.0.0.0 Serial0/0
access-list 1 permit 192.168.2.0 0.0.0.255
interface Ethernet0/1
ip address 192.168.2.254 255.255.255.0
ip nat inside
ip address 192.168.2.254 255.255.255.0
ip nat inside
2.动态地址转换
动态地址转换也是将内部本地地址与内部合法地址一对一地转换,但是动态地址转换是从内部合法地址池中动态地选择一个未使用的地址来对内部本地地址进行转换的。
3.复用动态地址转换
复用动态地址转换首先是一种动态地址转换,但是它可以允许多个内部本地地址共用一个内部合法地址。对只申请到少量IP地址但却经常同时有多个用户上外部网络的情况,这种转换极为有用。
PAT(Port Address Translation)也称为NAPT,就是将多个内部地址映射为一个公网地址,但以不同的协议端口号与不同的内部地址相对应。这种方式常用于拨号上Internet网。
复用动态地址转换首先是一种动态地址转换,但是它可以允许多个内部本地地址共用一个内部合法地址。对只申请到少量IP地址但却经常同时有多个用户上外部网络的情况,这种转换极为有用。
PAT(Port Address Translation)也称为NAPT,就是将多个内部地址映射为一个公网地址,但以不同的协议端口号与不同的内部地址相对应。这种方式常用于拨号上Internet网。
=cisco NAT 的配置例子=
!
version 12.0
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname nat-r1
!
enable secret 5 $1$FEQr$INhRecYBeCb.UqTQ3b9mY0
!
ip subnet-zero
!
!
!
!
interface Ethernet0
ip address 172.18.150.150 255.255.0.0
no ip directed-broadcast
ip nat inside /* 定义此为网络的内部端口 */
!
interface Serial0
ip address 192.1.1.161 255.255.255.252
no ip directed-broadcast
ip nat outside /* 定义此为网络的外部端口 */
no ip mroute-cache
no fair-queue
!
interface Serial1
no ip address
no ip directed-broadcast
shutdown
! /* 定义从ISP那里申请到的IP在企业内部的分配策阅 */
ip nat pool tech 192.1.1.100 192.1.1.120 netmask 255.255.255.0
ip nat pool deve 192.1.1.121 192.1.1.150 netmask 255.255.255.0
ip nat pool manager 192.1.1.180 192.1.1.200 netmask 255.255.255.0
ip nat pool soft-1 192.1.1.170 192.1.1.179 netmask 255.255.255.0
ip nat pool soft-2 192.1.1.151 192.1.1.159 netmask 255.255.255.0
ip nat pool temp-user 192.1.1.160 192.1.1.160 netmask 255.255.255.0
/* 将访问列表与地址池对应,以下为动态地址转换 */
ip nat inside source list 1 pool tech
ip nat inside source list 2 pool deve
ip nat inside source list 3 pool manager
ip nat inside source list 4 pool soft-1
ip nat inside source list 5 pool soft-2
/* 将访问列表与地址池对应,以下为复用动态地址转换 */
ip nat inside source list 6 pool temp-user overload
/* 将访问列表与地址池对应,以下为静态地址转换 */
ip nat inside source static 172.18.100.168 192.1.1.168
ip nat inside source static 172.18.100.169 192.1.1.169
ip classless
ip route <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />0.0.0.0 0.0.0.0 Serial0 /* 设置一个缺省路由 */
! /* 内部网访问地址表,他指出内部网络能访问外部网的地址段,
分别定义是为了对应
不同的地址池 */
access-list 1 permit 172.18.107.0 0.0.0.255
access-list 2 permit 172.18.101.0 0.0.0.255
access-list 3 permit 172.18.108.0 0.0.0.255
access-list 4 permit 172.18.103.0 0.0.0.255
access-list 4 permit 172.18.102.0 0.0.0.255
access-list 4 permit 172.18.104.0 0.0.0.255
access-list 5 permit 172.18.105.0 0.0.0.255
access-list 5 permit 172.18.106.0 0.0.0.255
access-list 6 permit 172.18.111.0 0.0.0.255
!
line con 0
transport input none
line 1 16
line aux 0
line vty 0 4
login
!
end
version 12.0
service timestamps debug uptime
service timestamps log uptime
no service password-encryption
!
hostname nat-r1
!
enable secret 5 $1$FEQr$INhRecYBeCb.UqTQ3b9mY0
!
ip subnet-zero
!
!
!
!
interface Ethernet0
ip address 172.18.150.150 255.255.0.0
no ip directed-broadcast
ip nat inside /* 定义此为网络的内部端口 */
!
interface Serial0
ip address 192.1.1.161 255.255.255.252
no ip directed-broadcast
ip nat outside /* 定义此为网络的外部端口 */
no ip mroute-cache
no fair-queue
!
interface Serial1
no ip address
no ip directed-broadcast
shutdown
! /* 定义从ISP那里申请到的IP在企业内部的分配策阅 */
ip nat pool tech 192.1.1.100 192.1.1.120 netmask 255.255.255.0
ip nat pool deve 192.1.1.121 192.1.1.150 netmask 255.255.255.0
ip nat pool manager 192.1.1.180 192.1.1.200 netmask 255.255.255.0
ip nat pool soft-1 192.1.1.170 192.1.1.179 netmask 255.255.255.0
ip nat pool soft-2 192.1.1.151 192.1.1.159 netmask 255.255.255.0
ip nat pool temp-user 192.1.1.160 192.1.1.160 netmask 255.255.255.0
/* 将访问列表与地址池对应,以下为动态地址转换 */
ip nat inside source list 1 pool tech
ip nat inside source list 2 pool deve
ip nat inside source list 3 pool manager
ip nat inside source list 4 pool soft-1
ip nat inside source list 5 pool soft-2
/* 将访问列表与地址池对应,以下为复用动态地址转换 */
ip nat inside source list 6 pool temp-user overload
/* 将访问列表与地址池对应,以下为静态地址转换 */
ip nat inside source static 172.18.100.168 192.1.1.168
ip nat inside source static 172.18.100.169 192.1.1.169
ip classless
ip route <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />0.0.0.0 0.0.0.0 Serial0 /* 设置一个缺省路由 */
! /* 内部网访问地址表,他指出内部网络能访问外部网的地址段,
分别定义是为了对应
不同的地址池 */
access-list 1 permit 172.18.107.0 0.0.0.255
access-list 2 permit 172.18.101.0 0.0.0.255
access-list 3 permit 172.18.108.0 0.0.0.255
access-list 4 permit 172.18.103.0 0.0.0.255
access-list 4 permit 172.18.102.0 0.0.0.255
access-list 4 permit 172.18.104.0 0.0.0.255
access-list 5 permit 172.18.105.0 0.0.0.255
access-list 5 permit 172.18.106.0 0.0.0.255
access-list 6 permit 172.18.111.0 0.0.0.255
!
line con 0
transport input none
line 1 16
line aux 0
line vty 0 4
login
!
end
转载于:https://blog.51cto.com/pizazzdog/112125