一个以太口做nat 行吗?
请教:小区宽带接入,提供RJ45接口,如果用路由器,只有一个E0口,
配置两个IP, 作NAT, 既做INSIDE,又作OUTSIDE, 行吗?
-----------------------------------------------------------------------------------
可以的
这是一个例子:
interface Loopback0
ip address 10.0.1.1 255.255.255.252
ip nat outside
!--- Creates a virtual interface called Loopback 0 and assigns an
!--- IP address of 10.0.1.1 to it. Defines interface Loopback 0 as
!--- NAT outside.
!
!
interface Ethernet0
ip address 192.168.1.2 255.255.255.0 secondary
ip address 10.0.0.2 255.255.255.0
ip Nat inside
!--- Assigns a primary IP address of 10.0.0.2 and a secondary IP
!--- address of 192.168.1.2 to Ethernet 0. Defines interface Ethernet 0
!--- as NAT inside. The 192.168.1.2 address will be used to communicate
!--- through the CM to the CMTS and the Internet. The 10.0.0.2 address
!--- will be used to communicate with the local hosts.
ip policy route-map Nat-loop
!--- Assigns route-map "Nat-loop" to Ethernet 0 for policy routing.
!
ip Nat pool external 192.168.2.2 192.168.2.3 prefix-length 29
ip Nat inside source list 10 pool external overload
ip Nat inside source static 10.0.0.12 192.168.2.1
!--- NAT is defined: packets matching access-list 10 will be
!--- translated to an address from the pool called "external".
!--- A static NAT translation is defined for 10.0.0.12 to be
!--- translated to 192.168.2.1 (this is for host 2 which needs
!--- to be accessed from the Internet).
ip classless
!
!
ip route 0.0.0.0 0.0.0.0 192.168.1.1
ip route 192.168.2.0 255.255.255.0 Ethernet0
!--- Static default route set as 192.168.1.1, also a static
!--- route for network 192.168.2.0/24 directly attached to
!--- Ethernet 0
!
!
access-list 10 permit 10.0.0.0 0.0.0.255
!--- Access-list 10 defined for use by NAT statement above.
access-list 102 permit ip any 192.168.2.0 0.0.0.255
access-list 102 permit ip 10.0.0.0 0.0.0.255 any
!--- Access-list 102 defined and used by route-map "Nat-loop"
!--- which is used for policy routing.
!
Access-list 177 permit icmp any any
!--- Access-list 177 used for debug.
!
route-map Nat-loop permit 10
match ip address 102
set ip next-hop 10.0.1.2
!--- Creates route-map "Nat-loop" used for policy routing.
!--- Route map states that any packets matching access-list 102 will
!--- have the next hop set to 10.0.1.2 and be routed "out" the
!--- loopback interface. All other packets will be routed normally.
!
end
NAT-router#
------------------------------------------------------------------------------------
这就是CISCO网站讲的nat on stick
主要是要理解路由器的NAT原理、过程以及策略路由的原理过程就应该可以理解上述配置。
首先,NAT必须发生在两个接口(一个inside一个outside),但不一定必须要两个物理接口,逻辑接口也可以,比如本例中只有一个E0,因此就需要虚拟一个接口,如loopback。
其次,set ip next-hop 10.0.1.2这个指令是虚构的一个地址,必须与loopback口在一个网段,如果该地址设置的与loopback地址相同则会引起所有过来的数据报被丢弃。
第三,要理解NAT的处理过程。从内部到外部的是先路由后NAT,从外部到内部的是先NAT后路由。
第四,要理解策略路由与NAT的顺序,在这里都是先策略路由到loopback口,然后再NAT。
第五,要理解以太网口处理数据包的原理。多注意cisco路由器的debug中的forwarding的含义和顺序。
http://www.cisco.com/warp/public/556/nat-on-stick.pdf
-----------------------------------------------------------------------------------------
看看以前的资料
条件:
1、IOS在12.1(5)T9及以上版本。更低版本未做验证。
2、至少具有两个或多个ISP提供的的global地址。
实现思路:
1、将ISP提供的地址作为secondary地址配置在以太接口上。该以太接口同时作为inside接口。作为内部主机的网关。
2、 创建一个loopback接口做为nat的outside.
3、使用route-map,强行将内部网出去的数据包及从外部返回的对应数据包路由到loopback接口。
实例:
拓朴如下图所示:
配置如下:
interface Loopback0
ip address 172.16.2.254 255.255.255.252
ip nat outside
!
//创建一个loopback接口,并作为NAT outside接口。
interface Ethernet0
ip address 192.168.0.1 255.255.255.248 secondary
ip address 172.16.1.254 255.255.255.0
ip Nat inside
ip policy route-map rm-nat
!
//在E0接口上配置172.16.1.254做为IP,同时将ISP提供的地址做为Secondary地址。e0做为inside接口。
在本接口上应用rm-nat这个route-map
ip nat pool pool1 192.168.0.2 192.168.0.3 prefix-length 29
ip nat inside source list 10 pool pool1 overload
//常规NAT配置
ip classless
ip route 0.0.0.0 0.0.0.0 192.168.0.6
ip route 172.16.1.0 255.255.255.0 Ethernet0
access-list 10 permit 172.16.1.0 0.0.0.255
//配置路由及NAT所需要的access-list
access-list 101 permit ip 172.16.1.0 0.0.0.255 any
access-list 101 permit ip any 192.168.0.0 0.0.0.7
//配置route-map所需要的acl。第一句匹配出去的包,第二句匹配返回的包。
route-map rm-nat permit 10
match ip address 101
set ip next-hop 172.16.2.254
//配置所需要的route-map,凡是满足access-list 101条件的包均被转发到172.16.2.254(loopback0接口)。
浙公网安备 33010602011771号