คำสั่งพื้นฐานเพื่อใช้แก้ปัญหาระบบคอมพิวเตอร์และเครือข่ายบน Windows
เมื่อคอมพิวเตอร์เกิดปัญหา เช่น เชื่อมต่ออินเทอร์เน็ตไม่ได้, เข้าเว็บไซต์ไม่ได้, หาเครื่องอื่นในเครือข่ายไม่พบ, DNS มีปัญหา, Network Adapter ทำงานผิดปกติ หรือ Windows มีไฟล์ระบบเสียหาย การใช้คำสั่งผ่าน Command Prompt (CMD) และ PowerShell สามารถช่วยตรวจสอบและแก้ไขปัญหาเบื้องต้นได้อย่างรวดเร็ว
บทความนี้รวบรวม คำสั่งพื้นฐานสำหรับแก้ปัญหาคอมพิวเตอร์และระบบเครือข่าย Windows 10/11 ตั้งแต่การตรวจสอบ IP Address, ทดสอบ Network, ตรวจสอบ DNS, ดูเส้นทางเครือข่าย, ตรวจสอบ Port, Reset Network ไปจนถึงการตรวจสอบและซ่อมแซมไฟล์ระบบ Windows เหมาะสำหรับผู้ใช้งานทั่วไป, IT Support, Network Administrator และผู้ที่กำลังศึกษา Cybersecurity
สารบัญ
- วิธีเปิด Command Prompt และ PowerShell
- 1. ipconfig — ตรวจสอบ IP Address
- 2. ping — ทดสอบการเชื่อมต่อเครือข่าย
- 3. tracert — ตรวจสอบเส้นทาง Network
- 4. nslookup — ตรวจสอบ DNS
- 5. netstat — ตรวจสอบ Port และ Connection
- 6. arp — ตรวจสอบ ARP Table
- 7. route print — ตรวจสอบ Routing Table
- 8. hostname — ตรวจสอบชื่อเครื่อง
- 9. systeminfo — ตรวจสอบข้อมูล Windows
- 10. tasklist — ตรวจสอบ Process
- 11. taskkill — ปิด Process
- 12. ipconfig /flushdns — ล้าง DNS Cache
- 13. ipconfig /release และ /renew — ขอ IP ใหม่
- 14. netsh winsock reset — Reset Winsock
- 15. netsh int ip reset — Reset TCP/IP
- 16. sfc /scannow — ตรวจสอบไฟล์ระบบ Windows
- 17. DISM — ซ่อม Windows Image
- 18. chkdsk — ตรวจสอบ Disk
- 19. PowerShell สำหรับตรวจสอบ Network
- ขั้นตอน Troubleshooting Network ที่แนะนำ
- FAQ
วิธีเปิด Command Prompt และ PowerShell
คำสั่งส่วนใหญ่ในบทความนี้สามารถใช้งานผ่าน Command Prompt หรือ Windows PowerShell ได้
เปิด Command Prompt
- กด Windows + R
- พิมพ์ cmd
- กด Enter
หากต้องใช้สิทธิ์ Administrator:
- เปิด Start Menu
- ค้นหา Command Prompt
- คลิกขวา
- เลือก Run as administrator
เปิด PowerShell
- คลิกขวาที่ปุ่ม Start
- เลือก Terminal หรือ Windows PowerShell
บางคำสั่งที่ใช้แก้ไข Network หรือไฟล์ระบบจำเป็นต้องเปิด Terminal ด้วยสิทธิ์ Administrator
1. ipconfig — ตรวจสอบ IP Address
ipconfig เป็นหนึ่งในคำสั่งพื้นฐานที่ควรรู้มากที่สุดสำหรับการตรวจสอบ Network Configuration ของ Windows
ipconfig
จะแสดงข้อมูล เช่น:
- IPv4 Address
- Subnet Mask
- Default Gateway
ดูข้อมูล Network แบบละเอียด
ipconfig /all
สามารถตรวจสอบข้อมูลเพิ่มเติม เช่น:
- MAC Address
- DHCP Server
- DNS Server
- DHCP Enabled
- Lease Obtained
- Lease Expires
หากพบ IP Address ในช่วง 169.254.x.x อาจหมายความว่าเครื่องไม่สามารถรับ IP Address จาก DHCP Server ได้
2. ping — ทดสอบการเชื่อมต่อเครือข่าย
คำสั่ง ping ใช้ตรวจสอบว่าเครื่องสามารถติดต่อกับอุปกรณ์หรือ Server ปลายทางได้หรือไม่
ทดสอบ TCP/IP ภายในเครื่อง
ping 127.0.0.1
127.0.0.1 คือ Loopback Address หาก Ping ไม่สำเร็จ อาจมีปัญหากับ TCP/IP Stack ภายในระบบ
ทดสอบ Default Gateway
ตัวอย่าง:
ping 192.168.1.1
หาก Ping Gateway ไม่ได้ ควรตรวจสอบ LAN Cable, Wi-Fi, Network Adapter, IP Address และ Router
ทดสอบ Internet
ping 8.8.8.8
หาก Ping IP Address ได้ แต่เข้าเว็บไซต์ไม่ได้ อาจเกี่ยวข้องกับ DNS
ทดสอบ DNS และ Internet พร้อมกัน
ping google.com
หาก Ping 8.8.8.8 ได้ แต่ Ping google.com ไม่ได้ มีความเป็นไปได้สูงว่าระบบ DNS มีปัญหา
3. tracert — ตรวจสอบเส้นทาง Network
tracert หรือ Trace Route ใช้ตรวจสอบว่า Packet เดินทางผ่าน Router ใดบ้างก่อนถึงปลายทาง
tracert google.com
หรือ
tracert 8.8.8.8
มีประโยชน์ในการตรวจสอบ:
- เส้นทางการเชื่อมต่อ Network
- จุดที่ Network ขาดการเชื่อมต่อ
- Router หรือ Gateway ระหว่างทาง
- Network Latency
- ปัญหาระหว่าง Internal Network กับ ISP
4. nslookup — ตรวจสอบ DNS
nslookup ใช้ตรวจสอบการแปลงชื่อ Domain Name เป็น IP Address
nslookup google.com
ผลลัพธ์จะแสดง DNS Server ที่กำลังใช้งาน และ IP Address ของ Domain ที่ค้นหา
ทดสอบด้วย DNS Server ที่กำหนด
nslookup google.com 8.8.8.8
คำสั่งนี้จะให้ Google DNS ที่ IP Address 8.8.8.8 เป็นผู้ตอบ DNS Query
5. netstat — ตรวจสอบ Port และ Network Connection
netstat ใช้ตรวจสอบ Network Connection และ Port ที่กำลังใช้งานบนคอมพิวเตอร์
netstat -an
สามารถดูสถานะต่าง ๆ เช่น:
- LISTENING
- ESTABLISHED
- TIME_WAIT
- CLOSE_WAIT
ตรวจสอบ Process ID ที่ใช้ Network
netstat -ano
ตัวเลือก -o จะแสดง PID หรือ Process ID
ตรวจสอบ Port เฉพาะ
ตัวอย่างตรวจสอบ Port 443:
netstat -ano | findstr :443
ตรวจสอบ Port 80:
netstat -ano | findstr :80
คำสั่งนี้มีประโยชน์มากสำหรับ IT Support, System Administrator และ Cybersecurity ในการตรวจสอบว่าโปรแกรมใดกำลังเปิด Port หรือเชื่อมต่อออกไปยัง Network
6. arp — ตรวจสอบ ARP Table
ARP หรือ Address Resolution Protocol ใช้เชื่อมโยงระหว่าง IP Address และ MAC Address ของอุปกรณ์ภายใน Network
arp -a
สามารถใช้ดู:
- IP Address ของอุปกรณ์
- MAC Address
- ARP Entry
ล้าง ARP Cache
arp -d *
คำสั่งล้าง ARP Cache อาจต้องเปิด Command Prompt ด้วยสิทธิ์ Administrator
7. route print — ตรวจสอบ Routing Table
หากต้องการตรวจสอบว่า Windows จะส่ง Packet ออกไปทาง Network Interface หรือ Gateway ใด สามารถใช้:
route print
ข้อมูลสำคัญประกอบด้วย:
- Network Destination
- Netmask
- Gateway
- Interface
- Metric
คำสั่งนี้มีประโยชน์มากกรณีเครื่องมี Network Adapter หลายตัว เช่น Ethernet, Wi-Fi, VPN และ Virtual Network Adapter
8. hostname — ตรวจสอบชื่อเครื่อง
ตรวจสอบ Computer Name ได้ด้วย:
hostname
เหมาะสำหรับการตรวจสอบเครื่องในระบบ Domain, Workgroup หรือองค์กรที่มีคอมพิวเตอร์จำนวนมาก
9. systeminfo — ตรวจสอบข้อมูล Windows
ใช้ตรวจสอบรายละเอียดของระบบ:
systeminfo
ข้อมูลที่สามารถตรวจสอบได้ เช่น:
- Computer Name
- Windows Version
- OS Build
- System Manufacturer
- System Model
- BIOS Version
- RAM
- Network Adapter
- Windows Update บางส่วน
10. tasklist — ตรวจสอบ Process ที่กำลังทำงาน
tasklist ใช้ดู Process ที่กำลังทำงานอยู่บน Windows
tasklist
ค้นหา Process เฉพาะ เช่น Chrome:
tasklist | findstr chrome
สามารถนำ PID ที่ได้ไปเปรียบเทียบกับผลจาก netstat -ano เพื่อหาว่า Process ใดกำลังใช้งาน Network
11. taskkill — ปิด Process
หากโปรแกรมค้างและไม่สามารถปิดจากหน้าจอปกติได้ สามารถใช้ taskkill
ตัวอย่าง:
taskkill /PID 1234 /F
หรือปิดตามชื่อโปรแกรม:
taskkill /IM notepad.exe /F
/F หมายถึง Force Termination ดังนั้นควรตรวจสอบ Process ให้ถูกต้องก่อนใช้งาน
12. ipconfig /flushdns — ล้าง DNS Cache
หากเข้าเว็บไซต์ไม่ได้ทั้งที่ Internet ทำงานปกติ หรือ DNS มีข้อมูลเก่าค้างอยู่ สามารถล้าง DNS Cache ได้
ipconfig /flushdns
หากสำเร็จ Windows จะแสดงข้อความ:
Successfully flushed the DNS Resolver Cache.
เหมาะสำหรับปัญหา เช่น:
- เข้าเว็บไซต์บางเว็บไม่ได้
- Domain เปลี่ยน IP Address
- DNS Cache ผิดปกติ
- DNS Resolution มีปัญหา
13. ipconfig /release และ /renew — ขอ IP Address ใหม่
หากใช้ DHCP และสงสัยว่า IP Address มีปัญหา สามารถ Release และ Renew IP Address ได้
ปล่อย IP Address เดิม
ipconfig /release
ขอ IP Address ใหม่
ipconfig /renew
หลังจากนั้นควรตรวจสอบอีกครั้งด้วย:
ipconfig /all
14. netsh winsock reset — Reset Winsock
Winsock เป็นส่วนหนึ่งของ Windows ที่เกี่ยวข้องกับการทำงานของโปรแกรมผ่าน TCP/IP หาก Network Stack ทำงานผิดปกติ สามารถ Reset Winsock ได้
netsh winsock reset
ควรเปิด Command Prompt แบบ Administrator และ Restart Windows หลังจากดำเนินการ
เหมาะสำหรับปัญหา เช่น:
- Internet ใช้งานไม่ได้หลังติดตั้งหรือลบโปรแกรมบางชนิด
- Network Stack ผิดปกติ
- Browser เชื่อมต่อไม่ได้
- VPN หรือ Network Software ทำให้ Network ผิดปกติ
15. netsh int ip reset — Reset TCP/IP
หาก TCP/IP Configuration ของ Windows มีปัญหา สามารถ Reset กลับสู่ค่าพื้นฐานได้ด้วย:
netsh int ip reset
จากนั้น Restart เครื่อง
สามารถใช้ร่วมกับ:
netsh winsock reset
ipconfig /flushdns
ข้อควรระวัง: ในระบบองค์กรที่มีการตั้งค่า Static IP หรือ Network Configuration แบบเฉพาะ ควรบันทึกค่าปัจจุบันก่อน Reset
16. sfc /scannow — ตรวจสอบและซ่อมแซมไฟล์ระบบ Windows
หากสงสัยว่า Windows System File เสียหาย สามารถใช้ System File Checker
sfc /scannow
ต้องเปิด Command Prompt หรือ Terminal ด้วยสิทธิ์ Administrator
SFC จะตรวจสอบ Protected System Files และพยายามซ่อมแซมไฟล์ที่เสียหาย
17. DISM — ตรวจสอบและซ่อม Windows Image
หาก SFC ไม่สามารถแก้ปัญหาได้ สามารถใช้ DISM ตรวจสอบ Windows Component Store
ตรวจสอบสถานะเบื้องต้น
DISM /Online /Cleanup-Image /CheckHealth
Scan ระบบ
DISM /Online /Cleanup-Image /ScanHealth
ซ่อม Windows Image
DISM /Online /Cleanup-Image /RestoreHealth
หลังจาก DISM ทำงานเสร็จ สามารถใช้:
sfc /scannow
อีกครั้งเพื่อให้ Windows ตรวจสอบและซ่อม System Files
18. chkdsk — ตรวจสอบ Disk
chkdsk ใช้ตรวจสอบ File System และ Disk Error
chkdsk C:
ตรวจสอบและแก้ไข Error:
chkdsk C: /f
หาก Drive C: กำลังใช้งาน Windows อาจขอให้กำหนดการตรวจสอบในครั้งถัดไปที่ Restart เครื่อง
19. PowerShell สำหรับตรวจสอบ Network
นอกจาก Command Prompt แล้ว PowerShell ยังมีคำสั่งที่มีประสิทธิภาพสำหรับ Network Troubleshooting
ดู IP Address
Get-NetIPAddress
ดู Network Adapter
Get-NetAdapter
สามารถตรวจสอบว่า Network Adapter อยู่ในสถานะ Up หรือ Disabled
ดู Network Configuration
Get-NetIPConfiguration
ดู Routing Table
Get-NetRoute
ตรวจสอบ DNS
Resolve-DnsName google.com
ทดสอบ Network และ Port
ตัวอย่างตรวจสอบ Google Port HTTPS 443:
Test-NetConnection google.com -Port 443
ตรวจสอบ DNS Port 53:
Test-NetConnection 8.8.8.8 -Port 53
Test-NetConnection มีประโยชน์มาก เพราะสามารถตรวจสอบทั้ง DNS, IP Address, Ping และ TCP Port ได้
ขั้นตอน Troubleshooting Network ที่แนะนำ
เมื่อคอมพิวเตอร์ Windows เชื่อมต่อ Internet ไม่ได้ ไม่ควรเริ่มต้นด้วยการ Reset Network ทันที แต่ควรตรวจสอบปัญหาตามลำดับ
Step 1: ตรวจสอบ IP Address
ipconfig /all
ตรวจสอบว่า:
- ได้รับ IPv4 Address หรือไม่
- Subnet Mask ถูกต้องหรือไม่
- Default Gateway มีหรือไม่
- DNS Server ถูกต้องหรือไม่
Step 2: ทดสอบ TCP/IP ภายในเครื่อง
ping 127.0.0.1
Step 3: Ping IP Address ของเครื่องตัวเอง
ตัวอย่าง:
ping 192.168.1.100
Step 4: Ping Default Gateway
ping 192.168.1.1
ถ้าไม่สำเร็จ ให้ตรวจสอบ LAN Cable, Wi-Fi, Network Adapter, VLAN และ Router
Step 5: ทดสอบ Internet ด้วย IP Address
ping 8.8.8.8
Step 6: ทดสอบ DNS
ping google.com
จากนั้น:
nslookup google.com
Step 7: ตรวจสอบเส้นทาง Network
tracert 8.8.8.8
Step 8: ล้าง DNS Cache
ipconfig /flushdns
Step 9: ขอ IP Address ใหม่จาก DHCP
ipconfig /release
ipconfig /renew
Step 10: Reset Network Stack หากยังไม่หาย
netsh winsock reset
netsh int ip reset
ipconfig /flushdns
จากนั้น Restart Windows
ตัวอย่างการวิเคราะห์ปัญหา Internet แบบง่าย
กรณีที่ 1: Ping Gateway ไม่ได้
ตรวจสอบ:
- สาย LAN
- Wi-Fi Connection
- Network Adapter
- IP Address
- Subnet Mask
- VLAN
- Router หรือ Switch
กรณีที่ 2: Ping Gateway ได้ แต่ Ping 8.8.8.8 ไม่ได้
อาจเกี่ยวข้องกับ:
- Router
- Default Route
- Firewall
- ISP
- Internet Gateway
กรณีที่ 3: Ping 8.8.8.8 ได้ แต่ Ping google.com ไม่ได้
มีความเป็นไปได้ว่า DNS มีปัญหา
ตรวจสอบด้วย:
nslookup google.com
และลอง:
ipconfig /flushdns
กรณีที่ 4: Website เข้าไม่ได้เฉพาะบางเว็บ
สามารถตรวจสอบด้วย:
nslookup example.com
ping example.com
tracert example.com
รวมถึงตรวจสอบ Firewall, Proxy, VPN และ DNS Server ที่ใช้งานอยู่
ชุดคำสั่ง Network Troubleshooting ที่ควรจำ
หากต้องการชุดคำสั่งพื้นฐานสำหรับตรวจสอบ Network สามารถเริ่มต้นจากชุดนี้:
ipconfig /all
ping 127.0.0.1
ping 192.168.1.1
ping 8.8.8.8
ping google.com
nslookup google.com
tracert google.com
netstat -ano
arp -a
route print
สำหรับ PowerShell:
Get-NetAdapter
Get-NetIPConfiguration
Get-NetIPAddress
Get-NetRoute
Resolve-DnsName google.com
Test-NetConnection google.com -Port 443
ตารางสรุปคำสั่งที่ใช้บ่อย
| คำสั่ง | หน้าที่ |
|---|---|
ipconfig /all |
ตรวจสอบ IP และ Network Configuration |
ping |
ทดสอบการเชื่อมต่อ Network |
tracert |
ตรวจสอบเส้นทางของ Packet |
nslookup |
ตรวจสอบ DNS |
netstat -ano |
ตรวจสอบ Port, Connection และ PID |
arp -a |
ตรวจสอบ ARP Table |
route print |
ตรวจสอบ Routing Table |
ipconfig /flushdns |
ล้าง DNS Cache |
ipconfig /renew |
ขอ IP จาก DHCP ใหม่ |
netsh winsock reset |
Reset Winsock |
netsh int ip reset |
Reset TCP/IP |
sfc /scannow |
ตรวจสอบและซ่อม Windows System Files |
DISM /Online /Cleanup-Image /RestoreHealth |
ซ่อม Windows Component Store |
Get-NetAdapter |
ตรวจสอบ Network Adapter ผ่าน PowerShell |
Test-NetConnection |
ทดสอบ Host และ TCP Port |
ข้อควรระวังในการใช้คำสั่งแก้ปัญหาระบบ
- ตรวจสอบคำสั่งให้ถูกต้องก่อนกด Enter
- คำสั่งบางประเภทต้องใช้สิทธิ์ Administrator
- อย่า Reset TCP/IP โดยไม่จำเป็นในระบบที่กำหนด Static IP
- บันทึก IP Address, Gateway และ DNS ก่อนแก้ไข Network Configuration
- ระวังการใช้
taskkill /Fกับ Process สำคัญของระบบ - ในระบบองค์กรควรตรวจสอบนโยบายของ IT Department ก่อนเปลี่ยน Network Configuration
- หากพบ Connection หรือ Process ที่ไม่รู้จัก ไม่ควรสรุปทันทีว่าเป็น Malware ควรตรวจสอบข้อมูลเพิ่มเติม
สรุป
การใช้ Command Prompt และ PowerShell เป็นทักษะพื้นฐานที่มีประโยชน์อย่างมากสำหรับการแก้ปัญหา Windows และระบบเครือข่าย โดยเฉพาะคำสั่ง ipconfig, ping, tracert, nslookup, netstat, arp และ route ซึ่งสามารถช่วยแยกได้ว่าปัญหาเกิดขึ้นที่เครื่องคอมพิวเตอร์, Network Adapter, DNS, Gateway, Router หรือ Internet
หลักการสำคัญของ Network Troubleshooting คือ ตรวจสอบปัญหาตามลำดับจากใกล้ตัวไปไกล เช่น ตรวจสอบ IP ของเครื่อง → Loopback → Gateway → Internet IP → DNS → Route แทนการ Reset Network ทันที
สำหรับผู้ที่ทำงานด้าน IT Support, Network Administration หรือ Cybersecurity การเข้าใจคำสั่งเหล่านี้จะช่วยให้สามารถวิเคราะห์และแก้ไขปัญหาได้รวดเร็วและเป็นระบบมากขึ้น
FAQ: คำถามที่พบบ่อย
1. คำสั่งใดใช้ตรวจสอบ IP Address บน Windows?
ใช้คำสั่ง:
ipconfig
หากต้องการข้อมูลละเอียด:
ipconfig /all
2. ต้องการตรวจสอบว่า Internet ใช้งานได้หรือไม่ควรใช้คำสั่งอะไร?
สามารถเริ่มต้นด้วย:
ping 8.8.8.8
หากได้รับ Reply แสดงว่าสามารถติดต่อ IP Address ปลายทางได้
3. Ping 8.8.8.8 ได้ แต่เข้าเว็บไซต์ไม่ได้เกิดจากอะไร?
หนึ่งในสาเหตุที่ควรตรวจสอบคือ DNS เพราะเครื่องสามารถเชื่อมต่อ Internet ผ่าน IP ได้ แต่ไม่สามารถแปลง Domain Name เป็น IP Address
ตรวจสอบด้วย:
nslookup google.com
4. คำสั่งใดใช้ล้าง DNS Cache?
ipconfig /flushdns
5. คำสั่งใดใช้ตรวจสอบ Port ที่เปิดอยู่?
ใช้:
netstat -ano
หากต้องการค้นหาเฉพาะ Port 443:
netstat -ano | findstr :443
6. คำสั่งใดใช้ตรวจสอบเส้นทางของ Network?
ใช้:
tracert google.com
คำสั่งนี้จะแสดง Router หรือ Hop ที่ Packet เดินทางผ่านก่อนถึงปลายทาง
7. netsh winsock reset ใช้ทำอะไร?
ใช้ Reset Winsock Catalog ของ Windows ซึ่งอาจช่วยแก้ปัญหา Network Stack หรือโปรแกรมไม่สามารถเชื่อมต่อ Internet ได้
8. sfc /scannow ใช้แก้ปัญหา Network ได้หรือไม่?
SFC ไม่ได้เป็นคำสั่งสำหรับ Network โดยตรง แต่สามารถตรวจสอบและซ่อมแซม Windows System Files ที่เสียหาย ซึ่งบางกรณีอาจส่งผลต่อการทำงานของระบบหรือ Network Component
9. Command Prompt กับ PowerShell แบบไหนเหมาะกับ Network Troubleshooting?
ทั้งสองแบบสามารถใช้งานได้ Command Prompt เหมาะกับคำสั่งพื้นฐาน เช่น ping, ipconfig และ tracert ส่วน PowerShell มีคำสั่งขั้นสูง เช่น Get-NetAdapter, Get-NetIPAddress และ Test-NetConnection
10. คำสั่งใดเหมาะสำหรับตรวจสอบว่า Server เปิด Port อยู่หรือไม่?
PowerShell สามารถใช้:
Test-NetConnection server.example.com -Port 443
เหมาะสำหรับตรวจสอบ TCP Connectivity ไปยัง Service ปลายทาง
