An Access Control List (ACL) consists of one rule or a set of rules that describe the packet matching conditions. These conditions include source addresses, destination addresses, and port numbers of packets.
An ACL filters packets based on rules. A device with an ACL configured matches packets based on the rules to obtain the packets of a certain type, and then decides to forward or discard these packets according to the policies used by the service module to which the ACL is applied.
Depending on the rule definition methods, ACLs include basic ACL, advanced ACL, and Layer 2 ACL. An advanced ACL defines rules to filter IPv4 packets based on source IP addresses, destination addresses, IP protocol types, TCP source/destination port numbers, UDP source/destination port numbers, fragment information, and time ranges. Compared with a basic ACL, an advanced ACL is more accurate, flexible, and provides more functions. For example, if you want to filter packets based on source and destination IP addresses, configure an advanced ACL.
In this example, advanced ACLs are applied to the traffic policy module so that the device can filter the packets between different network segments and thus restrict mutual access between network segments.
This example applies to all versions and models.
The following commands and output information are obtained from S7712 running V200R007C00.
As shown in Figure 1, the departments of an enterprise are connected through the Switch. To facilitate network management, the administrator allocates the IP addresses on two network segments to the R&D and marketing departments respectively. The two departments belong to different VLANs. The mutual access between two network segments must be controlled to ensure information security.
The following configurations are performed on the Switch. The configuration roadmap is as follows:
# Create VLAN 10 and VLAN 20.
<HUAWEI> system-view [HUAWEI] sysname Switch [Switch] vlan batch 10 20
# Configure GE 1/0/1 and GE1/0/2 of the Switch as trunk interfaces and add them to VLAN 10 and VLAN 20 respectively.
[Switch] interface gigabitethernet 1/0/1 [Switch-GigabitEthernet1/0/1] port link-type trunk [Switch-GigabitEthernet1/0/1] port trunk allow-pass vlan 10 [Switch-GigabitEthernet1/0/1] quit [Switch] interface gigabitethernet 1/0/2 [Switch-GigabitEthernet1/0/2] port link-type trunk [Switch-GigabitEthernet1/0/2] port trunk allow-pass vlan 20 [Switch-GigabitEthernet1/0/2] quit
# Create VLANIF 10 and VLANIF 20 and assign IP addresses to them.
[Switch] interface vlanif 10 [Switch-Vlanif10] ip address 10.1.1.1 24 [Switch-Vlanif10] quit [Switch] interface vlanif 20 [Switch-Vlanif20] ip address 10.1.2.1 24 [Switch-Vlanif20] quit
# Create advanced ACL 3001 and configure rules for the ACL to block the packets from the R&D department to the marketing department.
[Switch] acl 3001 [Switch-acl-adv-3001] rule deny ip source 10.1.1.0 0.0.0.255 destination 10.1.2.0 0.0.0.255 //Prevent the R&D department from accessing the marketing department. [Switch-acl-adv-3001] quit
# Create advanced ACL 3002 and configure rules for the ACL to block the packets from the marketing department to the R&D department.
[Switch] acl 3002 [Switch-acl-adv-3002] rule deny ip source 10.1.2.0 0.0.0.255 destination 10.1.1.0 0.0.0.255 //Prevent the marketing department from accessing the R&D department. [Switch-acl-adv-3002] quit
# Configure the traffic classifier tc1 to classify packets that match ACL 3001 and ACL 3002.
[Switch] traffic classifier tc1 //Create a traffic classifier. [Switch-classifier-tc1] if-match acl 3001 //Associate an ACL with the traffic classifier. [Switch-classifier-tc1] if-match acl 3002 //Associate an ACL with the traffic classifier. [Switch-classifier-tc1] quit
# Configure the traffic behavior tb1 to reject packets.
[Switch] traffic behavior tb1 //Create a traffic behavior. [Switch-behavior-tb1] deny //Set the action of the traffic behavior to deny. [Switch-behavior-tb1] quit
# Define the traffic policy and associate the traffic classifier and traffic behavior with the traffic policy.
[Switch] traffic policy tp1 //Create a traffic policy. [Switch-trafficpolicy-tp1] classifier tc1 behavior tb1 //Associate the traffic classifier tc1 with the traffic behavior tb1. [Switch-trafficpolicy-tp1] quit
# The packets from the R&D and marketing departments are received by GE1/0/1 and GE1/0/2 respectively; therefore, apply the traffic policy to the inbound direction of GE1/0/1 and GE1/0/2.
[Switch] interface gigabitethernet 1/0/1 [Switch-GigabitEthernet1/0/1] traffic-policy tp1 inbound //Apply the traffic policy to the inbound direction of an interface. [Switch-GigabitEthernet1/0/1] quit [Switch] interface gigabitethernet 1/0/2 [Switch-GigabitEthernet1/0/2] traffic-policy tp1 inbound //Apply the traffic policy to the inbound direction of an interface. [Switch-GigabitEthernet1/0/2] quit
# Check the configuration of ACL rules.
[Switch] display acl 3001
Advanced ACL 3001, 1 rule
Acl's step is 5
rule 5 deny ip source 10.1.1.0 0.0.0.255 destination 10.1.2.0 0.0.0.255 (match-counter 0)
[Switch] display acl 3002
Advanced ACL 3002, 1 rule
Acl's step is 5
rule 5 deny ip source 10.1.2.0 0.0.0.255 destination 10.1.1.0 0.0.0.255 (match-counter 0)
# Check the configuration of the traffic classifier.
[Switch] display traffic classifier user-defined
User Defined Classifier Information:
Classifier: tc1
Precedence: 5
Operator: OR
Rule(s) : if-match acl 3001
if-match acl 3002
Total classifier number is 1
# Check the configuration of the traffic policy.
[Switch] display traffic policy user-defined tp1 User Defined Traffic Policy Information: Policy: tp1 Classifier: tc1 Operator: OR Behavior: tb1 Deny
# The network segments where the R&D and marketing departments reside cannot access each other, but they can access the network segments of other departments.
Configuration file of the Switch
# sysname Switch # vlan batch 10 20 # acl number 3001 rule 5 deny ip source 10.1.1.0 0.0.0.255 destination 10.1.2.0 0.0.0.255 acl number 3002 rule 5 deny ip source 10.1.2.0 0.0.0.255 destination 10.1.1.0 0.0.0.255 # traffic classifier tc1 operator or precedence 5 if-match acl 3001 if-match acl 3002 # traffic behavior tb1 deny # traffic policy tp1 match-order config classifier tc1 behavior tb1 # interface Vlanif10 ip address 10.1.1.1 255.255.255.0 # interface Vlanif20 ip address 10.1.2.1 255.255.255.0 # interface GigabitEthernet1/0/1 port link-type trunk port trunk allow-pass vlan 10 traffic-policy tp1 inbound # interface GigabitEthernet1/0/2 port link-type trunk port trunk allow-pass vlan 20 traffic-policy tp1 inbound # return