Techerest

Network Addressing Design: IPv4 Subnetting, VLSM และ VLAN

Network Addressing Design เป็นพื้นฐานสำคัญของ Enterprise Network เพราะการแบ่ง IPv4 Subnet, การใช้ VLSM (Variable Length Subnet Mask) และการกำหนด VLAN ที่เป็นระบบ ช่วยลดการใช้ IP Address โดยไม่จำเป็น เพิ่มความชัดเจนของ Routing และทำให้การขยายเครือข่ายในอนาคตง่ายขึ้น

บทความนี้อธิบายตั้งแต่การคำนวณ CIDR ไปจนถึงการออกแบบ Address Plan สำหรับสำนักงานใหญ่และสาขา พร้อมตัวอย่าง Cisco IOS/IOS XE, วิธีตรวจสอบ และข้อผิดพลาดที่พบจริง

1. IPv4 Addressing และ CIDR คืออะไร?

IPv4 Address มีขนาด 32 บิต เช่น 10.20.30.10 ส่วน CIDR Prefix เช่น /24 ระบุจำนวนบิตที่ใช้เป็น Network Prefix โดยบิตที่เหลือเป็น Host Portion

10.20.30.10/24
Subnet Mask: 255.255.255.0
Network:     10.20.30.0
Broadcast:   10.20.30.255
Usable:      10.20.30.1 - 10.20.30.254

ใน IPv4 Subnet ทั่วไป จำนวน Address เท่ากับ 2^(32-prefix) และจำนวน Usable Host มักเท่ากับจำนวนทั้งหมดลบ 2 เพื่อกัน Network และ Broadcast Address ข้อยกเว้นสำคัญคือ /31 สำหรับ Point-to-Point Link ตาม RFC 3021 และ /32 สำหรับ Single Host Route

PrefixSubnet MaskAddressesUsable Hosts (ทั่วไป)
/22255.255.252.01,0241,022
/23255.255.254.0512510
/24255.255.255.0256254
/25255.255.255.128128126
/26255.255.255.1926462
/27255.255.255.2243230
/28255.255.255.2401614
/29255.255.255.24886
/30255.255.255.25242

2. วิธีคำนวณ Subnet อย่างเป็นระบบ

Step 1 — กำหนดจำนวน Host ที่ต้องรองรับ

สมมติ VLAN หนึ่งต้องรองรับ 50 Devices ให้เลือกจำนวน Host Bits ที่ทำให้ 2^h - 2 >= 50 ดังนั้น h = 6 และ Prefix = 32 - 6 = /26

Step 2 — ตรวจ Subnet Boundary

/26 มี Block Size 64 Addresses ตัวอย่างภายใน 192.168.10.0/24 คือ:

192.168.10.0/26      .0   - .63
192.168.10.64/26     .64  - .127
192.168.10.128/26    .128 - .191
192.168.10.192/26    .192 - .255

Step 3 — แยก Network, Gateway และ Broadcast

Subnet:      192.168.10.64/26
Network:     192.168.10.64
Gateway:     192.168.10.65  (Design Choice)
Usable:      192.168.10.65 - 192.168.10.126
Broadcast:   192.168.10.127

Default Gateway ไม่จำเป็นต้องเป็น IP แรกเสมอไป แต่ควรกำหนด Convention ให้สม่ำเสมอ

3. VLSM คืออะไร และทำไมต้องใช้?

VLSM คือการใช้ Subnet Mask หลายขนาดภายใน Address Block เดียวกัน เพื่อให้แต่ละ Network ได้ Address Space เหมาะกับจำนวน Host แทนการแบ่งทุก VLAN เป็น /24 เท่ากัน

10.40.0.0/22
    |
    +-- User VLAN      /24
    +-- Wi-Fi VLAN     /25
    +-- Server VLAN    /26
    +-- Management     /27
    +-- Point-to-Point /31

ข้อดีคือ ลด Address Waste, เพิ่มความยืดหยุ่น และช่วยวางโครงสร้าง IP Address ตาม Site/Function แต่ต้องมี IPAM และเอกสารที่ชัดเจนเพื่อป้องกัน Subnet Overlap

4. เก็บ Requirement ก่อนออกแบบ IP Address Plan

ก่อนคำนวณ VLSM ให้รวบรวมข้อมูล จำนวนอุปกรณ์ปัจจุบัน, Growth, Site, VLAN, DHCP Scope, Static IP, Routing, Security Zone และ Cloud Connectivity

Networkจำนวน Host ที่วางแผนหน้าที่
Users200Employee PCs
Guest Wi-Fi100Internet-only
Servers50Internal Applications
Voice50IP Phones
Management20Network Devices

ตัวเลขในตารางถือเป็น Planned Capacity ที่รวมเผื่อการขยายแล้ว ไม่ใช่จำนวนเครื่องที่ใช้งาน ณ ปัจจุบัน

5. ตัวอย่าง VLSM Design: 10.40.0.0/22

สมมติสำนักงานใหญ่ได้รับ Private Address Block 10.40.0.0/22 ซึ่งครอบคลุม 10.40.0.0 - 10.40.3.255 รวม 1,024 Addresses

Step 1 — เรียง Network จากใหญ่ไปเล็ก

Users       200 hosts -> /24 (254 usable)
Guest       100 hosts -> /25 (126 usable)
Servers      50 hosts -> /26 (62 usable)
Voice        50 hosts -> /26 (62 usable)
Management   20 hosts -> /27 (30 usable)

Step 2 — จัดสรร Subnet โดยไม่ให้ทับกัน

VLANFunctionSubnetGatewayBroadcast
10Users10.40.0.0/2410.40.0.110.40.0.255
20Guest10.40.1.0/2510.40.1.110.40.1.127
30Servers10.40.1.128/2610.40.1.12910.40.1.191
40Voice10.40.1.192/2610.40.1.19310.40.1.255
99Management10.40.2.0/2710.40.2.110.40.2.31

Step 3 — สำรองพื้นที่สำหรับอนาคต

Allocated:
10.40.0.0/24       Users
10.40.1.0/25       Guest
10.40.1.128/26     Servers
10.40.1.192/26     Voice
10.40.2.0/27       Management

Unallocated:
10.40.2.32 - 10.40.3.255
(Reserved for growth / new VLANs)

พื้นที่ว่างควรบันทึกใน IP Address Management (IPAM) และกำหนดผู้รับผิดชอบการจัดสรร ไม่ควรปล่อยให้แต่ละทีมเลือกใช้เอง

6. VLAN Design และ IP Address Planning

VLAN แบ่ง Layer 2 Broadcast Domain ส่วน Subnet เป็นขอบเขตของ Layer 3 Addressing ใน Campus Design ทั่วไปนิยมใช้หนึ่ง IP Subnet ต่อหนึ่ง VLAN เพื่อให้ Routing และ Security Policy เข้าใจง่าย

                CORE L3 SWITCH
                      |
          +-----------+-----------+
          |           |           |
        VLAN10      VLAN20      VLAN30
        USERS       GUEST       SERVERS
          |           |           |
      10.40.0.0   10.40.1.0  10.40.1.128
         /24         /25         /26

การมี VLAN แยกกัน ไม่ได้รับประกัน Security Isolation หาก Layer 3 Gateway ยังอนุญาต Inter-VLAN Routing ทั้งหมด จึงต้องออกแบบ ACL หรือ Firewall Policy ร่วมด้วย

VLAN ID ไม่จำเป็นต้องตรงกับ Third Octet

ตัวอย่าง VLAN 30 ใช้ 10.40.1.128/26 ได้ตามปกติ เพราะ VLAN ID และ IP Prefix เป็นคนละระบบ

7. IP Address Summarization และ Site Planning

Route Summarization คือการประกาศ Route ที่ครอบคลุมหลาย Prefix เพื่อลดจำนวน Routing Entries และทำให้ Network Scale ได้ดีขึ้น

HQ:      10.40.0.0/22
Branch A:10.40.4.0/22
Branch B:10.40.8.0/22

Site Summary:
HQ       -> 10.40.0.0/22
Branch A -> 10.40.4.0/22
Branch B -> 10.40.8.0/22

ควรจัด Address Blocks ให้ Contiguous ตั้งแต่เริ่มออกแบบ เพราะการกระจาย Subnet ของ Site เดียวกันไปหลาย Block ทำให้ Summarization ยากขึ้น

ข้อควรระวัง: Summary Route อาจครอบคลุม Address ที่ยังไม่ได้ใช้งาน ต้องตรวจ Routing, Blackhole Risk และการมี More-Specific Routes ให้เหมาะสมก่อนประกาศจริง

8. ตัวอย่าง Cisco IOS/IOS XE Configuration

ตัวอย่างนี้สมมติว่า Cisco Layer 3 Switch รองรับ SVI และ ip routing และใช้ Interface Naming ตามอุปกรณ์จริงที่ตรวจสอบแล้ว

Step 1 — สร้าง VLAN

configure terminal
vlan 10
 name USERS
vlan 20
 name GUEST
vlan 30
 name SERVERS
vlan 40
 name VOICE
vlan 99
 name MANAGEMENT

Step 2 — เปิด Layer 3 Routing และ SVI

ip routing

interface Vlan10
 description USERS-GATEWAY
 ip address 10.40.0.1 255.255.255.0
 no shutdown

interface Vlan20
 description GUEST-GATEWAY
 ip address 10.40.1.1 255.255.255.128
 no shutdown

interface Vlan30
 description SERVERS-GATEWAY
 ip address 10.40.1.129 255.255.255.192
 no shutdown

interface Vlan40
 description VOICE-GATEWAY
 ip address 10.40.1.193 255.255.255.192
 no shutdown

interface Vlan99
 description MANAGEMENT-GATEWAY
 ip address 10.40.2.1 255.255.255.224
 no shutdown

Step 3 — กำหนด Access Port

interface GigabitEthernet1/0/10
 description USER-PC
 switchport mode access
 switchport access vlan 10
 spanning-tree portfast
 spanning-tree bpduguard enable

Step 4 — กำหนด Uplink Trunk

interface GigabitEthernet1/0/48
 description UPLINK-TO-ACCESS-SWITCH
 switchport mode trunk
 switchport trunk allowed vlan 10,20,30,40,99

บน Production ควรกำหนด Native VLAN, DTP Negotiation และ STP Security ตาม Platform และ Campus Design ด้วย

Step 5 — กำหนด Default Route ไปยัง Firewall/Router

ip route 0.0.0.0 0.0.0.0 <NEXT_HOP_IP>

ต้องแทน NEXT_HOP_IP ด้วย IP ของอุปกรณ์ Upstream ที่ Reachable จริง และต้องตรวจ Return Route บนอุปกรณ์ Upstream ด้วย

ตัวอย่างข้างต้นเป็น Lab Configuration ไม่ใช่ Full Production Hardening การ Apply ACL, DHCP Relay, Redundant Gateway และ Security Policy ต้องออกแบบเพิ่มเติมตามอุปกรณ์และข้อกำหนดขององค์กร

9. DHCP, Security และ IP Address Governance

DHCP Scope

แต่ละ VLAN ที่ใช้ DHCP ควรมี Scope ตรงกับ Subnet และ Default Gateway เช่น Users VLAN 10 ใช้ 10.40.0.0/24 พร้อมกัน Static Address Range สำหรับ Infrastructure หรือ Reserved Devices

DHCP Relay

ถ้า DHCP Server อยู่คนละ VLAN สามารถใช้ ip helper-address บน SVI ตามความสามารถของ Platform

interface Vlan10
 ip helper-address <DHCP_SERVER_IP>

Segmentation Policy

Guest VLAN ควรเข้าถึง Internet ตาม Policy แต่ถูกจำกัดการเข้าถึง Internal Server Networks ขณะที่ Management VLAN ควรอนุญาตเฉพาะ Authorized Administrators และ Management Systems

IPAM และ Documentation

ควรเก็บ Site, VLAN ID, Network Prefix, Gateway, DHCP Range, Static Reservations, Owner, Purpose และ Change History ไว้ในระบบกลาง

10. Verification บน Cisco

หลัง Configuration ให้ตรวจทั้ง VLAN, SVI, Routing และ Endpoint Connectivity

show vlan brief
show ip interface brief
show interfaces trunk
show ip route connected
show ip route
show running-config interface Vlan10
show running-config interface Vlan20
show arp

จุดที่ต้องตรวจ:

  • VLAN มีอยู่และ Access Ports อยู่ VLAN ที่ถูกต้อง
  • SVI อยู่ในสถานะ up/up เมื่อมี Active VLAN/Port ตาม Platform Behavior
  • Subnet Mask และ Gateway ตรงกับ IP Plan
  • Trunk อนุญาต VLAN ที่ต้องการ
  • มี Route ไปปลายทางและ Return Route กลับ
  • DHCP Client ได้ IP, Mask, Gateway และ DNS ถูกต้อง

11. Network Addressing Troubleshooting

Case 1 — เครื่องได้ IP แต่ Ping Gateway ไม่ได้

ตรวจ VLAN Assignment, Access Port, SVI State, ARP, Host Firewall และ Subnet Mask

Case 2 — Ping Gateway ได้ แต่ข้าม VLAN ไม่ได้

ตรวจ ip routing, ACL, Firewall Policy, Destination Gateway และ Return Route

Case 3 — DHCP ได้ IP ผิด Subnet

ตรวจ DHCP Scope, Relay Address, VLAN Port Membership, Rogue DHCP และ DHCP Snooping

Case 4 — Duplicate IP Address

ตรวจ DHCP Exclusions, Static Reservations, ARP Table, IPAM และการกำหนด Static IP ซ้ำ

Case 5 — Subnet Overlap ระหว่าง HQ กับ Branch

อาจทำให้ Routing ผ่าน VPN ผิดทิศทางหรือไม่สามารถแยกเครือข่ายปลายทางได้ ควรแก้ที่ Address Plan เป็นหลัก ส่วน NAT-Based Workaround ใช้เมื่อมีข้อจำกัดและออกแบบอย่างระมัดระวัง

Problem
   |
   v
Correct IP / Mask?
   |
   v
Correct VLAN?
   |
   v
Gateway Reachable?
   |
   v
Route Present?
   |
   v
Return Route Present?
   |
   v
ACL / Firewall / NAT?
   |
   v
Application Test

12. Network Addressing Best Practices

  • วางแผนตาม Site และ Function ก่อนเลือก Prefix
  • ใช้ VLSM ให้เหมาะกับ Planned Capacity และ Growth
  • หลีกเลี่ยง Subnet Overlap ระหว่าง On-Premises, Branch, VPN และ Cloud
  • สำรอง Address Space สำหรับการขยายในอนาคต
  • กำหนด Gateway Convention ให้สม่ำเสมอ
  • แยก Guest, Server, Voice และ Management ตาม Security Requirements
  • ใช้ IPAM เป็น Source of Truth สำหรับ Address Allocation
  • ทดสอบ Routing และ Return Path ทุกครั้งหลังเปลี่ยน IP Plan
  • Document Changes และเตรียม Rollback Plan ก่อน Migration

13. คำถามที่พบบ่อย

Subnetting กับ VLSM ต่างกันอย่างไร?

Subnetting คือการแบ่ง Network เป็น Subnets ส่วน VLSM คือการใช้ Subnet Mask หลายขนาดตาม Requirement ของแต่ละ Subnet

VLAN หนึ่งต้องใช้หนึ่ง Subnet เสมอหรือไม่?

ไม่ใช่ข้อบังคับทางเทคนิคทุกกรณี แต่ หนึ่ง Subnet ต่อหนึ่ง VLAN เป็นแนวทางทั่วไปที่ทำให้ Campus Network ดูแลและ Troubleshoot ได้ง่าย

VLAN ID ต้องตรงกับ IP Address หรือไม่?

ไม่จำเป็น VLAN ID เป็น Layer 2 Identifier ส่วน IP Prefix เป็น Layer 3 Addressing

/31 ใช้กับ Point-to-Point ได้หรือไม่?

ได้เมื่ออุปกรณ์ทั้งสองฝั่งรองรับตาม RFC 3021 และเป็น Link ที่เหมาะสม โดยไม่ใช้สูตรลบ 2 แบบ Subnet LAN ทั่วไป

ทำไมต้องเผื่อ IP Address สำหรับอนาคต?

เพื่อลดการ Renumbering และผลกระทบต่อ DHCP, DNS, ACL, VPN, Monitoring และ Application Dependencies

IP Address Summarization ช่วยอะไร?

ช่วยลดจำนวน Routing Entries และทำให้ Routing Architecture Scale ได้ดีขึ้น แต่ต้องจัด Prefix ให้ต่อเนื่องและตรวจความถูกต้องของ Route Advertisement

14. บทสรุป

Network Addressing Design ที่ดีไม่ใช่แค่คำนวณ Subnet ได้ถูกต้อง แต่ต้องรองรับการเติบโต ความปลอดภัย การทำ Routing และการดูแลรักษาในระยะยาว

Business Requirements
       |
       v
Host Capacity + Growth
       |
       v
Site Address Blocks
       |
       v
VLSM Allocation
       |
       v
VLAN / Gateway Design
       |
       v
Routing + Security Policy
       |
       v
Verification + IPAM

ตัวอย่าง 10.40.0.0/22 ในบทความแสดงให้เห็นการจัดสรร Subnets หลายขนาดสำหรับ Users, Guest, Servers, Voice และ Management โดยไม่ทับซ้อนกัน พร้อมสำรองพื้นที่สำหรับ VLAN ใหม่

บทความถัดไป: Enterprise Network Design — Access, Distribution และ Core Layer พร้อม Cisco Campus Architecture

Share this
Facebook Share X
TECHEREST COMMUNITY

Share your thoughts here

Join the conversation and share your perspective on this article.

Comments will load when you reach this section.