cấu hình nat cơ bản

6
Cấu hình NAT cơ bản + NAT Static: NAT một địa chỉ Local ra một địa chỉ Global tương ứng. Bước 1:Tạo câu lệnh NAT Static Gán địa chỉ IP Local với địa chỉ Global: Router(config)# ip nat inside source static local-ip global-ip Bước 2: Áp dụng vào từng interface thích hợp: Router (config)# interface type number Router (config-if)# ip nat inside (áp dụng cho cổng vào) Router (config)# interface type number Router (config-if)# ip nat outside (áp dụng cho cổng ra) thành một nhóm địa chỉ local.+ NAT Dynamic: NAT từ một nhóm địa chỉ Local Bước 1: Tạo một pool các địa chỉ IP global được cấp phát cần NAT thành: Router(config)# ip nat pool name start-ip end-ip {netmask netmask | prefix-length prefix-length} Bước 2: Tạo ACL cho phép Dải địa chỉ nào được phép ra ngoài. Router(config)# access-list access-list-number permit source [sourcewildcard] Bước 3: Kết hợp ACLs với pool NAT RouterX(config)# ip nat inside source list access-list-number pool name Bước 4: Áp Dụng vào những interface thích hợp. Router (config)# interface type number Router (config-if)# ip nat inside (áp dụng cho cổng vào)

Upload: german

Post on 22-Nov-2014

117 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: Cấu hình NAT cơ bản

Cấu hình NAT cơ bản

+ NAT Static: NAT một địa chỉ Local ra một địa chỉ Global tương ứng.Bước 1:Tạo câu lệnh NAT Static Gán địa chỉ IP Local với địa chỉ Global:

Router(config)# ip nat inside source static local-ip global-ip

Bước 2: Áp dụng vào từng interface thích hợp:

Router (config)# interface type numberRouter (config-if)# ip nat inside (áp dụng cho cổng vào)

Router (config)# interface type numberRouter (config-if)# ip nat outside (áp dụng cho cổng ra)

thành một nhóm địa chỉ local.+ NAT Dynamic: NAT từ một nhóm địa chỉ Local Bước 1: Tạo một pool các địa chỉ IP global được cấp phát cần NAT thành:

Router(config)# ip nat pool name start-ip end-ip {netmask netmask | prefix-length prefix-length}

Bước 2: Tạo ACL cho phép Dải địa chỉ nào được phép ra ngoài.Router(config)# access-list access-list-number permit source [sourcewildcard]

Bước 3: Kết hợp ACLs với pool NAT

RouterX(config)# ip nat inside source list access-list-number pool name

Bước 4: Áp Dụng vào những interface thích hợp.

Router (config)# interface type numberRouter (config-if)# ip nat inside (áp dụng cho cổng vào)

Router (config)# interface type numberRouter (config-if)# ip nat outside (áp dụng cho cổng ra)

+ NAT Overload hay còn gọi là PAT Cho phép nhiều địa chỉ Local được NAT thành 1 địa chỉ public.Bước 1: Tạo ACL cho phép dải địa chỉ Local nào được phép ra ngoài.RouterX(config)# access-list access-list-number permit source [sourcewildcard]Bước 2: Tạo lệnh NAT Dynamic kết hợp với ACL vừa tạoRouterX(config)# ip nat inside source list access-list-number interface interface overloadBước 3: Áp dụng vào interface thích hợpRouter (config)# interface type number

Page 2: Cấu hình NAT cơ bản

Router (config-if)# ip nat inside (áp dụng cho cổng vào)

Router (config)# interface type numberRouter (config-if)# ip nat outside (áp dụng cho cổng ra)

Tuy nhiên đôi khi Gặp phải những trường hợp trong thực tế ta có thể kết hợp giữa NAT Overload và NAT Dynamic: Bước 1: Tạo một pool các địa chỉ IP global được cấp phát cần NAT thành:

Router(config)# ip nat pool name start-ip end-ip {netmask netmask | prefix-length prefix-length}

Bước 2: Tạo ACL cho phép Dải địa chỉ nào được phép ra ngoài.Router(config)# access-list access-list-number permit source [sourcewildcard]

Bước 3: Kết hợp ACLs với pool NAT

RouterX(config)# ip nat inside source list access-list-number pool name Overload

Bước 4: Áp Dụng vào những interface thích hợp.

Router (config)# interface type numberRouter (config-if)# ip nat inside (áp dụng cho cổng vào)

Router (config)# interface type numberRouter (config-if)# ip nat outside (áp dụng cho cổng ra)

+ Để check lai trạng thái cấu hình dùng câu lệnh:Router(config)# Show IP nat Translation

+ Cấu Hình NAT theo thời gian:

Mục đích :

Bạn muốn lọc ứng dụng theo thời gian Giải pháp

Để lọc theo thời gian trong ngày bạn dùng những lệnh sau :

Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z.Router1(config)#time-range NOSURFRouter1(config-time-range)# periodic weekdays 9:00 to 17:00

Page 3: Cấu hình NAT cơ bản

Router1(config-time-range)#exitRouter1(config)#ip access-list extended NOSURFINGRouter1(config-ext-nacl)# deny tcp any any eq www time-range NOSURFRouter1(config-ext-nacl)# permit ip any anyRouter1(config-ext-nacl)#exitRouter1(config)#interface FastEthernet0/1Router1(config-if)#ip access-group NOSURFING in Router1(config-if)#endRouter1# Giải thích

Timed-based access-lists cho phép bạn có thể lọc dữ liệu của ứng dụng dựa trên thời gian trong ngày. Trong ví dụ trên , chúng ta xây dựng một access-list cấm HTTP traffic trong suốt giờ làm việc của công ty từ thứ 2 đến thứ 6 trong khoảng thời gian cụ thể là 9:00 -17:00. Timed-based access-lists cũng có thể giúp ta điểu khiển trên những ứng dụng khác của router dựa vào thời gian trong ngày như policy-based routing, CAR statements, ACL logging, on-demand link activation, hay security policies.

Việc đầu tiên khi cấu hình một timed-based access-list là bạn phải cấu hình một time-range:

Router2#configure terminal Enter configuration commands, one per line. End with CNTL/Z.Router2(config)#time-range nccRouter2(config-time-range)#periodic monday 9:00 to 17:00Router2(config-time-range)#endRouter2#

Trong ví dụ này , chúng ta đặt tên cho time-range là ncc và gán cho nó một time-range bắt đầu từ thứ 2 lúc 9:00-17:00. Periodic dùng để định nghĩa một time range. Tuy nhiên vẫn còn một cách khác để gán một giới hạn về thời gian bằng cách dùng lệnh absolute . Cách này ta phải đưa ra một khoảng thời gian thật cụ thể. Các bạn xem ví dụ bên dưới

Router2#configure terminal Enter configuration commands, one per line. End with CNTL/Z.Router2(config)#time-range ncc Router2(config-time-range)#absolute start 9:00 1 October 1988 end 18:00 31 December 1988Router2(config-time-range)#end Router2#

Chú ý là bạn có thể thiết lập cả 2 Periodic và absolute trên cùng một time-range. Và absolute được ưu tiên hơn :

Router2#configure terminal Enter configuration commands, one per line. End with CNTL/Z.

Page 4: Cấu hình NAT cơ bản

Router2(config)#time-range nccRouter2(config-time-range)#absolute start 9:00 1 October 1988 end 18:00 31 December 1988 # được ưu tiênRouter2(config-time-range)#periodic monday 9:00 to 17:00Router2(config-time-range)#endRouter2#

Notice in this example that we've included a periodic and absolute statement within the same time range. In this case, the periodic statement is ignored until the absolute start time is reached, and then each Monday the time range will become active. The same holds true for the absolute end time. Once we reach the absolute end time of 18:00 on December 31, then the periodic statements will again be ignored.

Chúc ý là trong trường hợp trên, Periodic sẽ không active mãi cho đến khi absolute bắt đầu (có nghĩa là cho dù thứ 2 là ngày 31/9 đi nữa những sẽ không có tác dụng mà phải đợi đến đúng 9:00 1 October 1988thì mới có tác dụng.) Sau khi absolute bắt đầu , đến mỗi thứ 2 thì time range sẽ được active.Sau khi absolute kết thúc tại 18:00 31 December 1988 thì Periodic tiếp tục không active (time range không active).Trích:Bạn có thể dùng nhiều câu lệnh Periodic nhưng chỉ có thể dùng duy nhất 1 absolute cho một range-time Sau khi đã cấu hình time range, bây giờ bạn đã có thể cấu hình ACL:

Router1#configure terminal Enter configuration commands, one per line. End with CNTL/Z.Router1(config)#ip access-list extended PhúcRouter1(config-ext-nacl)# deny tcp any any eq www time-range nccRouter1(config-ext-nacl)# permit ip any anyRouter1(config-ext-nacl)#endRouter1#

Chú ý là bạn gán time range vào đúng câu lệnh ACLs đầu tiên. ACLs sẽ bắt đầu active khi time-range đúng. Khi time-range active thì ACLs sẽ bắt đầu thực hiện những gì mà ta đã cấu hình. Trong ví dụ trên, ACL sẽ cắm tất cả HTTP traffice trong giờ làm việc.

Chúng ta thử xem ACLs sau giờ làm việc sẽ như thế nào (tất nhiên là inactive rồi !!!!):

Router1#show clock2050.985 EDT Tue Aug 22 1988Router1#Router1#show ip access-listExtended IP access list Phúc10 deny tcp any any eq www time-range ncc (inactive)20 permit ip any anyRouter1#

Page 5: Cấu hình NAT cơ bản

During this period, the timed ACL entry is marked inactive and HTTP-based traffic is allowed to pass. During normal workday hours, however, the timed ACL entry is changed to active and HTTP traffic is now blocked:

Router1#show clock0922.279 EDT Wed Aug 23 1988Router1#Router1#show ip access-listExtended IP access list ncc10 deny tcp any any eq www time-range ncc (active)20 permit ip any anyRouter1#