วิธีตั้ง IP และ Port ใน endpoint_add_tcp และ endpoint_add_udp FiveM แบบถูกต้อง
การตั้ง IP และ Port ของ FiveM Server ทำผ่านคำสั่ง endpoint_add_tcp และ endpoint_add_udp ใน server.cfg
สำหรับ Server ทั่วไป Cfx.re ใช้ค่าเริ่มต้นตัวอย่างดังนี้
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
และเอกสารทางการแนะนำว่า ถ้าเครื่อง Server ไม่ได้มี Network Interface หลายตัว โดยทั่วไปไม่จำเป็นต้องเปลี่ยน 0.0.0.0 ให้เปลี่ยนเฉพาะ Port เมื่อต้องการเท่านั้น
ดังนั้น FiveM Server ทั่วไปสามารถเริ่มด้วย
IP Binding = 0.0.0.0
TCP Port = 30120
UDP Port = 30120
แล้วไปกำหนด Firewall, NAT และ Public IP แยกตาม Network จริง
① รูปแบบ endpoint_add_tcp
คำสั่งพื้นฐานคือ
endpoint_add_tcp "IP:PORT"
ตัวอย่าง
endpoint_add_tcp "0.0.0.0:30120"
ใช้สร้างและ Bind TCP Endpoint ของ FXServer
② รูปแบบ endpoint_add_udp
ใช้
endpoint_add_udp "IP:PORT"
ตัวอย่าง
endpoint_add_udp "0.0.0.0:30120"
ใช้สร้าง UDP Endpoint
Address และ Port ต้องถูกต้องและไม่ชนกับการใช้งานที่ทำให้ Bind ไม่สำเร็จ
③ FiveM Server ทั่วไปควรตั้งอย่างไร
ถ้าเป็น Server หนึ่งตัวบนเครื่องปกติ ใช้
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
นี่เป็น Configuration ที่ตรงกับ Vanilla Example ของ Cfx.re
④ 0.0.0.0 คืออะไร
0.0.0.0 ในที่นี้เป็น Bind Address
หมายถึงให้ FXServer Listen ผ่าน IPv4 Interfaces ที่เหมาะสมของเครื่อง
ไม่ได้หมายความว่า Public IP ของ Server คือ
0.0.0.0
⑤ ผู้เล่นต้องใช้ 0.0.0.0 เข้า Server ไหม
ไม่
ผู้เล่นต้องใช้ Address ที่เข้าถึง Server ได้จริง
เช่น
127.0.0.1:30120
192.168.1.100:30120
PUBLIC_IP:30120
play.example.com:30120
ตามตำแหน่งที่เชื่อมต่อ
⑥ Server เครื่องเดียวกันใช้ IP อะไร
ถ้า FiveM Client อยู่เครื่องเดียวกับ FXServer สามารถใช้
connect 127.0.0.1:30120
เพื่อทดสอบ Local Server
⑦ เครื่องอื่นใน LAN ใช้อะไร
สมมุติ FXServer มี Local IP
192.168.1.100
คอมเครื่องอื่นในบ้านใช้
connect 192.168.1.100:30120
โดย server.cfg ยังสามารถใช้
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
เหมือนเดิม
⑧ ผู้เล่นจาก Internet ใช้อะไร
ใช้ Public Address ที่เข้าถึง Server ได้ เช่น
connect PUBLIC_IP:30120
หรือ Domain
connect play.example.com:30120
แต่ Firewall และ NAT ต้องตั้งถูกต้องด้วย
⑨ ต้องเอา Public IP ไปใส่ endpoint หรือไม่
โดยทั่วไป ไม่ต้อง
โดยเฉพาะเครื่องที่อยู่หลัง Router/NAT
ตัวอย่าง
Public IP ที่ Router
203.0.113.10
Local IP ของ Server
192.168.1.100
FXServer ไม่ได้มี 203.0.113.10 อยู่บน Network Interface ของเครื่องโดยตรง
จึงไม่ควร Bind Public IP แบบสุ่ม
⑩ Cfx.re แนะนำเรื่อง IP อย่างไร
Vanilla Configuration ระบุไว้ชัดเจนว่า
เปลี่ยน IP เฉพาะเมื่อใช้ Server
ที่มี Network Interfaces หลายตัว
นอกเหนือจากกรณีนั้น โดยทั่วไปให้เปลี่ยนเฉพาะ Port
⑪ เครื่องมี Network Card เดียวควรใช้แบบไหน
ใช้
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
ง่ายที่สุด
และใช้ Firewall ควบคุมว่า Traffic ใดเข้าถึง Service ได้
⑫ เครื่องมีหลาย Network Interface คืออะไร
ตัวอย่าง Dedicated Server อาจมี
NIC 1 → Public Network
NIC 2 → Private Network
VPN Interface
Docker/Virtual Interface
หากต้องการให้ FXServer Bind เฉพาะ Interface ใด Interface หนึ่ง จึงค่อยกำหนด IP เฉพาะ
⑬ ตัวอย่าง Bind Local IP เฉพาะ
ถ้าเครื่องมี Interface จริง
10.20.0.10
อาจใช้
endpoint_add_tcp "10.20.0.10:30120"
endpoint_add_udp "10.20.0.10:30120"
แต่ต้องมั่นใจว่า IP นี้ถูก Assign อยู่บนเครื่องจริง
⑭ ถ้าใส่ IP ที่ไม่มีอยู่ในเครื่องจะเกิดอะไร
FXServer อาจไม่สามารถ Bind Endpoint ได้
และอาจพบ Error เกี่ยวกับ
bind
address
endpoint
ใน Server Console
ดังนั้นอย่าเดา IP
⑮ วิธีดู IP ของเครื่อง Windows
เปิด Command Prompt
ipconfig
มองหา
IPv4 Address
ของ Network Adapter ที่ Server ใช้จริง
⑯ วิธีดู IP บน Linux
สามารถใช้
ip addr
หรือ
hostname -I
แล้วตรวจ Interface ที่ใช้จริง
⑰ Port 30120 คืออะไร
30120 เป็น Port เริ่มต้นที่ใช้ในตัวอย่าง FiveM Vanilla Server
จึงเห็น Configuration
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
บ่อยที่สุด
⑱ จำเป็นต้องใช้ 30120 เท่านั้นไหม
ไม่จำเป็น
สามารถเปลี่ยนเป็น
30121
30122
30200
31000
ได้ หาก Port นั้นไม่ชนและ Network Configuration ทุกส่วนถูกเปลี่ยนตาม
⑲ ตัวอย่างเปลี่ยน Port เป็น 30121
ใช้
endpoint_add_tcp "0.0.0.0:30121"
endpoint_add_udp "0.0.0.0:30121"
หลัง Save ต้อง Restart FXServer
⑳ ผู้เล่นต้องเปลี่ยน Address ตามไหม
ต้อง
จากเดิม
connect SERVER_IP:30120
เปลี่ยนเป็น
connect SERVER_IP:30121
㉑ Firewall ต้องเปลี่ยนตามไหม
ต้อง
ถ้า Game Port คือ
30121
Firewall ต้องอนุญาต
TCP 30121
UDP 30121
ไม่ใช่เปิด 30120 ต่อไป
㉒ Port Forwarding ต้องเปลี่ยนด้วยไหม
ถ้า Server อยู่หลัง Router ต้องเปลี่ยนด้วย
ตัวอย่าง
TCP 30121
→ 192.168.1.100:30121
UDP 30121
→ 192.168.1.100:30121
Network ทุก Layer ต้องใช้ค่าเดียวกับ FXServer
㉓ Cloud Firewall ต้องเปลี่ยนตามไหม
ถ้าใช้ VPS/Cloud Server ต้องตรวจ
Security Group
Cloud Firewall
Network ACL
Provider Firewall
และอนุญาต Port ใหม่ด้วย
㉔ TCP และ UDP ต้องใช้ Port เดียวกันไหม
สำหรับ Server ทั่วไปแนะนำให้ใช้ Port เดียวกัน
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
เพราะเข้าใจง่ายและลดความผิดพลาด
㉕ สามารถใช้ TCP และ UDP คนละ Port ได้ไหม
ใน Advanced Architecture ทำได้บางกรณี
Cfx.re มีตัวอย่าง Local TLS Proxy ที่ใช้
endpoint_add_udp "0.0.0.0:30120"
endpoint_add_tcp "0.0.0.0:30121"
แต่ Server ปกติไม่ควรทำแบบนี้โดยไม่มีเหตุผล
㉖ ทำไม Proxy Setup ถึงแยก Port
เพราะ TCP Connect Endpoint ถูกนำไปผ่าน Proxy
ส่วน UDP Game Endpoint ยังคงใช้ Port อีกตัว
นี่เป็น Network Architecture ขั้นสูง ไม่ใช่ค่าที่จำเป็นสำหรับ FiveM Server ทั่วไป
㉗ ลำดับ endpoint มีผลใน Proxy Setup ไหม
สำหรับตัวอย่าง Local TLS Proxy ของ Cfx.re มีข้อกำหนดเฉพาะว่า
endpoint_add_udp "0.0.0.0:30120"
endpoint_add_tcp "0.0.0.0:30121"
โดย UDP ต้องถูกระบุก่อน TCP ใน Setup ตัวอย่างนั้นเพื่อให้ Port Change ทำงานถูกต้อง
อย่านำเงื่อนไขนี้ไปเหมารวมกับ Server ธรรมดาทุกกรณี
㉘ เปิด FiveM Server สองตัวในเครื่องเดียวกันอย่างไร
ห้ามให้ทั้งสอง Instance แย่ง Port เดียวกันบน Binding เดียวกัน
ตัวอย่าง Server A
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
Server B
endpoint_add_tcp "0.0.0.0:30121"
endpoint_add_udp "0.0.0.0:30121"
㉙ เปิดสาม Server ทำอย่างไร
ตัวอย่าง
Production → 30120
Development → 30121
Test → 30122
แต่ละ Instance ต้องมี
Game Port
txAdmin Port
Server Data
Config
แยกกันอย่างชัดเจน
㉚ txAdmin Port ต้องแยกด้วยไหม
ถ้ามีหลาย Instance ต้องระวัง txAdmin Port ชนเช่นกัน
ตัวอย่าง
Production
Game = 30120
txAdmin = 40120
Development
Game = 30121
txAdmin = 40121
เพราะ Game Endpoint กับ txAdmin เป็นคนละ Service
㉛ Port ชนจะเห็นอาการอะไร
อาจพบ
Address already in use
Bind failed
Endpoint failed
Server เปิดไม่สมบูรณ์
เพราะ Address/Port ที่ endpoint_add_* ใช้ต้องไม่ถูก Service อื่นครอบครองในแบบที่ขัดกัน
㉜ ตรวจ Port ชนบน Windows
ใช้
netstat -ano | findstr :30120
ถ้าเปลี่ยนเป็น 30121
netstat -ano | findstr :30121
ดู PID ของ Process ที่ใช้ Port
㉝ ตรวจ Process จาก PID
ตัวอย่าง
tasklist /FI "PID eq 1234"
เปลี่ยน 1234 เป็น PID ที่พบจริง
อย่า End Process แบบสุ่มจนกว่าจะรู้ว่าเป็น Service อะไร
㉞ Linux เช็ก Port อย่างไร
ใช้
ss -lntup | grep 30120
ตรวจว่ามี TCP/UDP Endpoint ใดใช้งาน Port อยู่
㉟ Port 30120 กับ 40120 อย่าสับสน
จำง่าย ๆ
30120
→ FiveM Game Endpoint ค่าเริ่มต้น
40120
→ txAdmin Web Port ค่าเริ่มต้น
อย่าเปลี่ยน Game Endpoint เป็น 40120 เพียงเพราะเข้า txAdmin ผ่าน Port นี้
㊱ netPort คืออะไร
FXServer มี Variable
netPort
ซึ่งเกี่ยวข้องกับ Primary Port ที่ใช้ในระบบภายใน เช่น Heartbeat และ Master List Authoring
หากไม่ได้กำหนด Primary Port ไว้ endpoint_add_tcp สามารถเป็นตัวกำหนด Primary Port ได้
Server ทั่วไปไม่จำเป็นต้องตั้ง netPort เพิ่มเอง
㊲ ต้องเพิ่ม netPort 30120 ไหม
สำหรับ Configuration ปกติที่มี
endpoint_add_tcp "0.0.0.0:30120"
ไม่จำเป็นต้องเพิ่ม
netPort 30120
โดยไม่มีเหตุผลเฉพาะ
ลด Config ที่ไม่จำเป็นจะดูแลง่ายกว่า
㊳ sv_endpoints คืออะไร
sv_endpoints คือรายการ IP Address ที่ Client สามารถใช้ Connect ผ่าน UDP
ถ้าค่าว่าง FXServer สามารถใช้ Public IP ที่ Auto-detect ได้
นี่เป็น Configuration ที่เกี่ยวข้องกับ Network ขั้นสูงมากกว่า Server ทั่วไป
㊴ ต้องตั้ง sv_endpoints ทุก Server ไหม
ไม่ต้อง
สำหรับ Server ทั่วไปควรปล่อย Auto-detection ก่อน
ใช้ sv_endpoints เมื่อมี Requirement เช่น Proxy หรือ Multi-IP ที่ต้องกำหนด Endpoint เฉพาะจริง ๆ
㊵ Server บ้านควรตั้ง IP อย่างไร
โดยทั่วไปใช้
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
จากนั้น Router จัดการ
Public IP
↓
Port Forwarding
↓
Local IP ของ FXServer
อย่าเอา Public IP ของ Router มา Bind โดยไม่จำเป็น
㊶ VPS ควรตั้ง IP อย่างไร
VPS ที่มี Network Interface ปกติหนึ่งตัวก็ยังสามารถใช้
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
ได้
จากนั้นเปิด Provider Firewall และ OS Firewall ให้ตรงกับ Port
㊷ Dedicated Server หลาย IP ทำอย่างไร
ถ้ามีหลาย Public IP เช่น
203.0.113.10
203.0.113.11
และ IP ทั้งสองถูก Assign ให้เครื่องจริง สามารถออกแบบให้แต่ละ Instance Bind IP เฉพาะได้
เช่น
endpoint_add_tcp "203.0.113.10:30120"
endpoint_add_udp "203.0.113.10:30120"
แต่ Routing และ Firewall ต้องรองรับด้วย
㊸ หลาย IP ใช้ Port 30120 ซ้ำได้ไหม
เชิง Network อาจทำได้ถ้า Bind คนละ IP และระบบปฏิบัติการ/Service Architecture รองรับ
เช่น
203.0.113.10:30120
203.0.113.11:30120
เป็นคนละ Socket Address
แต่ Setup นี้ควรใช้เฉพาะผู้ดูแลที่เข้าใจ Multi-homing และ Routing แล้ว
㊹ ใช้ 0.0.0.0 แล้วเปิดหลาย Instance Port เดียวกันได้ไหม
โดยทั่วไปไม่ได้ในลักษณะปกติ เพราะ Instance แรกที่ Bind
0.0.0.0:30120
ครอบคลุม IPv4 Interfaces ที่เกี่ยวข้อง
Instance ถัดไปจึงมีโอกาส Bind Port เดิมไม่ได้
ทางง่ายกว่าคือใช้ Port คนละตัว
㊺ หลังแก้ Endpoint ต้องทำอะไร
ทำตามนี้
Save server.cfg
↓
Restart FXServer
↓
ดู Console
↓
ตรวจ Port Listen
↓
ทดสอบ info.json
↓
ทดสอบ Direct Connect
Restart Resource อย่างเดียวไม่พอสำหรับเปลี่ยน Listening Endpoint
㊻ ทดสอบ info.json หลังเปลี่ยน Port
ถ้าใช้ 30120
http://127.0.0.1:30120/info.json
ถ้าใช้ 30121
http://127.0.0.1:30121/info.json
ใช้ Port ใหม่ทุกครั้ง
㊼ ทดสอบ Direct Connect
เปิด FiveM แล้วกด F8
ถ้า Server ใช้ 30120
connect SERVER_IP:30120
ถ้าใช้ 30121
connect SERVER_IP:30121
คำสั่ง connect รองรับ IP Address พร้อม Port โดยตรงตามเอกสาร FiveM
㊽ Config ที่มือใหม่ไม่ควรทำ
อย่าใช้แบบนี้เพราะเห็นจาก Tutorial อื่นโดยไม่เข้าใจ
endpoint_add_tcp "PUBLIC_IP:30120"
endpoint_add_udp "LOCAL_IP:30121"
netPort 30200
sv_endpoints "ANOTHER_IP"
Configuration ที่ซับซ้อนโดยไม่มีเหตุผลจะทำให้ Debug ยากมาก
เริ่มจาก Default ก่อน
㊾ Checklist ตั้ง IP และ Port
ตรวจให้ครบ
ใช้ IP Binding ถูก
ถ้ามี NIC เดียวใช้ 0.0.0.0 ได้
TCP Port ถูก
UDP Port ถูก
Port ไม่ชน
Firewall ตรง Port
Cloud Firewall ตรง Port
Port Forwarding ตรง Port
Public IP ถูก
Server Restart แล้ว
Console ไม่มี Bind Error
info.json ผ่าน
Direct Connect ผ่าน
สำหรับ Server หลาย Instance ให้ตรวจ Port ของแต่ละ Server แยกกัน
㊿ สรุปวิธีตั้ง IP และ Port ใน endpoint_add_tcp และ endpoint_add_udp
สำหรับ FiveM Server ทั่วไป การตั้งที่แนะนำคือ
endpoint_add_tcp "0.0.0.0:30120"
endpoint_add_udp "0.0.0.0:30120"
โดย
0.0.0.0
→ Bind Address
และ
30120
→ Game Port ค่าเริ่มต้น
Cfx.re แนะนำว่า อย่าเปลี่ยน IP ถ้า Server ไม่ได้มี Network Interfaces หลายตัว โดยทั่วไปถ้าต้องการเปลี่ยน ให้เปลี่ยนเพียง Port
เช่น
endpoint_add_tcp "0.0.0.0:30121"
endpoint_add_udp "0.0.0.0:30121"
แล้วต้องแก้
Firewall
Cloud Firewall
Port Forwarding
Direct Connect Address
Monitoring
ให้เป็น 30121 ด้วย
ถ้าเปิด Server หลาย Instance ผู้ดูแล comsiam แนะนำให้จัด Port แบบเรียงกัน เช่น
Production → 30120
Development → 30121
Test → 30122
จะดูแลง่ายและลดโอกาส Port Conflict
ส่วนการ Bind Public IP เฉพาะ, ใช้หลาย Network Interface, แยก TCP/UDP คนละ Port, กำหนด sv_endpoints หรือทำ Reverse Proxy ควรใช้เมื่อมี Requirement จริงและเข้าใจ Network Architecture แล้ว
หลักสำคัญสำหรับ FiveM Server ของ comsiam คือ
endpoint_add_tcp / udp
→ กำหนดว่า FXServer Listen ที่ไหน
Firewall
→ กำหนดว่า Traffic ผ่านได้หรือไม่
Port Forwarding
→ ส่ง Traffic ผ่าน NAT
Public IP / Domain
→ Address ที่ผู้เล่นใช้เข้าถึง Server
เมื่อแยกหน้าที่ทั้งสี่อย่างนี้ออกจากกันได้ การตั้ง IP และ Port ของ FiveM จะตรงไปตรงมา และแก้ปัญหา Server เข้าไม่ได้ได้ง่ายขึ้นมาก
Comments
Post a Comment