วิธีตั้ง Port FiveM Server เปลี่ยน 30120 เปิด TCP/UDP และแก้ปัญหาเข้า Server ไม่ได้
การ ตั้ง Port FiveM Server ต้องตั้งให้ตรงกันตั้งแต่ server.cfg, Firewall, Router หรือ Cloud Firewall ไปจนถึง Address ที่ผู้เล่นใช้เข้า Server เพราะการเปลี่ยน Port ใน server.cfg เพียงอย่างเดียวไม่ได้ทำให้ Network เปิด Port ใหม่ให้อัตโนมัติ
FiveM Server แบบมาตรฐานมักใช้
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
ดังนั้น 30120 จึงเป็น Game Port ที่พบได้บ่อยที่สุด
ถ้าต้องการเปลี่ยนเป็น 30121 ก็สามารถทำได้ เช่น
endpoint_add_tcp "0.0.0.0:30121"
endpoint_add_udp "0.0.0.0:30121"
แต่ต้องเปิด Firewall และ Network ให้ตรงกับ 30121 ด้วย
① FiveM Server Port คืออะไร
Port เปรียบเสมือนช่องทางที่ Network ใช้ส่ง Traffic ไปยัง Service ที่ถูกต้อง
ตัวอย่าง
Public IP
203.0.113.10
เครื่องเดียวอาจมีหลาย Service เช่น
30120 → FiveM Server
40120 → txAdmin
3306 → MySQL
22 → SSH
แต่ละ Port ทำหน้าที่ต่างกัน
② FiveM ใช้ Port อะไรเป็นค่าเริ่มต้น
ตัวอย่าง Vanilla FXServer ของ Cfx.re ใช้
30120
โดยกำหนดทั้ง
TCP 30120
UDP 30120
ผ่าน endpoint_add_tcp และ endpoint_add_udp
③ Port 30120 เปลี่ยนได้ไหม
เปลี่ยนได้
เช่น
30121
30122
30200
30500
ตราบใดที่ Port นั้น
ไม่ชน Service อื่น
FXServer Bind ได้
Firewall อนุญาต
NAT/Port Forwarding ถูกต้อง
ผู้เล่นใช้ Port ถูก
④ ตั้ง Port FiveM ที่ไหน
เปิด
server.cfg
หา
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
แล้วเปลี่ยน Port ตามต้องการ
⑤ ตัวอย่างเปลี่ยนเป็น Port 30121
จาก
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
เป็น
endpoint_add_tcp "0.0.0.0:30121"
endpoint_add_udp "0.0.0.0:30121"
จากนั้น Save และ Restart FXServer
⑥ ต้องเปลี่ยนทั้ง TCP และ UDP ไหม
สำหรับ Setup ปกติที่ต้องการใช้ Port เดียวกัน ควรเปลี่ยนให้ตรงกัน
เช่น
endpoint_add_tcp "0.0.0.0:30200"
endpoint_add_udp "0.0.0.0:30200"
แล้วจัด Firewall ให้รองรับ
TCP 30200
UDP 30200
⑦ TCP กับ UDP ต่างกันอย่างไร
FiveM Connection มี Traffic หลายรูปแบบ
Cfx.re ระบุว่ากระบวนการเชื่อมต่อสามารถเกี่ยวข้องกับทั้ง
HTTP/TCP
Raw TCP
UDP
จึงไม่ควรตั้ง Network โดยคิดว่า FiveM ใช้ Protocol เดียวทั้งหมด
⑧ 0.0.0.0 ต้องเปลี่ยนไหม
โดยทั่วไปไม่ต้อง
Cfx.re ระบุใน Vanilla Configuration ว่าให้เปลี่ยน IP เฉพาะเมื่อเครื่องมีหลาย Network Interfaces และต้องการเลือก Interface เฉพาะ
Server ปกติสามารถใช้
0.0.0.0
ต่อไปได้
⑨ อย่าใส่ Public IP แทน 0.0.0.0 แบบสุ่ม
สมมุติ Public IP คือ
203.0.113.10
ไม่ได้หมายความว่าต้องเปลี่ยนเป็น
endpoint_add_tcp "203.0.113.10:30120"
เพราะเครื่องที่อยู่หลัง NAT อาจไม่ได้มี Public IP นี้บน Network Interface โดยตรง
ใช้ Binding Address ให้สอดคล้องกับ Network Architecture จริง
⑩ Port 30120 กับ 40120 ต่างกันอย่างไร
อย่าสับสน
30120
= FiveM Game Port ค่าเริ่มต้น
40120
= txAdmin HTTP Port ค่าเริ่มต้น
เปลี่ยน Game Port ไม่จำเป็นต้องเปลี่ยน txAdmin Port
⑪ ตัวอย่าง Server หนึ่งเครื่อง
อาจใช้
FiveM Game
TCP/UDP 30120
txAdmin
TCP 40120
ผู้เล่นใช้ 30120
Admin เข้า txAdmin ผ่าน 40120
⑫ วิธีตั้ง Port สำหรับ Server ตัวแรก
ตัวอย่าง
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
ใช้เป็น Production Server ตัวแรกได้
ถ้า Port ไม่ชนและ Network อนุญาต
⑬ Server ตัวที่สองใช้ Port เดิมได้ไหม
ถ้าอยู่ IP/Interface เดียวกันและ Instance แรก Bind Port เดิมอยู่แล้ว จะเกิด Port Conflict ได้
ดังนั้นควรใช้คนละ Port
เช่น Server 2
endpoint_add_tcp "0.0.0.0:30121"
endpoint_add_udp "0.0.0.0:30121"
⑭ ตัวอย่างหลาย FiveM Server
Production
Game Port = 30120
Development
Game Port = 30121
Test
Game Port = 30122
จัดแบบนี้ดูแลง่ายกว่าการสุ่มหมายเลข Port
⑮ txAdmin หลาย Instance ก็ต้องแยก Port
ตัวอย่าง
Production
Game = 30120
txAdmin = 40120
Development
Game = 30121
txAdmin = 40121
Test
Game = 30122
txAdmin = 40122
ป้องกัน Port Conflict ทั้ง Game และ Management Panel
⑯ เปลี่ยน Game Port แล้วต้อง Restart ไหม
ควร Restart FXServer
เพราะ Endpoint ถูก Bind ตอน Server Startup
Workflow คือ
แก้ server.cfg
↓
Save
↓
Restart FXServer
↓
ดู Console
↓
ตรวจ Port
⑰ ดู Console หลัง Restart หาอะไร
ตรวจว่าไม่มี Error เช่น
address already in use
failed to bind
endpoint error
ถ้ามีข้อความเกี่ยวกับ Port ให้แก้ก่อนทดสอบจาก Internet
⑱ วิธีดูว่า Port ถูกใช้อยู่บน Windows
เปิด Command Prompt
netstat -ano | findstr :30120
ถ้ากำลังตรวจ Port ใหม่ เช่น 30121
ใช้
netstat -ano | findstr :30121
⑲ PID ที่เห็นคืออะไร
ผลจาก netstat สามารถแสดง PID ของ Process
จากนั้นตรวจ Process ได้ เช่น
tasklist /FI "PID eq 1234"
เปลี่ยน 1234 เป็น PID จริง
ช่วยหาว่า Program ใดกำลังใช้ Port
⑳ PowerShell ตรวจ TCP Port ได้ไหม
ได้
ตัวอย่าง
Get-NetTCPConnection -LocalPort 30120
เหมาะสำหรับตรวจ TCP Listener/Connection
แต่จำไว้ว่าการตรวจ TCP อย่างเดียวไม่ได้ยืนยัน UDP ทั้งหมด
㉑ Linux ตรวจ Port อย่างไร
ใช้
ss -lntup | grep 30120
หรือเปลี่ยนเป็น Port ที่กำลังใช้งาน
ss -lntup | grep 30121
ถ้า Server Running แต่ไม่พบ Endpoint ให้กลับไปตรวจ server.cfg และ Console
㉒ Windows Firewall ต้องตั้งอย่างไร
ถ้าใช้ Port 30120 ควรมี Inbound Rules ที่เหมาะสมสำหรับ
TCP 30120
UDP 30120
ไม่แนะนำให้ปิด Windows Firewall ทั้งระบบเพียงเพื่อให้ FiveM เข้าได้
㉓ ตัวอย่างเปิด TCP บน Windows Firewall
PowerShell แบบ Administrator สามารถใช้แนวทาง
New-NetFirewallRule -DisplayName "FiveM TCP 30120" -Direction Inbound -Protocol TCP -LocalPort 30120 -Action Allow
㉔ ตัวอย่างเปิด UDP
New-NetFirewallRule -DisplayName "FiveM UDP 30120" -Direction Inbound -Protocol UDP -LocalPort 30120 -Action Allow
ถ้าเปลี่ยนเป็น 30121 ต้องเปลี่ยน Rule ให้ตรงกัน
㉕ Linux UFW ตัวอย่าง
ถ้า Server ใช้ UFW สามารถกำหนดตามแนวคิด
sudo ufw allow 30120/tcp
sudo ufw allow 30120/udp
จากนั้นตรวจ
sudo ufw status
ก่อนใช้งานจริงต้องตรวจ Security Policy ของเครื่องด้วย
㉖ Cloud Firewall ต้องเปิดด้วยไหม
ต้องตรวจ
VPS บางรายมี Firewall อีกชั้น
ดังนั้นแม้ Windows/Linux Firewall เปิดแล้ว ยังอาจเป็น
Internet
↓
Cloud Firewall BLOCK
↓
OS Firewall ALLOW
↓
FXServer
ผลคือผู้เล่นยังเข้าไม่ได้
㉗ Security Group ต้องตั้งด้วยไหม
ถ้า Provider ใช้ระบบ Security Group ต้องเพิ่ม Inbound Rule ตาม Port ที่ใช้
เช่น
TCP 30120
UDP 30120
ชื่อเมนูอาจแตกต่างกัน เช่น
Firewall
Security Group
Network ACL
Inbound Rules
㉘ Server บ้านต้อง Port Forwarding ไหม
ถ้า Server อยู่หลัง Router/NAT และต้องการให้ผู้เล่นจาก Internet เข้า โดยทั่วไปต้อง Forward Port
แนวคิด
Internet
↓
Public IP:30120
↓
Router
↓
192.168.1.100:30120
↓
FXServer
㉙ Port Forwarding ต้องชี้ไปที่ IP ไหน
ต้องชี้ไป Local IP ของเครื่อง FiveM Server
ตัวอย่าง
Server Local IP
192.168.1.100
Rule จึงเป็นแนวคิด
External TCP 30120
→ 192.168.1.100:30120
External UDP 30120
→ 192.168.1.100:30120
㉚ Local IP ควรเปลี่ยนไปมาหรือไม่
ถ้า Router แจก IP ด้วย DHCP และ Local IP ของ Server เปลี่ยน อาจทำให้ Port Forwarding ชี้ผิดเครื่อง
ควรใช้
DHCP Reservation
หรือ Static IP Configuration ที่ถูกต้อง
เพื่อให้ FiveM Server ได้ Local IP เดิม
㉛ CGNAT ทำให้ Port Forward ไม่ได้ไหม
ได้
ถ้า ISP ใช้ Carrier-Grade NAT คุณอาจไม่มี Public IPv4 ที่รับ Incoming Connection มาถึง Router โดยตรง
อาการที่พบบ่อยคือ
LAN เข้าได้
Port Forward ตั้งแล้ว
แต่ Internet ยังเข้าไม่ได้
กรณีนี้ต้องตรวจกับ ISP หรือเปลี่ยน Network Architecture
㉜ Double NAT คืออะไร
ตัวอย่าง
Internet
↓
ISP Router
↓
Router ส่วนตัว
↓
FiveM Server
ถ้าทั้งสองอุปกรณ์ทำ NAT การ Forward แค่ Router ชั้นในอาจไม่พอ
ต้องแก้ Network Architecture ให้ Traffic มาถึง Server จริง
㉝ VPS มี Public IP ต้อง Port Forward ไหม
ส่วนใหญ่ VPS ที่ได้รับ Public IP โดยตรงจะไม่ต้องใช้ Router Port Forwarding แบบบ้าน
แต่ยังต้องตรวจ
Provider Firewall
OS Firewall
Routing
ให้ครบ
㉞ วิธีทดสอบ Port หลังตั้งค่า
เริ่มจาก Server เครื่องเดียวกันก่อน
เปิด Browser
http://127.0.0.1:30120/info.json
ถ้าเปลี่ยน Port เป็น 30121
ใช้
http://127.0.0.1:30121/info.json
㉟ info.json เปิดได้หมายความว่าอะไร
หมายความว่า HTTP Connect Endpoint สามารถตอบกลับในเส้นทางที่กำลังทดสอบได้
ถือเป็นสัญญาณที่ดี
แต่ไม่ได้พิสูจน์ว่าทุก UDP/TCP Game Traffic จาก Internet ผ่านครบแล้ว
ต้องทดสอบ FiveM Client จริงด้วย
㊱ ทดสอบจากเครื่องอื่นใน LAN
สมมุติ Server Local IP คือ
192.168.1.100
ลอง
http://192.168.1.100:30120/info.json
ถ้า Localhost เข้าได้แต่ LAN เข้าไม่ได้ ให้สงสัย Local Firewall หรือ Interface/Network Policy
㊲ ทดสอบจาก Internet
ใช้เครื่องที่อยู่นอก Network Server ทดสอบ Public Address
ตัวอย่าง
http://PUBLIC_IP:30120/info.json
ถ้า LAN ผ่านแต่ Public ไม่ผ่าน ให้ตรวจ
Router
NAT
CGNAT
Cloud Firewall
Public IP
㊳ ทดสอบ FiveM Direct Connect
เปิด FiveM แล้วกด
F8
พิมพ์
connect PUBLIC_IP:30120
ถ้าเปลี่ยนเป็น 30121
ต้องใช้
connect PUBLIC_IP:30121
㊴ ถ้าไม่พิมพ์ Port จะเกิดอะไร
สำหรับ Bare Host/IP ระบบ Connection ของ Cfx.re ใช้ 30120 เป็น Default
ดังนั้น
connect play.example.com
เหมาะเมื่อ Endpoint ใช้ Default 30120
ถ้าใช้ Port อื่นควรระบุ
connect play.example.com:30121
㊵ เปลี่ยน Port แล้ว Domain ต้องแก้ไหม
ถ้า Domain ยังชี้ Public IP เดิม DNS อาจไม่ต้องเปลี่ยน
แต่ Connection Address ต้องรู้ Port ใหม่
เช่น
play.example.com:30121
DNS ปกติไม่ได้เปลี่ยน TCP/UDP Port ให้เอง
㊶ Port Check Website เช็ก UDP ได้ครบไหม
ต้องระวัง
Port Checker บนเว็บจำนวนมากตรวจเฉพาะ TCP
ดังนั้นผลว่า
30120 OPEN
อาจยืนยันเพียง TCP
ไม่ได้ยืนยัน UDP Game Traffic
วิธีที่ดีที่สุดคือทดสอบ FiveM Client จริงจาก Network ภายนอก
㊷ เปลี่ยน Port ช่วย Server ไม่ Lag ไหม
ไม่
เปลี่ยน
30120
เป็น
30121
ไม่ได้ทำให้ CPU หรือ Network เร็วขึ้น
Port เป็นหมายเลข Endpoint ไม่ใช่ Performance Setting
㊸ เปลี่ยน Port ป้องกัน DDoS ได้ไหม
ไม่ถือเป็น DDoS Protection
Attacker ยังสามารถ Scan หรือค้นพบ Port ได้
การป้องกัน DDoS ต้องใช้ระบบอย่าง
Provider Filtering
Network Protection
Firewall Architecture
Proxy
Rate Controls
ตามความเหมาะสม
㊹ ใช้ Reverse Proxy ได้ไหม
FiveM รองรับ Advanced Proxy Setup
แต่ต้องเข้าใจว่ามีทั้ง
Connect Endpoint
และ
Raw TCP/UDP Server Endpoint
HTTP Reverse Proxy ธรรมดาไม่ได้ Proxy UDP Game Traffic ให้อัตโนมัติ
㊺ TCP Port กับ UDP Port จำเป็นต้องเท่ากันไหม
Configuration ปกติใช้ Port เดียวกัน เช่น
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
แต่ Architecture ขั้นสูงสามารถมีการแยกหรือ Proxy Endpoint ได้
ไม่ควรทำจนกว่าจะเข้าใจ Connection Flow ของ FiveM
㊻ เปลี่ยน TCP อย่างเดียวได้ไหม
ใน Setup Proxy ขั้นสูงบางแบบทำได้ และ Cfx.re มีตัวอย่าง Local TLS Proxy ที่ใช้ TCP ภายในต่างจาก UDP
แต่ Server ทั่วไปไม่จำเป็นต้องทำให้ซับซ้อน
หากเพียงต้องการเปลี่ยน Game Port ให้ใช้ TCP/UDP Port เดียวกันจะดูแลง่ายกว่า
㊼ Server ไม่ขึ้น Server List หลังเปลี่ยน Port
ตรวจ
endpoint_add_tcp
endpoint_add_udp
Firewall TCP
Firewall UDP
Cloud Firewall
Port Forwarding
Public IP
Direct Connect
sv_projectName
sv_projectDesc
Cfx.re ระบุว่าปัญหา Server ไม่ขึ้น List มักเกี่ยวข้องกับ Port Forwarding หรือ Firewall
㊽ Checklist เปลี่ยน FiveM Port
ก่อนเปิดให้ผู้เล่นเข้า ตรวจ
Backup server.cfg
เลือก Port ใหม่แล้ว
Port ไม่ชน
แก้ endpoint_add_tcp
แก้ endpoint_add_udp
Save server.cfg
Restart FXServer
Console ไม่มี Bind Error
Windows/Linux Firewall ถูก
Cloud Firewall ถูก
Port Forwarding ถูกถ้ามี NAT
Public IP ถูก
info.json ใช้งานได้
Direct Connect ใช้งานได้
Server List ปกติ
㊾ ตัวอย่าง Config หลาย Server ที่เป็นระเบียบ
Production
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
Development
endpoint_add_tcp "0.0.0.0:30121"
endpoint_add_udp "0.0.0.0:30121"
Test
endpoint_add_tcp "0.0.0.0:30122"
endpoint_add_udp "0.0.0.0:30122"
แล้วตั้ง txAdmin แต่ละ Instance ให้ใช้ Management Port คนละตัวเช่นกัน
㊿ สรุปวิธีตั้ง Port FiveM Server
วิธีตั้ง Port FiveM ที่ถูกต้องเริ่มจากแก้ server.cfg
ตัวอย่าง Port Default
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
ถ้าต้องการเปลี่ยนเป็น 30121
endpoint_add_tcp "0.0.0.0:30121"
endpoint_add_udp "0.0.0.0:30121"
จากนั้นทำตามลำดับ
1. Save server.cfg
2. Restart FXServer
3. ตรวจ Console
4. ตรวจ Port ไม่ชน
5. เปิด TCP Firewall
6. เปิด UDP Firewall
7. แก้ Cloud Firewall ถ้ามี
8. แก้ Port Forwarding ถ้าอยู่หลัง Router
9. ทดสอบ info.json
10. ทดสอบ Direct Connect จากภายนอก
สำหรับ Production Server comsiam แนะนำให้กำหนด Port เป็นระบบตั้งแต่ต้น โดยเฉพาะหากมี Production, Development และ Test Instance หลายตัว
ตัวอย่าง
Production → 30120
Development → 30121
Test → 30122
และต้องจำว่า 40120 เป็น Default Port ของ txAdmin ไม่ใช่ Game Port
สิ่งสำคัญที่สุดคือ การแก้ Port ใน server.cfg ไม่ได้เปิด Firewall หรือ Router ให้อัตโนมัติ ทุก Layer ของ Network ต้องใช้ค่าที่สัมพันธ์กัน
เมื่อ Server ของ comsiam สามารถตอบ info.json และ FiveM Client จาก Network ภายนอกสามารถใช้
connect SERVER_IP:PORT
เข้าได้สำเร็จ จึงถือได้ว่า Game Endpoint ผ่านการทดสอบจากภายนอกในระดับใช้งานจริงแล้ว
Comments
Post a Comment