
ACL (Access Control List) คืออะไร?
Access Control List (ACL) คือ ชุดกฎ (Rules) ที่กำหนดว่า Traffic ไหน อนุญาต (Permit) และ Traffic ไหน ปฏิเสธ (Deny) ให้ผ่านเข้า-ออก Interface ของ Router หรือ Switch ได้ ACL เป็นเครื่องมือพื้นฐานที่สุดสำหรับ Network Security ที่ทุก Network Engineer ต้องเข้าใจ
ACL ทำหน้าที่เหมือน Security Guard ที่ยืนหน้าประตู ตรวจสอบ Packet ทุกตัวที่ผ่าน ถ้าตรงกับกฎที่อนุญาตก็ปล่อยผ่าน ถ้าตรงกับกฎที่ปฏิเสธก็บล็อก
ACL ใช้ทำอะไรได้บ้าง?
- Traffic Filtering: บล็อก/อนุญาต Traffic ตาม Source IP, Destination IP, Port, Protocol
- VTY Access Control: จำกัดว่า IP ไหน SSH/Telnet เข้า Router ได้
- NAT (Network Address Translation): กำหนดว่า IP ไหนผ่าน NAT ได้
- Route Filtering: ควบคุมว่า Route ไหนจะ Advertise ใน Routing Protocol
- QoS (Quality of Service): จำแนก Traffic เพื่อกำหนด Priority
- VPN Crypto Map: กำหนด Traffic ที่จะเข้ารหัสผ่าน VPN
ACL Logic — หลักการทำงาน
Permit / Deny
ทุก ACL Entry (ACE) จะเป็น permit (อนุญาต) หรือ deny (ปฏิเสธ):
! ตัวอย่าง ACL Entry
permit 192.168.1.0 0.0.0.255 ! อนุญาต Traffic จาก 192.168.1.0/24
deny 10.0.0.0 0.255.255.255 ! บล็อก Traffic จาก 10.0.0.0/8
Top-Down Processing
ACL ประมวลผล จากบนลงล่าง ตามลำดับ เมื่อ Packet ตรงกับ Entry ใดก็ Execute ทันที ไม่ตรวจ Entry ถัดไป:
! ACL ทำงานเหมือน if-elif-else
! Entry 10: permit 192.168.1.10 → ถ้าตรง → permit ทันที → หยุด
! Entry 20: deny 192.168.1.0/24 → ถ้าตรง → deny ทันที → หยุด
! Entry 30: permit any → ถ้าตรง → permit ทันที → หยุด
! (implicit deny any) → ถ้าไม่ตรงอะไรเลย → deny
Implicit Deny Any (สำคัญมาก!)
ทุก ACL มี กฎซ่อน อยู่บรรทัดสุดท้าย คือ deny any หมายความว่า ถ้า Packet ไม่ตรงกับ Entry ใดเลย จะถูก Deny ทั้งหมด นี่คือ Gotcha ที่ทำให้มือใหม่พลาดบ่อยที่สุด:
! ACL นี้ ตั้งใจจะ Block 10.0.0.0/8
access-list 10 deny 10.0.0.0 0.255.255.255
! แต่เพราะ implicit deny any อยู่ท้าย
! ทุก Traffic ที่ไม่ใช่ 10.0.0.0/8 ก็ถูก Deny ด้วย!
! ต้องเพิ่ม:
access-list 10 permit any
Wildcard Mask
ACL ใช้ Wildcard Mask แทน Subnet Mask โดย Wildcard Mask คือ ตรงข้าม ของ Subnet Mask:
| Subnet Mask | Wildcard Mask | ความหมาย | CIDR |
|---|---|---|---|
| 255.255.255.255 | 0.0.0.0 | Match IP เดียว (Host) | /32 |
| 255.255.255.0 | 0.0.0.255 | Match ทั้ง Subnet /24 | /24 |
| 255.255.0.0 | 0.0.255.255 | Match ทั้ง Subnet /16 | /16 |
| 255.0.0.0 | 0.255.255.255 | Match ทั้ง Subnet /8 | /8 |
| 0.0.0.0 | 255.255.255.255 | Match ทุก IP (any) | /0 |
! วิธีคำนวณ Wildcard Mask
! Wildcard = 255.255.255.255 - Subnet Mask
! เช่น Subnet /24 = 255.255.255.0
! Wildcard = 255.255.255.255 - 255.255.255.0 = 0.0.0.255
! Shortcut ใน Cisco IOS
! "host 192.168.1.10" = "192.168.1.10 0.0.0.0"
! "any" = "0.0.0.0 255.255.255.255"
Standard ACL vs Extended ACL
| คุณสมบัติ | Standard ACL | Extended ACL |
|---|---|---|
| Number Range | 1-99, 1300-1999 | 100-199, 2000-2699 |
| Filter ตาม | Source IP เท่านั้น | Source IP, Dest IP, Port, Protocol |
| ตำแหน่งที่ Apply | ใกล้ Destination | ใกล้ Source |
| ความยืดหยุ่น | น้อย | มาก |
| ใช้เมื่อ | Block ทั้ง Subnet | Block เฉพาะ Port/Protocol |
Numbered ACL vs Named ACL
| คุณสมบัติ | Numbered ACL | Named ACL |
|---|---|---|
| ตัวอย่าง | access-list 10 … | ip access-list standard MY_ACL |
| แก้ไข/ลบบรรทัดเดียว | ทำไม่ได้ (ต้องลบทั้ง ACL) | ทำได้ (ใช้ sequence number) |
| อ่านง่าย | ต้องจำ Number | ตั้งชื่อสื่อความหมาย |
| แนะนำใช้ | Lab/ทดสอบ | Production |
เขียน Standard ACL
Numbered Standard ACL
! Scenario: อนุญาตเฉพาะ 192.168.1.0/24 เข้าถึง Server
! Block ทุก Network อื่น
! สร้าง ACL
access-list 10 permit 192.168.1.0 0.0.0.255
! implicit deny any (ซ่อนอยู่)
! Apply บน Interface (ใกล้ Destination)
interface GigabitEthernet0/1
ip access-group 10 in
Named Standard ACL
! สร้าง Named ACL
ip access-list standard ALLOW_OFFICE
10 permit 192.168.1.0 0.0.0.255
20 permit 192.168.2.0 0.0.0.255
30 deny any log
! Apply
interface GigabitEthernet0/1
ip access-group ALLOW_OFFICE in
! แก้ไข — เพิ่ม Entry ระหว่างบรรทัด
ip access-list standard ALLOW_OFFICE
15 permit host 10.0.0.50
! ลบ Entry เดียว
ip access-list standard ALLOW_OFFICE
no 15
เขียน Extended ACL
Syntax ของ Extended ACL
! Extended ACL Syntax:
! access-list {number} {permit|deny} {protocol} {source} {wildcard} {dest} {wildcard} [eq port]
!
! Protocol: ip, tcp, udp, icmp, eigrp, ospf, gre, etc.
! Port: 80(HTTP), 443(HTTPS), 22(SSH), 23(Telnet), 53(DNS), 25(SMTP), etc.
ตัวอย่าง Extended ACL
! Scenario 1: อนุญาต HTTP/HTTPS จาก LAN ไป Internet
access-list 100 permit tcp 192.168.1.0 0.0.0.255 any eq 80
access-list 100 permit tcp 192.168.1.0 0.0.0.255 any eq 443
access-list 100 permit udp 192.168.1.0 0.0.0.255 any eq 53
access-list 100 deny ip any any log
interface GigabitEthernet0/0
ip access-group 100 in
! Scenario 2: Block SSH ไปยัง Server 10.1.1.100 จากทุกที่ ยกเว้น Admin
access-list 101 permit tcp host 192.168.1.10 host 10.1.1.100 eq 22
access-list 101 deny tcp any host 10.1.1.100 eq 22
access-list 101 permit ip any any
! Scenario 3: Block Ping (ICMP) จาก Network หนึ่ง
access-list 102 deny icmp 10.0.0.0 0.255.255.255 any
access-list 102 permit ip any any
Named Extended ACL
! Named Extended ACL (แนะนำสำหรับ Production)
ip access-list extended WEB_SERVER_ACCESS
10 permit tcp any host 10.1.1.100 eq 80
20 permit tcp any host 10.1.1.100 eq 443
30 permit tcp host 192.168.1.10 host 10.1.1.100 eq 22
40 deny ip any host 10.1.1.100 log
50 permit ip any any
interface GigabitEthernet0/1
ip access-group WEB_SERVER_ACCESS in
Apply ACL — In vs Out บน Interface
ACL สามารถ Apply ได้ 2 ทิศทางบน Interface:
| ทิศทาง | ความหมาย | ตรวจสอบเมื่อ |
|---|---|---|
| in (Inbound) | ตรวจ Traffic ที่เข้ามาทาง Interface นี้ | Packet เข้า Interface → ตรวจ ACL → Route |
| out (Outbound) | ตรวจ Traffic ที่ออกไปทาง Interface นี้ | Route → ตรวจ ACL → ส่ง Packet ออก Interface |
! Apply ACL ขาเข้า (แนะนำ — Block เร็ว ลด Processing)
interface GigabitEthernet0/0
ip access-group 100 in
! Apply ACL ขาออก
interface GigabitEthernet0/1
ip access-group 101 out
! กฎ: Interface หนึ่งมี ACL ได้สูงสุด
! 1 inbound ACL + 1 outbound ACL ต่อ 1 Protocol (IPv4/IPv6)
ตำแหน่งที่ควร Apply ACL
! Standard ACL → Apply ใกล้ Destination
! เพราะ Standard ACL ดูแค่ Source IP
! ถ้า Apply ใกล้ Source จะ Block Traffic ไปทุกที่
! Extended ACL → Apply ใกล้ Source
! เพราะ Extended ACL ดูทั้ง Source + Dest + Port
! Block ที่ต้นทางเร็วกว่า ไม่ต้องเสีย Bandwidth
! ตัวอย่าง Network:
! PC (192.168.1.0/24) → R1 → R2 → R3 → Server (10.1.1.100)
!
! Standard ACL block 192.168.1.0 → Apply ที่ R3 (ใกล้ Server)
! Extended ACL block 192.168.1.0 ไปยัง 10.1.1.100 port 80 → Apply ที่ R1 (ใกล้ PC)
ACL สำหรับ VTY Access Control
จำกัดว่า IP ไหน SSH/Telnet เข้า Router ได้:
! สร้าง ACL สำหรับ VTY
ip access-list standard VTY_ACCESS
permit 192.168.1.0 0.0.0.255
permit host 10.0.0.50
deny any log
! Apply บน VTY Lines
line vty 0 15
access-class VTY_ACCESS in
transport input ssh
login local
! ทดสอบ: SSH จาก IP ที่อนุญาต → สำเร็จ
! SSH จาก IP อื่น → Connection refused
ACL สำหรับ NAT
! กำหนด ACL ว่า IP ไหนผ่าน NAT ได้
access-list 1 permit 192.168.1.0 0.0.0.255
access-list 1 permit 192.168.2.0 0.0.0.255
! NAT Overload (PAT)
ip nat inside source list 1 interface GigabitEthernet0/0 overload
! กำหนด Inside/Outside Interface
interface GigabitEthernet0/0
ip nat outside
interface GigabitEthernet0/1
ip nat inside
ACL สำหรับ Route Filtering
! ใช้ ACL ควบคุม Route ที่ Advertise ใน OSPF
access-list 20 permit 192.168.0.0 0.0.255.255
access-list 20 deny any
router ospf 1
distribute-list 20 out
! ใช้กับ EIGRP
router eigrp 100
distribute-list 20 out GigabitEthernet0/0
! ใช้กับ BGP
router bgp 65001
neighbor 203.0.113.1 distribute-list 20 out
ACL Debugging — ตรวจสอบ ACL
! ดู ACL ทั้งหมด
show access-lists
show ip access-lists
! ตัวอย่าง Output:
! Extended IP access list WEB_SERVER_ACCESS
! 10 permit tcp any host 10.1.1.100 eq www (1205 matches)
! 20 permit tcp any host 10.1.1.100 eq 443 (3821 matches)
! 30 permit tcp host 192.168.1.10 host 10.1.1.100 eq 22 (45 matches)
! 40 deny ip any host 10.1.1.100 log (12 matches)
! 50 permit ip any any (98432 matches)
! ดู ACL ที่ Apply บน Interface
show ip interface GigabitEthernet0/0 | include access
! ใช้ log keyword เพื่อดู Traffic ที่โดน ACL
! (เพิ่ม log ท้าย Entry)
access-list 100 deny ip 10.0.0.0 0.255.255.255 any log
! ดู Log
show logging | include %SEC-6-IPACCESSLOG
! Clear ACL Counters (เริ่มนับใหม่)
clear access-list counters 100
Time-Based ACL
ACL ที่ทำงานเฉพาะช่วงเวลาที่กำหนด:
! สร้าง Time Range
time-range BUSINESS_HOURS
periodic weekdays 08:00 to 18:00
time-range LUNCH_TIME
periodic weekdays 12:00 to 13:00
! ใช้ Time Range กับ ACL
ip access-list extended OFFICE_POLICY
! อนุญาต Social Media เฉพาะเวลาพักกลางวัน
10 permit tcp 192.168.1.0 0.0.0.255 any eq 443 time-range LUNCH_TIME
! อนุญาต Business traffic ตลอดเวลาทำงาน
20 permit tcp 192.168.1.0 0.0.0.255 any eq 80 time-range BUSINESS_HOURS
30 permit tcp 192.168.1.0 0.0.0.255 any eq 443 time-range BUSINESS_HOURS
40 permit udp 192.168.1.0 0.0.0.255 any eq 53
50 deny ip any any log
! ตรวจสอบ Time Range
show time-range
Reflexive ACL — Dynamic Stateful ACL
Reflexive ACL ช่วยให้ Router อนุญาต Return traffic อัตโนมัติ เมื่อมี Outbound connection:
! สร้าง Outbound ACL พร้อม Reflect
ip access-list extended OUTBOUND
permit tcp 192.168.1.0 0.0.0.255 any reflect TCP_TRAFFIC timeout 300
permit udp 192.168.1.0 0.0.0.255 any reflect UDP_TRAFFIC timeout 60
permit icmp 192.168.1.0 0.0.0.255 any reflect ICMP_TRAFFIC timeout 10
deny ip any any log
! สร้าง Inbound ACL ที่ Evaluate Reflected traffic
ip access-list extended INBOUND
evaluate TCP_TRAFFIC
evaluate UDP_TRAFFIC
evaluate ICMP_TRAFFIC
deny ip any any log
! Apply
interface GigabitEthernet0/0
ip access-group OUTBOUND out
ip access-group INBOUND in
! วิธีทำงาน:
! 1. PC ส่ง HTTP request ออกไป → ตรงกับ reflect rule
! 2. Router สร้าง dynamic entry สำหรับ return traffic
! 3. HTTP response กลับมา → ตรงกับ dynamic entry → permit
! 4. หลัง timeout → dynamic entry หายไป
ACL Best Practices
| ข้อ | Best Practice | เหตุผล |
|---|---|---|
| 1 | ใช้ Named ACL เสมอ | อ่านง่าย แก้ไขง่าย ลบทีละ Entry ได้ |
| 2 | เรียง Specific → General | กฎเฉพาะก่อน กฎกว้างทีหลัง |
| 3 | เพิ่ม permit any (ถ้าต้องการ) | ป้องกัน implicit deny block ทุกอย่าง |
| 4 | ใส่ log ใน deny entry | เห็น Traffic ที่โดน Block เพื่อ Troubleshoot |
| 5 | ใช้ remark อธิบาย | คนอื่นในทีม (หรือตัวเอง) อ่านเข้าใจ |
| 6 | Test ใน Lab ก่อน Production | ACL ผิดทำให้ Network ล่มทั้งหมด |
| 7 | เว้นช่อง Sequence number | เช่น 10, 20, 30 เพื่อแทรก Entry ได้ |
| 8 | Standard ACL ใกล้ Destination | ไม่ Block Traffic ไปที่อื่นโดยไม่ตั้งใจ |
| 9 | Extended ACL ใกล้ Source | Block เร็ว ประหยัด Bandwidth |
| 10 | Document ทุก ACL | ACL ที่ไม่มี Comment คืออันตราย |
! ตัวอย่าง ACL ที่มี remark
ip access-list extended PRODUCTION_FIREWALL
remark === Allow Admin SSH ===
10 permit tcp 192.168.100.0 0.0.0.255 any eq 22
remark === Allow Web Traffic ===
20 permit tcp any any eq 80
30 permit tcp any any eq 443
remark === Allow DNS ===
40 permit udp any any eq 53
remark === Allow ICMP for Troubleshooting ===
50 permit icmp any any echo
60 permit icmp any any echo-reply
remark === Deny and Log Everything Else ===
999 deny ip any any log
ACL vs Firewall Rules
| คุณสมบัติ | Router ACL | Firewall (Stateful) |
|---|---|---|
| Stateful Inspection | ไม่มี (Stateless) * | มี (Track Session) |
| Application Layer | ดูแค่ L3/L4 | ดูถึง L7 (DPI) |
| Logging | พื้นฐาน | Detail + Dashboard |
| Performance | เร็วมาก (Hardware ASIC) | ช้ากว่า (Software) |
| ใช้เมื่อ | Basic filtering, Inter-VLAN | Perimeter security, DMZ |
| ราคา | มีอยู่แล้วใน Router | ต้องซื้อเพิ่ม |
* Reflexive ACL เป็น Semi-stateful แต่ไม่ดีเท่า Firewall จริง
IPv6 ACL
! IPv6 ACL ใช้ Named ACL เท่านั้น (ไม่มี Numbered)
ipv6 access-list IPv6_WEB_ACCESS
permit tcp any host 2001:db8::100 eq 80
permit tcp any host 2001:db8::100 eq 443
permit icmp any any nd-na ! Neighbor Discovery
permit icmp any any nd-ns ! Neighbor Solicitation
deny ipv6 any any log
! Apply
interface GigabitEthernet0/1
ipv6 traffic-filter IPv6_WEB_ACCESS in
! ตรวจสอบ
show ipv6 access-list
ข้อแตกต่างจาก IPv4 ACL:
- ใช้ Named ACL เท่านั้น
- ไม่ใช้ Wildcard Mask แต่ใช้ Prefix Length (เช่น 2001:db8::/32)
- ต้องอนุญาต ICMPv6 ND-NA/ND-NS เสมอ (ถ้าไม่มีจะ Network ใช้ไม่ได้)
- Apply ด้วย
ipv6 traffic-filterแทนip access-group
สรุป — Network ACL 2026
Access Control List (ACL) เป็นเครื่องมือพื้นฐานที่ Network Engineer ทุกคนต้องเชี่ยวชาญ เข้าใจ Implicit deny any, Wildcard Mask, Standard vs Extended, In vs Out แล้วคุณจะเขียน ACL ได้อย่างมั่นใจ ใช้ Named ACL เสมอใน Production เพิ่ม remark ทุก Section และ Test ใน Lab ก่อนทุกครั้ง
ACL ไม่ใช่ Firewall ทดแทนกันไม่ได้ แต่ ACL บน Router คือ First line of defense ที่เร็วและมีประสิทธิภาพสูง ใช้ ACL สำหรับ Basic filtering และ Firewall สำหรับ Advanced security เพื่อ Defense in Depth ที่แข็งแกร่ง