ใน Windows ทุก Version Default Port สำหรับ RDP (Remote Desktop Protocol) คือ TCP 3389 หลังเปิดใช้งาน RDP ใน Windows Service TermService (Remote Desktop Services) จะ Listen บน Port 3389 บทความนี้แสดงวิธีเปลี่ยน Default RDP Port Number บน Desktop Editions ของ Windows (7/8/10/11) และ Windows Server ผ่าน Registry Editor และ PowerShell
โปรดทราบว่า Windows เวอร์ชันใหม่ยังใช้ UDP ด้วย Port Number เดียวกัน (3389) สำหรับ Remote Desktop Connections นอกจาก TCP

สามารถเปลี่ยน Default RDP Port Number ใน Windows จาก 3389 เป็น Port อื่นได้ ใช้บ่อยเมื่อต้องการซ่อน RDP/RDS Host จาก Port Scanners ที่มองหา Windows Hosts บนเครือข่ายที่มี Open RDP Port TCP/3389
การเปลี่ยน RDP Port จะลดโอกาสถูก Exploit RDP Vulnerabilities (Critical Vulnerability ล่าสุดคือ BlueKeep CVE-2019-0708) ลด RDP Brute Force Attacks (อย่าลืมวิเคราะห์ RDP Connection Logs เป็นประจำ) SYN และ Attacks อื่นๆ เมื่อ NLA ปิด ใช้บ่อยกับคอมพิวเตอร์ที่เชื่อมต่อ Internet โดยตรง (VPS/VDS) หรือเครือข่ายที่ Edge Router Forward Port 3389/RDP ไปยัง Windows Host ใน LAN
แม้จะเปลี่ยน Port Number แล้ว การเปิด RDP Port บน Host ไปสู่ Internet ยังไม่ปลอดภัย Port Scanners ช่วยให้ Attacker ค้นพบ RDP Listener บน Port ใหม่ (โดย Signature) หากต้องการเปิด RDP Access ให้คอมพิวเตอร์ในเครือข่าย ควรใช้ VPN, RD Web Access, RDS Gateway และ Secure Connection Tools อื่นๆ
เวลาเลือก Non-standard RDP Port โปรดทราบว่าไม่แนะนำใช้ Port ใน Range 1-1023 (Well-known Ports) ใช้ Dynamic Port ใน RPC Port Range (49152 to 65535) หรือ Port ใดๆ ใน Range 1024 to 49151 ที่ไม่ได้ใช้โดย Service/Application อื่น
วิธีเปลี่ยน Remote Desktop Port บน Windows
ในตัวอย่าง จะเปลี่ยน Port Number ที่ Remote Desktop Service Listen เป็น 1350 ขั้นตอน:
- เปิด Registry Editor (
regedit.exe) ไปที่ Key HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp - หา DWORD Parameter ชื่อ PortNumber Parameter นี้แสดง Port ที่ Remote Desktop Service Listen Default คือ 3389 (Decimal)
- เปลี่ยนค่า Parameter นี้ ผมเปลี่ยน RDP Port เป็น 1350 (Decimal)
เปลี่ยนผ่าน PowerShell: Set-ItemProperty -Path "HKLM:\System\CurrentControlSet\Control\Terminal Server\WinStations\RDP-Tcp\" -Name PortNumber -Value 1350 - หาก Windows Firewall เปิดอยู่ ต้องสร้าง Rule ใหม่ Allow Inbound Connection ไปยัง RDP Port ใหม่ หากกำหนดค่า Remote Windows Host ผ่าน RDP ให้แน่ใจว่าสร้าง Allow Rules ใน Firewall ก่อน Restart TermService มิฉะนั้นจะเสียการเข้าถึง Server
- สร้าง Inbound Allow Rule สำหรับ TCP/UDP RDP Port ใหม่ แบบ Manual ใน Windows Defender Firewall Console (
firewall.cpl) หรือ PowerShell Cmdlets จาก NetSecurity Module:New-NetFirewallRule -DisplayName "NewRDPPort-TCP-In" -Direction Inbound -LocalPort 1350 -Protocol TCP -Action allow
New-NetFirewallRule -DisplayName "NewRDPPort-UDP-In" -Direction Inbound -LocalPort 1350 -Protocol UDP -Action allow
- Reboot Computer หรือ Restart Remote Desktop Service:
net stop termservice & net start termservice
- เชื่อมต่อ Windows Host นี้ผ่าน Remote Desktop ต้องระบุ New RDP Connection Port ใน mstsc.exe Client ใช้ Colon:
RDPComputerName:1350หรือ IP Address:192.168.1.10:1350หรือจาก Command Prompt:mstsc.exe /v 192.168.1.10:1350
หากใช้ RDCMan จัดการ Multiple RDP Connections ระบุ RDP Port ที่ตั้งค่าไว้ใน Tab Connection Settings 
- จะเชื่อมต่อ Remote Desktop ของคอมพิวเตอร์ด้วย RDP Port ใหม่สำเร็จ ใช้
netstat –na | Find "LIST"ตรวจสอบว่า Remote Desktop Service Listen บน Port ใหม่
สังเกตว่า UDP RDP Port Number ก็เปลี่ยนเป็น 1350 อัตโนมัติ (ตรวจสอบได้ด้วย TCPView Tool)

ใช้ Test-NetConnection ตรวจสอบว่า Default RDP Port 3389 ปิดแล้ว (TcpTestSucceeded: False):
Test-NetConnection 192.168.3.102 -port 3389 |select TcpTestSucceeded
ตอนนี้ต้องใช้ Port ใหม่ 1350 สำหรับ RDP Connection

หมายเหตุ หากเปลี่ยน Default RDP Listening Port Number อาจมีปัญหากับ Remote Assistance, Shadow RDP Connections ใน Windows 10, และ RDS Shadowing บน Windows Server
หากต้องการเปลี่ยน RDP Port Number บน Domain Computers ใช้ Group Policy Features สร้าง GPO ใหม่ Deploy Registry Parameter PortNumber ด้วย RDP Port Number ใหม่ไปยัง Domain Computers
เปลี่ยน RDP Listening Port Number ด้วย PowerShell
PowerShell Script ครบถ้วนสำหรับเปลี่ยน RDP Port, สร้าง Firewall Rule, และ Restart Remote Desktop Service:
Write-host "Specify the number of your new RDP port: " -ForegroundColor Yellow -NoNewline;$RDPPort = Read-Host
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-TCP\" -Name PortNumber -Value $RDPPort
New-NetFirewallRule -DisplayName "NewRDPPort-TCP-In-$RDPPort" -Direction Inbound –LocalPort $RDPPort -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "NewRDPPort-UDP-In-$RDPPort" -Direction Inbound –LocalPort $RDPPort -Protocol UDP -Action Allow
Restart-Service termservice -force
Write-host "The number of the RDP port has been changed to $RDPPort " -ForegroundColor Magenta
เปลี่ยน RDP Port Number บน Remote Computer ได้ ต้อง Enable WinRM บน Remote Computer แล้วใช้ Invoke-Command:
Invoke-Command -ComputerName wksname112 -ScriptBlock {Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-TCP\" -Name PortNumber -Value 1350}
หากต้องการเปลี่ยน RDP Number ระยะไกลบนหลายคอมพิวเตอร์ใน AD Domain (OU เฉพาะ) ใช้ Script นี้ (ดูรายการ Computers ใน OU ด้วย Get-ADComputer):
Write-host "Specify the number of your new RDP port: " -ForegroundColor Yellow -NoNewline;$RDPPort = Read-Host
$PCs = Get-ADComputer -Filter * -SearchBase "CN=IT,CN=Computers,CN=NY,DC=woshub,DC=com"
Foreach ($PC in $PCs) {
Invoke-Command -ComputerName $PC.Name -ScriptBlock {
param ($RDPPort)
Set-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\Terminal Server\WinStations\RDP-TCP\" -Name PortNumber -Value $RDPPort
New-NetFirewallRule -DisplayName "NewRDPPort-TCP-In-$RDPPort" -Direction Inbound –LocalPort $RDPPort -Protocol TCP -Action Allow
New-NetFirewallRule -DisplayName "NewRDPPort-UDP-In-$RDPPort" -Direction Inbound –LocalPort $RDPPort -Protocol TCP -Action Allow
Restart-Service termservice -force
}
คู่มือเปลี่ยน Default RDP Port นี้ใช้ได้กับ Windows ทุก Version ตั้งแต่ Windows XP (Windows Server 2003) ถึง Windows 10, Windows 11, และ Windows Server 2022 Build ล่าสุด