24 · Explaining the Basics of ACL說明 ACL 的基礎

Verifying and Modifying IPv4 ACLs驗證與修改 IPv4 ACL

When adding ACL statements to the configuration, Cisco IOS Software automatically numbers each statement. By default, numbering starts with 10 and subsequent numbers are incremented by 10.

在設定中新增 ACL 陳述式時,Cisco IOS 軟體會自動為每條陳述式編號。預設情況下,編號從 10 開始,之後每條遞增 10。

To verify the configured access-list, you can use the following commands:

若要驗證已設定的存取清單,可使用下列指令:

  • The show access-lists command displays the content of all configured ACLs. The output can be narrowed to a specific list by providing its number or its nameshow access-lists 指令會顯示所有已設定 ACL 的內容,也可指定編號或名稱以縮小輸出範圍至特定清單。
  • The show ip access-lists command displays the content of all IPv4 access list. The output can be narrowed by specifying a specific ACL number or name.show ip access-lists 指令會顯示所有 IPv4 存取清單的內容,可指定特定 ACL 編號或名稱來縮小輸出範圍。

Both commands display ACL statements with their sequence numbers.

兩個指令都會顯示 ACL 陳述式及其序號。

The verification command output for the access lists from the previous examples would be:

前述範例中存取清單的驗證指令輸出如下:

RouterX# show access-lists 1
Standard IP access list 1
 10 deny host 172.16.3.3
 20 permit 172.16.0.0 0.0.255.255
RouterX# show access-lists 101
Extended IP access list 101
 10 deny tcp 172.16.3.0 0.0.0.255 any eq 22
 20 deny tcp 172.16.3.0 0.0.0.255 any eq telnet
 30 permit ip 172.16.3.0 0.0.0.255 any

Modifying an access list differs for numbered and named configuration method. Adding and removing statements is more convenient when using named configuration method.

修改存取清單的方式因編號式與具名設定方式而異。使用具名設定方式新增及移除陳述式較為方便。

When modifying access lists, you can delete the entire lists or add/remove specific entries.

修改存取清單時,你可以刪除整份清單,或新增/移除特定項目。

To delete an IPv4 access list, you can use one of the following commands.

若要刪除 IPv4 存取清單,可使用下列其中一個指令:

  • no access-list access-list numberno access-list access-list number
  • no ip access-list standard|extended access-list-nameno ip access-list standard|extended access-list-name

Both commands require you to specify the number or the name of the access list you wish to delete.

兩個指令都要求你指定欲刪除的存取清單編號或名稱。

Using numbered configuration method, you cannot add or remove individual statements directly. Instead, you would have to first copy the entire access list, modify it in the text editor, delete it from the configuration and enter the modified ACL statements.

使用編號式設定方式時,你無法直接新增或移除個別陳述式,而必須先複製整份存取清單、在文字編輯器中修改、從設定中刪除,再輸入修改後的 ACL 陳述式。

Because the show access-lists command displays ACL statements in the format different to the syntax used to configure them, it is more convenient to use the show running-config command when you want to edit the statements in an editor. In the running configuration file, the ACL statements are stored with the proper syntax, therefore they can be easily reused. To filter out only numbered access lists from the show running-config output, use the include and access-lists keywords.

由於 show access-lists 指令顯示 ACL 陳述式的格式與設定它們所用的語法不同,若想在編輯器中編輯陳述式,使用 show running-config 指令會更為方便。在執行中設定檔中,ACL 陳述式是以正確的語法儲存,因此可輕鬆重複使用。若要從 show running-config 輸出中只篩選出編號式存取清單,可使用 includeaccess-lists 關鍵字。

With named configuration method, modifying an ACL is significantly easier. Before you implement the modification, you need to know the sequence number of the statement you wish to add or remove. Modifications are implemented in the Named Access List configuration mode.

使用具名設定方式時,修改 ACL 會容易得多。在實施修改之前,你需要知道欲新增或移除陳述式的序號。修改是在具名存取清單設定模式中進行。

To add an entry from within Named Access List configuration mode, use one of the following commands, depending on whether you are modifying a standard or an extended access list:

若要在具名存取清單設定模式中新增項目,依你要修改的是標準或延伸存取清單,使用下列其中一個指令:

  • For the standard ACL use the [sequence-number] permit|deny source_matching_criteria command標準 ACL 使用 [sequence-number] permit|deny source_matching_criteria 指令
  • For the extended ACL use the [sequence-number] permit|deny protocol source_matching_criteria destination_matching_criteria command延伸 ACL 使用 [sequence-number] permit|deny protocol source_matching_criteria destination_matching_criteria 指令

When you choose the sequence number, you choose where the new entry will be placed in the ACL. You can use any number that is not currently assigned, even if it is not a multiple of 10.

選擇序號時,等於是選擇新項目在 ACL 中的放置位置。你可以使用任何目前尚未使用的編號,即使它不是 10 的倍數也可以。

For example, if you want to modify an existing access list 1 from the previous example with another specific host entry, you enter the following commands:

例如,若你想在前述範例的既有存取清單 1 中,加入另一個特定主機項目,可輸入以下指令:

RouterX(config)# ip access-list standard 1
RouterX(config-std-nacl)# 15 deny host 172.16.4.4

In this example you assigned number 15 to a new entry. An entry matching a single IPv4 address is more specific than an entry matching a subnet or a range of subnets, therefore it was added near the top of the ACL. The ACL entries are as follows:

在此範例中,你將編號 15 分配給了新項目。比對單一 IPv4 位址的項目比比對子網路或子網路範圍的項目更具體,因此它被加到了 ACL 的較前面位置。ACL 項目如下:

RouterX# show access-lists 1
Standard IP access list 1
 10 deny host 172.16.3.3
 15 deny host 172.16.4.4
 20 permit 172.16.0.0 0.0.255.255

Specific statements cannot be overwritten using the same sequence number as an existing statement. The current statement must be deleted first, and then the new one can be added.

無法使用與現有陳述式相同的序號來覆寫特定陳述式,必須先刪除目前的陳述式,才能新增新的陳述式。

To delete an entry, go to the Named Access List configuration mode. When deleting an entry for the numbered access list, use the ACL number as the name of the list you wish to modify. Again, you need to know the sequence number of the statement you wish to delete. To delete a statement, use the command no sequence-number.

若要刪除項目,請進入具名存取清單設定模式。在刪除編號式存取清單的項目時,請使用 ACL 編號作為你要修改的清單名稱。同樣地,你需要知道欲刪除陳述式的序號。若要刪除陳述式,請使用指令 no sequence-number。

Note that a reload will resequence numbers in the ACL so that all numbers are multiples of 10. To initiate resequencing on your own and avoid reloading, use the access-list ACL name resequence command.

請注意,重新載入會將 ACL 中的編號重新排序,使所有編號都成為 10 的倍數。若要自行啟動重新排序而不需要重新載入,可使用 access-list ACL name resequence 指令。

After modifying an access list, verify the changes using the show access-lists command.

修改存取清單後,請使用 show access-lists 指令驗證變更。

Which statement describes the named configuration method?下列哪一項敘述描述了具名設定方式?