NAT

 NAT(Network Address Translation)

 
·NAT核心思想:將私網地址轉換成公網地址。
NAT technology enables private IP networks that use nonregistered IP addresses to connect to a public network. 
 
·私網地址範圍:
 10.0.0.0 - 10.255.255.255
  172.16.0.0 - 172.31.255.255
  192.168.0.0 - 192.168.255.255
 
·NAT常用於下述情形:
 1.沒有足夠的公網連接到Internet
  2.當更換ISP需要重新編址
 3.合併兩個使用重疊地址空間的內部網絡
 4.使用單個IP地址支持基本的負載分擔
 
·使用NAT做地址轉換時,可以靜態的,也可以是動態的
 靜態:內部地址被預選映射到指定的外部地址,內部地址和外部地址是一一對應的。
 動態:內部地址可以使用地址池中的外部地址。
 (內部=私網) (外部=公網)
 PAT(Port Add translation):多個內部地址共享一個外部地址,通過
端口號多路複用。
 
·優點:
 1.節省了公網IP地址
 2.能夠處理編址方案重疊的情況
 3.網絡發生改變時不需要重新編址
 4.隱藏了真正的IP地址
 
·缺點:
 1.NAT引起數據交互的延遲
 2.導致無法進行端到端的IP跟蹤
 3.某些應用程序不支持NAT
 4.需要消耗額外的CPU和內存
 
<靜態內部源地址轉換>
 
1)配置IP地址,DCE配置時鐘,將R2變成PC機(no ip routing)
 
2)定義NAT的內口/外口
interface Ethernet0/0
 ip address 192.168.8.3 255.255.255.0
 ip nat inside
 
interface Serial0/1
 ip address 200.1.1.3 255.255.255.0
 ip nat outside
 
3)地址轉換(將私網地址轉換成已經購買的公網IP地址)
R3(config)#ip nat inside source static 192.168.8.2   200.1.1.2 
                   (inside local)(inside global)
 
4)配置默認路由:
R3(config)#ip route 0.0.0.0 0.0.0.0 serial 0/1
 
 路由器接口默認開啓Proxy ARP
 R3(config-if)#no ip proxy-arp  (關閉代理ARP)
 PC-R2#clear arp-cache (清ARP表項)
 
5)在PC機上設置默認網關
PC-R2(config)#ip default-gateway 192.168.8.3
 如果路由器接口支持Proxy-arp時也可不用設。(對端接口)
 
R3#show ip nat translations (查看NAT轉換表項)
R3#show ip nat statistics (查看NAT的統計信息)
 
R3#debug ip nat (查看NAT轉換信息)
 
 
*Mar  1 01:28:14.110: NAT*: s=192.168.8.2->200.1.1.2, d=1.1.1.1
*Mar  1 01:28:14.114: NAT*: s=1.1.1.1, d=200.1.1.2->192.168.8.2 
 
<PAT>
 
1)新增加一臺主機R4,(no ip rouing),設置網關。
 
2)定義NAT的內口/外口
 
3)定義可被轉換的私網地址
R3(config)#access-list 8 permit 192.168.8.0 0.0.0.255
 
4)端口複用
ip nat inside source list 8 interface Serial0/1 overload
           (access-list) (出去的端口) (端口複用)
 
5)設置默認路由
 
show ip nat [translations]在網關上看一些信息,端口號和IP地址的對應關係,本表項一分鐘後就會刪除
 
<動態內部源地址轉換>
 
1)將PC-R4改成192.168.9.4/24
   在R3上做一個192.168.9.3/24的secondary地址
 ip address 192.168.9.3 255.255.255.0 secondary
 
2)定義NAT的外口/內口
 
3)定義可被轉換的私網地址
R3(config)#access-list 8 permit 192.168.8.0 0.0.0.255
R3(config)#access-list 9 permit 192.168.9.0 0.0.0.255
 
R3#show ip access-lists (查看訪問控制列表)
 
4)定義地址池(已經購買的IP地址200.1.1.10-200.1.1.15)
ip nat pool POOL-8 200.1.1.10 200.1.1.12 prefix-length 24
      (名字)(起始IP) (終結IP)     (掩碼)
ip nat pool POOL-9 200.1.1.13 200.1.1.15 netmask 255.255.255.0
 
5)動態映射:
R3(config)#ip nat inside source list 8 pool POOL-8 [overload]
R3(config)#ip nat inside source list 9 pool POOL-9 [overload]
 
6)配置靜態路由
 
R3#clear ip nat translation * (清NAT轉換表項)
  (針對Static映射不起效)
 
 
<訪問內網服務器>
 
1)將R2、R4模擬成FTP&WEB服務器。
  R2、R3、R4還是在同一網段192.168.8.0/24
 
2)定義NAT的外口/內口
 
3)配置映射:
 
ip nat inside source static tcp 192.168.8.2  23 200.1.1.3 10000 extendable
                             (inside local) (local port) (inside global) (global port任意指定)
 
ip nat inside source static tcp 
192.168.8.4 23 interface serial 0/1 20000
 
R3(config)#line vty 0 4
R3(config-line)#no login (telnet本路由器時不需密碼)
 
·在R2、R4上的Line vty 0 4 設置無密碼(no login)
 
測試:在R1上
R1#telnet 200.1.1.3 10000  >FTP
R1#telnet 200.1.1.3 20000    >WEB
 
R3#show ip nat  translations
 
CCIE中的一道題
3.3 IP Masquerading(R6)
Telnet from any (except R3) within your topology to Y.Y.6.254 will result in a connection to R3 lo0 interface IP address, HTTP session originating from any(except R3)within topology to Y.Y.6.254 to R3 s0/0(36.1/24).Do not transition any other connections  session between R3 and any other devices in your topology,不創建新interface 使用secoudry 完成這個
36.1->80
 
int s0/0(36.0/30)
ip nat inside
int e0/0(67.0/24)
ip nat outside
 
ip nat inside source static tcp 8.8.36.1 80 8.8.6.254 80 extendable
ip nat inside source static tcp 8.8.3.3 23 8.8. 6.254 23 extendable
 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章