ทดสอบ Network Speed ด้วย iPerf3 บน VPS
iPerf3 คือ tool มาตรฐาน industry สำหรับวัด TCP/UDP bandwidth ระหว่างสอง endpoint ต่างจากการดาวน์โหลดไฟล์ทดสอบ iPerf3 วัด throughput จริงของ network ไม่ใช่ web server performance ใช้สำหรับตรวจสอบว่า VPS ให้ bandwidth ตามที่สัญญาไว้ หรือ debug ปัญหา network bottleneck
ติดตั้ง iPerf3
# Ubuntu/Debian (ทั้ง server และ client)
sudo apt install iperf3 -y
# CentOS/RHEL
sudo yum install iperf3 -y
# macOS
brew install iperf3
# ตรวจ
iperf3 --version
รัน Server Mode บน VPS
# รัน iperf3 ใน server mode (port 5201 โดย default)
iperf3 -s
# รัน background และฟัง port อื่น
iperf3 -s -p 5201 -D
# เปิด firewall
sudo ufw allow 5201/tcp
ทดสอบจาก Client
# Test TCP bandwidth 10 วินาที
iperf3 -c VPS_IP
# Test ด้วย multiple threads (วัด max throughput)
iperf3 -c VPS_IP -P 4
# Test นานขึ้น (60 วินาที)
iperf3 -c VPS_IP -t 60
# Test ทั้งขาไปและขากลับ
iperf3 -c VPS_IP --bidir
# Test UDP (วัด latency/jitter)
iperf3 -c VPS_IP -u -b 100M
อ่านผลลัพธ์
# ตัวอย่าง output TCP test:
[ ID] Interval Transfer Bitrate
[ 5] 0.00-10.00 sec 1.25 GBytes 1.07 Gbits/sec sender
[ 5] 0.00-10.00 sec 1.25 GBytes 1.07 Gbits/sec receiver
# Transfer = ข้อมูลที่ส่ง
# Bitrate = bandwidth (1.07 Gbps = ดี)
# ตัวอย่าง UDP test:
# Jitter = ความแปรปรวนของ latency (ต่ำ = ดี สำหรับ video/VoIP)
# Lost = packet ที่หาย (0% = ดี)
Test ระหว่าง 2 VPS
# VPS A (server): iperf3 -s
# VPS B (client): iperf3 -c VPS_A_IP
# ใช้สำหรับทดสอบ network ระหว่าง datacenter
# เช่น TH VPS ↔ SG VPS latency และ bandwidth
Public iPerf3 Servers สำหรับทดสอบ
# ไม่มี client ตัวที่สอง ใช้ public server ทดสอบได้
# ตรวจ latency จาก VPS ไทยไปสิงคโปร์:
iperf3 -c bouygues.testdebit.info -p 5209
# หรือ
ping -c 10 sg.speedtest.xtom.com
iperf3 -c sg.speedtest.xtom.com -p 5201
ตรวจสอบว่า iPerf3 ทำงานถูกต้อง
# ตรวจ port เปิดอยู่
ss -tlnp | grep 5201
# ทดสอบ loopback (ควรได้ ~10 Gbps+ บน local)
iperf3 -c 127.0.0.1
# ตรวจ firewall อนุญาต port
sudo ufw status | grep 5201
# ดู process
pgrep -l iperf3
iperf3 -c VPS_IP -J | python3 -c "import sys,json; r=json.load(sys.stdin); print(r['end']['sum_received']['bits_per_second']/1e6, 'Mbps')"
แก้ปัญหาที่พบบ่อย
Error: "connect failed: Connection refused"
iPerf3 server ไม่รัน หรือ firewall block port 5201:
ssh ubuntu@VPS_IP "iperf3 -s -D"
sudo ufw allow 5201/tcp
# ทดสอบอีกครั้ง
Bandwidth ต่ำกว่าที่คาด (1 Gbps plan แต่ได้ 100 Mbps)
อาจเป็น TCP window size ที่เล็กเกินไป เพิ่มด้วย -w flag:
iperf3 -c VPS_IP -w 4M # เพิ่ม TCP window size
iperf3 -c VPS_IP -P 8 # เพิ่ม parallel streams
UDP test แสดง packet loss สูง
Rate ที่ส่งสูงกว่า bandwidth จริง ลด rate:
# ลดจาก 100M เป็น 50M
iperf3 -c VPS_IP -u -b 50M
iPerf3 server หยุดหลัง test เดียว
Default behavior รับ 1 connection แล้วหยุด ใช้ --daemon หรือ loop:
# รันตลอด
iperf3 -s --daemon
# หรือรัน loop
while true; do iperf3 -s; done
คำถามที่พบบ่อย
iPerf3 กับ speedtest-cli ต่างกันอย่างไร?
speedtest-cli วัด bandwidth ไปยัง speedtest.net servers ที่อาจมีผลจาก CDN iPerf3 วัด raw network throughput ระหว่าง 2 endpoints โดยตรง ให้ค่าที่แม่นยำกว่าสำหรับ VPS-to-VPS หรือ VPS-to-client benchmarks
ต้องการ root เพื่อรัน iPerf3 ไหม?
ไม่จำเป็น user ปกติรัน iPerf3 ได้ เว้นแต่ต้องการ bind port ต่ำกว่า 1024 หรือตั้ง QoS/TOS bits ซึ่งต้องการ CAP_NET_ADMIN
วัด latency ด้วย iPerf3 ได้ไหม?
ไม่โดยตรง iPerf3 วัด bandwidth/throughput ใช้ ping หรือ mtr สำหรับ latency measurement iPerf3 UDP mode แสดง jitter ซึ่งเกี่ยวข้องกับ latency variation แต่ไม่ใช่ absolute latency