在NAT中有4个术语:内部本地,内部全局,外部本地,外部全局.这四个术语如果不细致理解,确实让人感到非常的乱,但理解后其实并不难.
内部本地 | 内部全局 | 外部本地 | 外部全局 |
(相同颜色处于同一层次平面)
上面四个术语描述的IP地址,可以这样理解:
内部本地和外部全局,是通信中正式的真正源/目的地址
内部全局和外部本地是在NAT过程中的一个中间量.
内部全局是内部本地在全局平面(外部网络)的表现,也就是说 内部全局在外部网络(全局平面)中代表了内部本地
外部本地是外部全局在本地平面(内部网络)的表现,也就是说 外部本地在内部网络(本地平面)中代表了外部全局
如图:
看下面的图进一步理解这样的关系,这个图是我自己理解关系时候想象出来的,通过这个图可以比较直观的理清关系,在这个图中我引入了2个名词本地平面/全局平面.
只有处在同一平面的才能进行直接的数据传输
那么内部本地(SA)要想和外部全局(DA)通信,该如何进行?
首先:要想能正常传输,必须要让数据处于同一个平面,现在2者不在同一平面,由于数据方向是内部本地-->外部全局,要统一到全局平面,所以需要把内部本地转换成内部全局,用内部全局代表了内部本地,内部全局与外部全局就处于同一平面,就可以正常通信.
同理,外部全局(SA)要和内部本地(DA)通信,由于数据方向是外部全局--->内部本地,要统一到本地平面,外部全局就需要被转换到外部本地,用然后外部本地与内部本地通信.
事实上,我们可以这样理解路由器的行为:
从内部本地发向外部全局的数据,数据包的源地址是内部本地,目的地址是外部本地,在经过路由器的inside接口后,源地址被替换为内部全局,而目的地址被替换为外部全局,也就是说实现了从本地平面向全局平面的迁移,在这里,如果转换前后的目标地址相同(外部本地和外部全局),就可以认为是普通的由内到外的NAT,如果转换前后的目标地址不同(外部本地和外部全局),就可以将这种方式用来处理路由器两边网络存在地址重叠的情况.
从外部全局发向内部本地的数据,数据保的源地址是外部全局,目的地址是内部全局,在经过路由器的outside接口后,源地址被替换为外部本地,而目的地址被替换为内部本地,也就是说实现了从全局平面向本地平面的迁移,在这里,如果转换前后的目标地址相同(内部全局和内部本地)相同,就可以认为是普通的由外向内的NAT,如果转换前后的目标地址不同,就可以将这种方式用来处理路由器两边网络存在地址重叠的情况.
============
NAT 具体命令理解
1,由内向外的转换,在路由器的inside口处发生了NAT转换行为
r1-2514(config)#ip nat inside ?
destination Destination address translation
source Source address translation
从上面可以看出,在inside边可以对数据包中的源地址或者目标地址进行转换.
r1-2514(config)#ip nat inside source ?
list Specify access list describing local addresses
route-map Specify route-map
static Specify static local->global mapping
从上面可以看出,针对源地址进行转换可以使用acl 或者 route-map来表述一个本地地址,意思是数据包中源地址符合这些的都要被转换. 也可以使用static进行静态映射,指定一个静态的从本地到全局的映射.
r1-2514(config)#ip nat inside source list 1 ?
interface Specify interface for global address
pool Name pool of global addresses
从上面输出可以看出接下来要给一个全局地址,数据包中的源地址将被这个全局地址替代.
对于静态映射,还可以指定协议 端口号:
When translating addresses to an interface's address, outside-initiated connections to services on the inside network (like mail) will require additional configuration to send the connection to the correct inside host. This command allows the user to map certain services to certain inside hosts.
list Specify access list describing global addresses
pool Name pool of local addresses
pool Name pool of local addresses
所以这是一个针对从outside向inside方向数据的NAT,凡是在这个方向数据包中目标地址符合ACL描述的全部被转换成POOL中的本地地址.这可以被用来进行TCP的负载均衡,即外部都请求同一个全局地址,而在路由器的inside边,这些请求的目标地址全部被转换成地址池中的地址,而且是循环使用地址池中的地址,从而达到负载均衡,但是这种方法只适合TCP流,同时不适宜用在WEB服务的负载均担上.详细解释看这里:
source Source address translation
list Specify access list describing global addresses
route-map Specify route-map
static Specify static global->local mapping
pool Name pool of local addresses
ip nat pool net-20 171.69.233.208 171.69.233.223 netmask <netmask> 255.255.255.240
ip nat inside source list 1 pool net-20
!
interface Ethernet0
ip address 171.69.232.182 255.255.255.240
ip nat outside
!
interface Ethernet1
ip address 192.168.1.94 255.255.255.0
ip nat inside
!
access-list 1 permit 192.168.1.0 0.0.0.255
access-list 1 permit 192.168.2.0 0.0.0.255
The next sample configuration translates between inside hosts addressed from the 9.114.11.0 net to the globally unique 171.69.233.208/28 network. Packets from outside hosts addressed from 9.114.11.0 net (the "true" 9.114.11.0 net) are translated to appear to be from net 10.0.1.0/24.
ip nat pool net-20 171.69.233.208 171.69.233.223 netmask <netmask> 255.255.255.240
ip nat pool net-10 10.0.1.0 10.0.1.255 netmask <netmask> 255.255.255.0
ip nat inside source list 1 pool net-20
ip nat outside source list 1 pool net-10
!
interface Ethernet0
ip address 171.69.232.182 255.255.255.240
ip nat outside
!
interface Ethernet1
ip address 9.114.11.39 255.255.255.0
ip nat inside
!
access-list 1 permit 9.114.11.0 0.0.0.255
ip nat pool <name> { netmask <mask> | prefix-length <length> } [ type { rotary } ]
This command will put the user into IP NAT Pool configuration mode, where a sequence of address ranges can be configured. There is only one command in this mode:
address <start> <end>
Example:
Router(config)#ip nat pool fred prefix-length 24
Router(config-ipnat-pool)#address 171.69.233.225 171.69.233.226
Router(config-ipnat-pool)#address 171.69.233.228 171.69.233.238
This configuration creates a pool containing addresses 171.69.233.225-226 and 171.69.233.228-238 (171.69.233.227 has been omitted).
ip nat inside source list <number> interface <interface> overload
If there is no address on the interface, or it the interface is not up, no translation will occur.
Example:
ip nat inside source list 1 interface Serial0 overload
ip nat inside source static { tcp | udp } <localaddr> <localport> <globaladdr> <globalport>
Example:
ip nat inside source static tcp 192.168.10.1 25 171.69.232.209 25
In this example, outside-initiated connections to the SMTP port (25) will be sent to the inside host 192.168.10.1.
ip nat inside source route-map <name> pool <name>
Example:
ip nat pool provider1-space 171.69.232.1 171.69.232.254 prefix-length 24
ip nat pool provider2-space 131.108.43.1 131.108.43.254 prefix-length 24
ip nat inside source route-map provider1-map pool provider1-space
ip nat inside source route-map provider2-map pool provider2-space
!
interface Serial0/0
ip nat outside
!
interface Serial0/1
ip nat outside
!
interface Fddi1/0
ip nat inside
!
route-map provider1-map permit 10
match ip address 1
match interface Serial0/0
!
route-map provider2-map permit 10
match ip address 1
match interface Serial0/1
转载于:https://blog.51cto.com/51like/389336