คู่มือครอบคลุมการตั้งค่า VLAN บนสวิตช์ Cisco
ในสถาปัตยกรรมของเครือข่ายองค์กรสมัยใหม่ Virtual Local Area Networks (VLANs) ไม่ใช่เพียงความสะดวกเท่านั้น แต่เป็นเสาหลังที่สำคัญของความปลอดภัย ประสิทธิภาพ และหลักการจัดระเบียบ โดยการแบ่งสวิตช์กายภาพเดียวออกเป็นหลายเครือข่ายทางตรรกะ วิศวกรสามารถแยกโดเมนการกระจายสัญญาณ ปกป้องข้อมูลที่ละเอียดอ่อน และจัดการการจราจัยได้อย่างมีประสิทธิภาพ คู่มือนี้ให้คำแนะนำที่ละเอียดอ่อนและครบถ้วนทีละขั้นตอนสำหรับการตั้งค่า ยืนยัน และจัดการ VLANs บนสวิตช์ที่ใช้ Cisco IOS ซึ่งออกแบบมาสำหรับผู้เชี่ยวชาญด้านเครือข่ายที่ต้องการความแม่นยำและการปฏิบัติตามแนวที่ดีที่สุด.
1. การเข้าใจแนวคิด VLAN
ก่อนดำเนินการคำสั่ง การเข้าใจกลไกเป็นสิ่งสำคัญ VLAN จะทำการแท็กเฟรม Ethernet ด้วยตัวระบุ (ID) 802.1Q ซึ่งช่วยให้สวิตช์สามารถแยกแยะกระแสการจราจัยได้ พอร์ตบนสวิตช์มักถูกกำหนดให้อยู่ในโหมดหนึ่งในสองโหมดดังนี้:
- พอร์ตการเข้าถึง (Access Ports): เชื่อมต่ออุปกรณ์ปลายทาง (PC, เครื่องพิมพ์) และถือครองการจราจัยสำหรับ VLAN เดียว เมื่อเฟรมออกจากพอร์ตไปยังอุปกรณ์ จะไม่มีการแท็ก.
- พอร์ตทรังก์ (Trunk Ports): เชื่อมต่อสวิตช์กับสวิตช์หรือรายอื่น พวกมันถือครองการจราจัยสำหรับหลาย VLAN และรักษาแท็ก 802.1Q เพื่อระบุเจ้าของเฟรม.
2. การสร้างและตั้งชื่อ VLANs
ขั้นตอนแรกในการแบ่งส่วนคือการกำหนด VLANs ในฐานข้อมูลของสวิตช์ ในขณะที่ VLAN ID สามารถอยู่ในช่วง 1 ถึง 4094 ได้ ช่วงมาตรฐาน (1-1005) คือที่ใช้กันมากที่สุด.
Switch# configure terminal Switch(config)# vlan 10 Switch(config-vlan)# name DATA_NETWORK Switch(config-vlan)# exit Switch(config)# vlan 20 Switch(config-vlan)# name VOICE_NETWORK Switch(config-vlan)# exit Switch(config)# vlan 99 Switch(config-vlan)# name MANAGEMENT Switch(config-vlan)# end
แนวที่ดีที่สุด: ตั้งชื่อ VLANs ของคุณเสมอ ในสภาพแวดล้อมที่ซับซ้อน การเห็น “VLAN 20” น้อยกว่าการเห็น “VOICE_NETWORK” มากในระหว่างการแก้ปัญหา.
3. การกำหนดพอร์ตให้กับ VLANs (โหมดการเข้าถึง)
เมื่อ VLANs มีอยู่แล้ว อินเตอร์เฟซกายภาพต้องถูกกำหนดให้กับพวกมือ การตั้งค่านี้บอกสวิตช์ว่าการจราจัยใดๆ ที่เข้าสู่พอร์ตเฉพาะจะเป็นของ VLAN เฉพาะ.
การตั้งค่าอินเตอร์เฟ�์เดียว:
Switch(config)# interface GigabitEthernet0/1 Switch(config-if)# description Connection to HR_PC_01 Switch(config-if)# switchport mode access Switch(config-if)# switchport access vlan 10 Switch(config-if)# no shutdown
การตั้งค่าช่วงของอินเตอร์เฟซ:
Switch(config)# interface range GigabitEthernet0/2 - 10 Switch(config-if-range)# description HR_Department_PCs Switch(config-if-range)# switchport mode access Switch(config-if-range)# switchport access vlan 10
4. การตั้งค่าลิงก์ทรังก์ (การเชื่อมต่ะระหว่างสวิตช์)
เพื่อให้การจราจัยสามารถผ่านระหว่างสวิตช์ได้ คุณต้องตั้งค่าลิงก์ทรังก์ ลิงก์เหล่านี้จะถือครองเฟรมที่ถูกแท็ก การตั้งค่า VLAN ดั้งเดิม (การจราจัยที่ยังคงไม่มีแท็ก) เป็นสิ่งอื่นนอกเหนือจาก VLAN 1 ดั้งเดิมเพื่อวัตถุประสงค์ด้านความปลอดภัยเป็นสิ่งสำคัญ.
Switch(config)# interface GigabitEthernet0/24
Switch(config-if)# description Uplink_to_Core_Switch
Switch(config-if)# switchport trunk encapsulation dot1q
Switch(config-if)# switchport mode trunk
Switch(config-if)# switchport trunk native vlan 99
Switch(config-if)# switchport trunk allowed vlan 10,20,99
Note: The command `switchport trunk encapsulation dot1q` may not be required on newer switches that only support 802.1Q, but it is mandatory on older models that also supported ISL.
5. Configuring Voice VLANs
In environments with IP phones, a single port often supports both a PC and a phone. Cisco switches use a specialized feature called “Voice VLAN” to handle this via a mini-trunk.
Switch(config)# interface GigabitEthernet0/5
Switch(config-if)# description PC_and_Phone
Switch(config-if)# switchport mode access
Switch(config-if)# switchport access vlan 10
Switch(config-if)# switchport voice vlan 20
Switch(config-if)# trust device cisco-phone
This configuration places data traffic in VLAN 10 (untagged) and voice traffic in VLAN 20 (tagged), ensuring Quality of Service (QoS) separation.
6. Verification and Troubleshooting
Configuration is only half the job; verification ensures stability. Use the following commands to validate your setup.
Verify VLAN Database
Ensure your VLANs are active and named correctly.
Switch# show vlan brief
VLAN Name Status Ports
---- -------------------------------- --------- -------------------------------
1 default active Gi0/11, Gi0/12...
10 DATA_NETWORK active Gi0/1, Gi0/2...
20 VOICE_NETWORK active Gi0/5
99 MANAGEMENT active
Verify Interface Assignments
Check the administrative and operational mode of specific ports.
Switch# show interfaces switchport
Name: Gi0/1
Switchport: Enabled
Administrative Mode: static access
Operational Mode: static access
Access Mode VLAN: 10 (DATA_NETWORK)
Trunking Native Mode VLAN: 1 (default)
...
Verify Trunk Links
Confirm which ports are trunking and which VLANs are allowed across them.
Switch# show interfaces trunk
Port Mode Encapsulation Status Native vlan
Gi0/24 on 802.1q trunking 99
Port Vlans allowed on trunk
Gi0/24 10,20,99
7. Security Best Practices: VLAN Hopping Mitigation
Default configurations are often insecure. Attackers can exploit Dynamic Trunking Protocol (DTP) to hop between VLANs. Secure your ports with these standard hardening steps:
- Disable DTP on Access Ports: By hard-coding `switchport mode access`, you prevent the port from negotiating a trunk link.
- Shutdown Unused Ports: Any port not in use should be administratively down and assigned to a “black hole” VLAN (a VLAN with no Layer 3 access).
- Disable DTP Globally (Optional but Recommended): Use `switchport nonegotiate` on trunk links to stop DTP frames.
Switch(config)# interface GigabitEthernet0/24
Switch(config-if)# switchport nonegotiate
บทสรุป
Effective VLAN management is the bedrock of a stable network infrastructure. By strictly adhering to naming conventions, properly configuring trunk and access modes, and implementing security controls against VLAN hopping, network engineers ensure a scalable and secure environment. Regular auditing using verification commands is essential to maintaining configuration integrity over time.
วอทส์แอป+8613603031172