• If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.
Xin chào ! Nếu đây là lần đầu tiên bạn đến với diễn đàn, xin vui lòng danh ra một phút bấm vào đây để đăng kí và tham gia thảo luận cùng VnPro.

Announcement

Collapse
No announcement yet.

Lab 1-3: NAT động với Multiple Pool sử dụng Route-map để kiểm soát quá trình NAT

Collapse
This is a sticky topic.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Lab 1-3: NAT động với Multiple Pool sử dụng Route-map để kiểm soát quá trình NAT

    Dynamic NAT with Multiple Pool Using Route Maps

    1. Mục tiêu
    Bài lab này, chúng ta sẽ cấu hình NAT động với multiple pools dùng Route-map

    2. Hoàn cảnh



    Tất cả các user trên LAN SanJose1 có nhu cầu truy cập tới Web Server trên SanJose2 và SanJose3. Tất cả các host trên mạng 192.168.1.0 được chuyển thành:
    - 172.106.2.0 khi truy cập WebServer2 (172.106.1.2)
    - 172.160.2.0 khi truy cập Web Server3 (172.160.1.2)

    3. Thực hiện
    Bước1 :
    Cấu hình địa chỉ IP các router dựa theo sơ đồ trên. Đồng thời, để giả lập WebServer, ta cấu hình router SanJose2 và SanJose3 thành WebServer như sau:

    SanJose2(config)#ip http server
    SanJose3(config)#ip http server


    Do không sử dụng routing protocol, nên ta cấu hình static route trên SanJose1 để đến các Web Server trên SanJose2 và SanJose3.
    Default route cũng được cấu hình trên SanJose2 và SanJose3 để đến mạng 192.168.1.0

    SanJose1(config)#ip route 172.106.1.0 255.255.255.0 10.0.0.3
    SanJose1(config)#ip route 172.160.1.0 255.255.255.0 10.0.0.2

    SanJose2(config)#ip route 0.0.0.0 0.0.0.0 10.0.0.1
    SanJose3(config)#ip route 0.0.0.0 0.0.0.0 10.0.0.1

    Kiểm tra :
    Extend ping từ SanJose2 (172.160.1.2) đến SanJose3 (172.106.1.2).
    Ping thành công do packet đi từ SanJose2 theo đường default route đến 10.0.0.1, sau đó được SanJose1 gửi đến mạng 172.106.1.0 qua static route dùng next hop 10.0.0.3


    Bước 2:
    Tạo các pool địa chỉ để các host trên mạng 192.168.1.0 (địa chỉ private) ra ngoài Internet. Đồng thời tạo các ACL cho phép các chỉ host trên mạng 192.168.1.0 mới được truy cập vào mạng 172.106.1.0 và 172.160.1.0

    SanJose1(config)#ip nat pool pool106 172.106.2.1 172.106.2.254 prefix-length 24
    SanJose1(config)#ip nat pool pool160 172.160.2.1 172.160.2.254 prefix-length 24

    SanJose1(config)#access-list 106 permit ip 192.168.1.0 0.0.0.255 172.106.1.0 0.0.0.255
    SanJose1(config)#access-list 160 permit ip 192.168.1.0 0.0.0.255 172.160.1.0 0.0.0.255

    Bước 3:
    Chỉ định các inside và outside cho NAT trên SanJose1:

    SanJose1(config)#interface e0/0
    SanJose1(config)#ip nat outside

    SanJose1(config)#interface e1/0
    SanJose1(config)#ip nat inside

    Bước 4:
    • NAT dùng access list và route map chỉ khi nó cần tạo một translation entry. Nếu một translation entry đã tồn tại, match với traffic, router sẽ sử dụng entry đó, và không so sánh với access list hay route map.
    • Sự khác nhau giữa việc sử dụng access list và route map là loại translation entry được tạo ra.
    • Khi NAT sử dụng route map để tạo translation entry, nó sẽ luôn luôn tạo ra một translation entry “đầy đủ”. Translation entry này sẽ bao gồm cả các địa chỉ inside và outside, local và global, thông tin cổng TCP hoặc UDP.
    • Khi NAT sử dụng access list để tạo translation entry, nó sẽ tạo một translation entry đơn giản. Nó chỉ bao gồm các địa chỉ IP inside local, inside global và không bao gồm thông tin cổng TCP hay UDP.
    • Ta sẽ kiểm tra hoạt động của NAT khi dùng access list để giải thích tại sao nó không phải là cách giải quyết vấn đề một cách lý tưởng trong trường hợp này.

    SanJose1(config)#ip nat inside source list 106 pool pool106
    SanJose1(config)#ip nat inside source list 160 pool pool160

    Dùng debug ip nat trên router SanJose1 và SanJose3

    Tại Host A trên SanJose1 truy cập tới Web Server trên SanJose3 (địa chỉ 172.106.1.2) và theo dõi kết quả debug

    SanJose1#debug ip nat
    IP NAT debugging is on
    SanJose1#
    00:26:18: NAT*: s=192.168.1.2->172.106.2.1, d=172.106.1.2 [12415]
    00:26:18: NAT*: s=172.106.1.2, d=172.106.2.1->192.168.1.2 [12415]
    00:26:19: NAT*: s=192.168.1.2->172.106.2.1, d=172.106.1.2 [12416]
    00:26:19: NAT*: s=172.106.1.2, d=172.106.2.1->192.168.1.2 [12416]

    Dùng lệnh show ip nat translations trên router SanJose1:

    SanJose1#show ip nat translations
    Pro Inside global Inside local Outside local Outside global
    --- 172.106.2.1 192.168.1.2 --- ---

    Dùng debug ip nat trên router SanJose1 và SanJose2
    Tại Host A trên SanJose1 truy cập tới Web Server trên SanJose3 (địa chỉ 172.160.1.2) và theo dõi kết quả debug

    SanJose1#debug ip nat
    IP NAT debugging is on
    SanJose1#
    00:26:18: NAT*: s=192.168.1.2->172.106.2.1, d=172.160.1.2 [12415]
    00:26:18: NAT*: s=172.160.1.2, d=172.106.2.1->192.168.1.2 [12415]
    00:26:19: NAT*: s=192.168.1.2->172.106.2.1, d=172.160.1.2 [12416]
    00:26:19: NAT*: s=172.160.1.2, d=172.106.2.1->192.168.1.2 [12416]

    Dùng lệnh show ip nat translations trên router SanJose1:

    SanJose1#show ip nat translations
    Pro Inside global Inside local Outside local Outside global
    --- 172.106.2.1 192.168.1.2 --- ---

    Ta thấy ở cả 2 trường hợp, host 192.168.1.2 đều ra ngoài Internet bằng địa chỉ 172.106.2.1. Điều đó cho thấy, NAT chỉ translation lần đầu tiên khi host đến webserver trên SanJose2, Còn khi host đến webserver trên SanJose3 thì NAT đã match thấy địa chỉ IP của host nên không xử lý, mà tiếp tục cho phép host này ra ngoài với IP như cũ, mà không xét đến ACL.

    NOTE:
    Ta có thể bắt buộc NAT phải xét đến ACL mỗi khi translation một entry bằng cách disable fast-switching trên interface e1/0.

    SanJose1(config)#int e1/0
    SanJose1(config-if)#no ip route-cache
    Nhưng cách này không được recommend vì nó bắt router phải sử dụng resource để xử lý. Ta sẽ giải quyết vấn đề này ở sau.


    Ta debug ip packet để xem thêm thông tin

    SanJose1#debug ip packet
    IP packet debugging is on
    SanJose1#
    00:29:42: IP: s=172.106.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward
    00:29:43: IP: s=172.106.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward
    00:29:44: IP: s=172.106.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward
    00:29:45: IP: s=172.106.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward


    SanJose1#debug ip packet
    IP packet debugging is on
    SanJose1#
    00:30:23: IP: s=172.106.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward
    00:30:24: IP: s=172.106.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward
    00:30:25: IP: s=172.106.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward
    00:30:26: IP: s=172.106.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward



    Bước 5:
    Trước khi cấu hình route map, ta bỏ một vài lệnh đã cấu hình trước như sau :

    SanJose1#undebug ip nat
    SanJose1#clear ip nat translation *

    SanJose1#configure terminal
    SanJose1(config)#no ip nat inside source list 106 pool pool106
    SanJose1(config)#no ip nat inside source list 160 pool pool160

    Lúc này ta vẫn còn các pool đã được định nghĩa trước như sau :

    ip nat pool pool106 172.106.2.1 172.106.2.254 prefix-length 24
    ip nat pool pool160 172.160.2.1 172.160.2.254 prefix-length 24


    Bây giờ, ta sẽ cấu hình route map để giải quyết vấn đề tồn tại của access list.
    Tạo một inside source route map và address pool như sau:

    SanJose1(config)#ip nat inside source route-map MAP-106 pool pool106
    SanJose1(config)#ip nat inside source route-map MAP-160 pool pool160

    Tạo route map:

    SanJose1(config)#route-map MAP-106 permit 10
    SanJose1(config-route-map)#match ip address 106

    SanJose1(config)#route-map MAP-160 permit 10
    SanJose1(config-route-map)#match ip address 160

    Dùng debug ip nat trên router SanJose1 và SanJose3
    Tại Host A trên SanJose1 truy cập tới Web Server trên SanJose3 (địa chỉ 172.106.1.2) và theo dõi kết quả debug

    SanJose1#debug ip nat
    IP NAT debugging is on
    SanJose1#
    00:42:12: NAT : s=192.168.1.2->172.106.2.2, d=172.106.1.2 [12435]
    00:42:12: NAT*: s=172.106.1.2, d=172.106.2.2->192.168.1.2 [12435]
    00:42:13: NAT*: s=192.168.1.2->172.106.2.2, d=172.106.1.2 [12436]
    00:42:13: NAT*: s=172.106.1.2, d=172.106.2.2->192.168.1.2 [12436]
    00:42:14: NAT*: s=192.168.1.2->172.106.2.2, d=172.106.1.2 [12437]

    Dùng debug ip nat và debug ip packet trên router SanJose1 và SanJose2
    Tại Host A trên SanJose1 truy cập tới Web Server trên SanJose3 (địa chỉ 172.160.1.2) và theo dõi kết quả debug

    SanJose1#debug ip nat
    IP NAT debugging is on
    SanJose1#
    00:46:21: NAT*: s=192.168.1.2->172.160.2.2, d=172.160.1.2 [12455]
    00:46:21: NAT*: s=172.160.1.2, d=172.160.2.2->192.168.1.2 [12455]
    00:46:22: NAT*: s=192.168.1.2->172.160.2.2, d=172.160.1.2 [12456]
    00:46:22: NAT*: s=172.160.1.2, d=172.160.2.2->192.168.1.2 [12456]
    00:46:23: NAT*: s=192.168.1.2->172.160.2.2, d=172.160.1.2 [12457]

    SanJose1#debug ip packet
    IP packet debugging is on
    SanJose1#
    00:46:55: IP: s=172.160.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward
    00:46:56: IP: s=172.160.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward
    00:46:56: IP: s=0.0.0.0 (Ethernet0/0), d=255.255.255.255, len 328, rcvd 2
    00:46:57: IP: s=172.160.1.2 (Ethernet0/0), d=192.168.1.2 (Ethernet1/0), g=192.168.1.2, len 60, forward

    Dùng lệnh show ip nat translations verbose trên router SanJose1:

    SanJose1#show ip nat translations verbose
    Pro Inside global Inside local Outside local Outside global
    icmp 172.160.2.2:512 192.168.1.2:512 172.160.1.2:512 172.160.1.2:512
    create 00:01:39, use 00:00:46, left 00:00:13,
    flags: extended, use_count: 0
    tcp 172.160.2.1:23 10.0.0.1:23 10.0.0.2:11002 10.0.0.2:11002
    create 00:02:41, use 00:00:05, left 00:00:54,
    flags: extended, timing-out, use_count: 0

    Dynamic NAT with multiple pools using route map đã được cấu hình thành công.

    NOTE:
    NAT dùng route map với static translation được giới thiệu lần đầu với Cisco IOS 12.2(4)T và 12.2(4)T2 cho Cisco 7500 series routers
    NAT sử dụng access list với overload sẽ tạo ra translation “đầy đủ” như với route map


    Nhận xét :
    Ta thấy, cả 2 cơ chế dùng ACL và Route-map đều là đang sử dụng fast-swiching.
    ACL thì chỉ tạo translation entry một lần đối với một host nào đó. Sau đó, nếu host đó có yêu cầu ra ngoài (đến các webserver) thì NAT sẽ không xét đến địa chỉ đích hay ACL nữa mà sử dụng entry đã có ở lần tạo trước.
    Route-map xét cả địa chỉ source lẫn địa chỉ destination (đích) nên nó thực hiện đúng với yêu cầu của ta.



    4. Cấu hình

    SanJose1#show running-config
    Building configuration...

    Current configuration:
    !
    version 12.0
    service timestamps debug uptime
    service timestamps log uptime
    no service password-encryption
    !
    hostname SanJose1
    !
    ip subnet-zero
    no ip domain-lookup
    !
    interface Ethernet0/0
    ip address 10.0.0.1 255.255.255.0
    no ip directed-broadcast
    ip nat outside
    !
    interface Ethernet1/0
    ip address 192.168.1.1 255.255.255.0
    no ip directed-broadcast
    ip nat inside
    !
    ip nat pool pool106 172.106.2.1 172.106.2.254 prefix-length 24
    ip nat pool pool160 172.160.2.1 172.160.2.254 prefix-length 24
    ip nat inside source route-map MAP-106 pool pool106
    ip nat inside source route-map MAP-160 pool pool160
    ip classless
    ip route 172.106.1.0 255.255.255.0 10.0.0.3
    ip route 172.160.1.0 255.255.255.0 10.0.0.2
    !
    access-list 106 permit ip 192.168.1.0 0.0.0.255 172.106.1.0 0.0.0.255
    access-list 160 permit ip 192.168.1.0 0.0.0.255 172.160.1.0 0.0.0.255
    route-map MAP-106 permit 10
    match ip address 106
    !
    route-map MAP-160 permit 10
    match ip address 160
    !
    !
    !
    line con 0
    logging synchronous
    transport input none
    line aux 0
    line vty 0 4
    privilege level 15
    no login
    !
    End


    SanJose2#show run
    Building configuration...

    Current configuration : 1058 bytes
    !
    version 12.1
    no service single-slot-reload-enable
    service timestamps debug uptime
    service timestamps log uptime
    no service password-encryption
    !
    hostname SanJose2
    !
    no logging buffered
    no logging buffered
    logging rate-limit console 10 except errors
    !
    memory-size iomem 10
    ip subnet-zero
    no ip domain-lookup
    !
    interface Loopback0
    ip address 172.160.1.2 255.255.255.0
    !
    interface FastEthernet0/0
    ip address 10.0.0.2 255.255.255.0
    duplex auto
    speed auto
    !
    ip classless
    ip route 0.0.0.0 0.0.0.0 10.0.0.1
    ip http server
    !
    line con 0
    logging synchronous
    transport input none
    line aux 0
    line vty 0 4
    privilege level 15
    no login
    !
    End

    SanJose3#show run
    Building configuration...

    Current configuration : 926 bytes
    !
    version 12.1
    no service single-slot-reload-enable
    service timestamps debug uptime
    service timestamps log uptime
    no service password-encryption
    !
    hostname SanJose3
    !
    ip subnet-zero
    !
    no ip finger
    no ip domain-lookup
    !
    interface Loopback0
    ip address 172.106.1.2 255.255.255.0
    !
    interface Ethernet0/0
    ip address 10.0.0.3 255.255.255.0
    half-duplex
    !
    ip kerberos source-interface any
    ip classless
    ip route 0.0.0.0 0.0.0.0 10.0.0.1
    ip http server
    !
    line con 0
    logging synchronous
    transport input none
    line aux 0
    line vty 0 4
    privilege level 15
    no login
    !
    end
    Last edited by lamvantu; 20-09-2012, 07:35 AM.

  • #2
    qua hay, dung truong hop cua em luon , NAT 1 source den nhieu` destination.

    Comment


    • #3
      em dùng phần mềm packet tracer5.0 sao em lấy cái router nào cũng ko có command ip http server hết, router version mấy mới có lệnh này ạ.thanks

      Comment


      • #4
        Chào bạn,

        Dùng packet nhanh, dễ, tuy nhiên đây chỉ là một phần mềm nên thiếu lệnh rất nhiều.
        Nếu muốn dùng đủ lệnh thì bạn nên dùng GNS3 (có giao diện) sẽ đủ các lệnh như một router thật, vì nó dùng IOS thật để chạy.
        Phạm Minh Tuấn

        Email : phamminhtuan@vnpro.org
        Yahoo : phamminhtuan_vnpro
        -----------------------------------------------------------------------------------------------
      Trung Tâm Tin Học VnPro
      149/1D Ung Văn Khiêm P25 Q.Bình thạnh TPHCM
      Tel : (08) 35124257 (5 lines)
      Fax: (08) 35124314

      Home page: http://www.vnpro.vn
      Support Forum: http://www.vnpro.org
      - Chuyên đào tạo quản trị mạng và hạ tầng Internet
      - Phát hành sách chuyên môn
      - Tư vấn và tuyển dụng nhân sự IT
      - Tư vấn thiết kế và hỗ trợ kỹ thuật hệ thống mạng

      Network channel: http://www.dancisco.com
      Blog: http://www.vnpro.org/blog

      Comment


      • #5
        topo & config is not match. Maybe wrong name . There's confusion between Sanjose 1&3

        Comment


        • #6
          Đúng rồi. Topo và config không trùng nhau.
          Chủ topic cần cẩn thận trong việc translate sao cho tương ứng.

          Comment

          • Working...
            X