How To Add Static Route on Microsoft Windows

Supachai Jaturaprom
2 min readFeb 13, 2020

--

การเพิ่ม Static Route บน Microsoft Windows แบบง่ายๆ

  1. เปิด Command Prompt โดยให้ Run As Administrator ด้วยครับ

2. ใช้คำสั่งดู Routing Table บนเครื่อง PC เรา

C:\>route print -4
===========================================================================
Interface List
39...02 50 41 00 00 01 ......PANGP Virtual Ethernet Adapter #2
47...0a 00 27 00 00 2f ......VirtualBox Host-Only Ethernet Adapter #2
18...10 4a 7d 83 ab b3 ......Microsoft Wi-Fi Direct Virtual Adapter #4
46...12 4a 7d 83 ab b2 ......Microsoft Hosted Network Virtual Adapter #2
42...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1 #2
20...00 50 56 c0 00 02 ......VMware Virtual Ethernet Adapter for VMnet2 #2
23...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8 #2
1...........................Software Loopback Interface 1
=======================================
IPv4 Route Table
===========================================================================
Active Routes:
Network Destination Netmask Gateway Interface Metric
0.0.0.0 0.0.0.0 172.24.1.1 172.24.1.10 291
172.24.1.0 255.255.255.0 On-link 172.24.1.1 291
172.24.1.32 255.255.255.255 On-link 172.24.1.1 291
172.24.1.255 255.255.255.255 On-link 172.24.1.1 291
127.0.0.0 255.0.0.0 On-link 127.0.0.1 331
127.0.0.1 255.255.255.255 On-link 127.0.0.1 331
127.255.255.255 255.255.255.255 On-link 127.0.0.1 331
169.254.0.0 255.255.0.0 On-link 169.254.127.16 281
169.254.127.16 255.255.255.255 On-link 169.254.127.16 281
169.254.255.255 255.255.255.255 On-link 169.254.127.16 281
172.24.1.0 255.255.255.0 On-link 172.24.1.1 291
172.24.1.1 255.255.255.255 On-link 172.24.1.1 291
172.24.1.255 255.255.255.255 On-link 172.24.1.1 291
172.25.1.0 255.255.255.0 On-link 172.25.1.1 291
172.25.1.1 255.255.255.255 On-link 172.25.1.1 291
172.25.1.255 255.255.255.255 On-link 172.25.1.1 291
224.0.0.0 240.0.0.0 On-link 127.0.0.1 331
224.0.0.0 240.0.0.0 On-link 169.254.127.16 281
224.0.0.0 240.0.0.0 On-link 172.25.1.1 291
224.0.0.0 240.0.0.0 On-link 172.24.1.1 291
255.255.255.255 255.255.255.255 On-link 127.0.0.1 331
255.255.255.255 255.255.255.255 On-link 169.254.127.16 281
255.255.255.255 255.255.255.255 On-link 172.25.1.1 291
255.255.255.255 255.255.255.255 On-link 172.24.1.1 291
===========================================================================
Persistent Routes:
Network Address Netmask Gateway Address Metric
0.0.0.0 0.0.0.0 172.24.1.1 Default
===========================================================================
C:\>

3. ทำการเพิ่ม Routing Entry ที่เราต้องการเข้าไป โดยใช้คำสั่ง

Syntax Format:

route ADD Network-deestination MASK Subnet-mask  Gateway-IP Metric-Cost

Example Add Routing:

C:\>route -p ADD 10.0.0.0 MASK 255.255.255.0 172.25.1.1
OK!
C:\>

สำหรับ -p คือ Permanent ครับ เมื่อใช้ parameter นี้แล้วเวลา Reboot PC หรือ Server แล้ว Static Route ที่เราเพิ่มเข้าไปจะใม่หาย แต่ถ้าไม่ใช้ -p เวลา Reboot จะหายต้องเพิ่มเข้าไปใหม่นะครับ

4. ตรวจสอบ Routing Table ในเครื่อง PC เราอีกครั้ง

C:\>route print -4 | find "10.0.0.0"
10.0.0.0 255.255.255.0 On-link 172.25.1.1 36
10.0.0.0 255.255.255.0 172.25.1.1 1
C:\>

5. ในการลบ Static Route ใช้คำสั่งดังนี้

Syntax Format:

route delete Network-destination

Example Delete Routing:

C:\>route delete 10.0.0.0
OK!
C:\>
C:\>route print -4 | find "10.0.0.0"
C:\>

เสร็จแล้วครับ

--

--