Computer >> บทช่วยสอนคอมพิวเตอร์ >  >> ระบบ >> Windows

แก้ไขปัญหาเครือข่าย Windows Server ด้วยคำสั่ง Test-NetConnection ใน PowerShell

Windows Server มี Tools 多มากสำหรับ Admin กรณี Application หรือ Computer เชื่อมต่อ Port หรือ Server IP ไม่ได้ สิ่งที่คิดถึงทันทีคือ Tools แก้ DNS และ Network issues แต่ถ้าชอบ PowerShell มีคำสั่งเก๋ง Test-NetConnection ใช้ได้

แก้ไขปัญหาเครือข่าย Windows Server ด้วยคำสั่ง Test-NetConnection ใน PowerShell

แก้ไขปัญหาเครือข่ายด้วย PowerShell

ใช้ Test-NetConnection cmdlet เพื่อหาข้อมูล Diagnostic สำหรับ Connection รองรับ Ping test, TCP test, Route tracing, และ Route selection diagnostics

ขึ้นอยู่กับ Options ที่ใช้ Output จะประกอบด้วย ComputerName, RemoteAddress, SelectedSourceAddress, OutgoingInterfaceIndex, SelectedNetRoute, และอื่นๆ

รายการ Parameters ที่รองรับ:

  • CommonTCPPort: ระบุ Typical service TCP port number
  • ComputerName: ระบุ DNS name หรือ IP address ของ Target computer
  • ConstrainInterface: ระบุ Interface constraint สำหรับ Route diagnostics
  • ConstrainSourceAddress: ระบุ Source address constraint สำหรับ Route diagnostics
  • DiagnoseRouting: รัน Route diagnostics เพื่อ Output Route และ Source address selection info สำหรับ Remote host
  • Hops: ระบุจำนวน Hops ใน Traceroute command
  • InformationLevel: ระบุ Information level Detailed หรือ Quiet
  • Port: ระบุ TCP port number บน Remote computer
  • TraceRoute: รัน Tracert ทดสอบ Connectivity ไป Remote host

ใช้งาน Test-NetConnection cmdlet อันทรงพลัง

Test-NetConnection -ComputerName "www.contoso.com" -ConstrainInterface 5 -DiagnoseRouting -InformationLevel "Detailed"
ComputerName : www.contoso.com
RemoteAddress : 2600:1409:a:185::2768
ConstrainInterfaceIndex : 5
SelectedSourceAddress : 2001:4898:e0:79:75dd:64cf:d9ff:f86
OutgoingInterfaceIndex : 5
SelectedNetRoute : DestinationPrefix: ::/0 NextHop: fe80::200:5eff:fe00:202
RouteSelectionEvents : IP: Route [DestinationPrefix: ::/0 NextHop: fe80::200:5eff:fe00:202 InterfaceIndex: 4 RouteMetric: 256] is blocked for Destination: 2600:1409:a:185::2768 ConstrainInterfaceIndex: 5 ConstrainScopeZone: 1 in Compartment: 1, Reason: InterfaceConstraint.
SourceAddressSelectionEvents : IP: Source address 2001:4898:e0:79:75dd:64cf:d9ff:f86 is preferred over fe80::75dd:64cf:d9ff:f86 for destination 2600:1409:a:185::2768 Rule = 2.0.
IP: Source address 2001:4898:e0:79:75dd:64cf:d9ff:f86 is preferred over fe80::75dd:64cf:d9ff:f86 for destination 2600:1409:a:185::2768 Rule = 2.0.
RouteDiagnosticsSucceeded : True

ตัวอย่างคำสั่ง

แก้ไขปัญหาเครือข่าย Windows Server ด้วยคำสั่ง Test-NetConnection ใน PowerShell

ตัวอย่างคำสั่งที่ลองได้ บางคำสั่งต้อง Admin privileges เปิด PowerShell 7 หรือ 5.1 ด้วย Permission ที่เหมาะสม

Test-NetConnection youtube.com

ข้อมูลเชื่อมต่อรายละเอียด:

Test-NetConnection youtube.com -InformationLevel "Detailed"

ทำงานกับ Web services ต้อง Test Specific TCP port:

Test-NetConnection youtube.com -Port 443 -InformationLevel "Detailed"

Route diagnostics ไป Remote host:

Test-NetConnection -ComputerName itopstalk.com -DiagnoseRouting -InformationLevel Detailed

หา Default port ของ Website:

Test-NetConnection -ComputerName microsoft.com -CommonTCPPort HTTP

Run Trace Route สำหรับ Website:

Test-NetConnection -ComputerName google.com -TraceRoute

ประโยชน์หากอยู่ Non-Windows platform แต่ใช้คำสั่งเดียวกับ Windows

นอกจากนี้ พบว่า Execute commands สำหรับบาง Website เช่น Microsoft.com ไม่ได้ Ping fail ตลอด อาจเป็น Server block random requests

แก้ไขปัญหาเครือข่าย Windows Server ด้วยคำสั่ง Test-NetConnection ใน PowerShell