DriteStudio
DRITESTUDIODigital Infrastructure
Home
ArticlesAbout UsContact

Services

VPSHigh-performance virtual servers with full root access
Web HostingManaged hosting with Plesk and free SSL
Dedicated ServerEnterprise hardware with IPMI access
ColocationSecure data center space for your servers
SecurityWAF, DDoS Protection & 24/7 SOC Monitoring
StatusCheck system uptime and service availability

Quick Links

View All ServicesDocumentationContact Sales
Home
VPSHigh-performance virtual servers with full root access
Web HostingManaged hosting with Plesk and free SSL
Dedicated ServerEnterprise hardware with IPMI access
ColocationSecure data center space for your servers
SecurityWAF, DDoS Protection & 24/7 SOC Monitoring
StatusCheck system uptime and service availability
Articles
About Us
Contact
0%
การทำ NAT เบื่องต้นในเครื่องลินุกซ์
Back to articles

การทำ NAT เบื่องต้นในเครื่องลินุกซ์

การทำ NAT เป็นสิ่งที่สำคัญเมื่อคุณมี Public IP แค่ไอพีเดียวแต่อยากเข้าถึงเครื่องภายในวงเน็ตจากภายนอก

Linux-August 11, 2023-Updated: March 13, 2026

การตั้งค่า NAT Port Forwarding ด้วย iptables ใน Linux

1. ตั้งค่า PREROUTING

คำสั่งนี้จะรับข้อมูล TCP ที่เข้ามาที่อินเตอร์เฟซ ens3f1 บนพอร์ต 3390 แล้วนำไปสู่ IP ภายใน 192.168.122.154 บนพอร์ต 3389.

sudo iptables -t nat -A PREROUTING -p tcp -i ens3f1 --dport 3390 -j DNAT --to-destination 192.168.122.154:3389

2. ตั้งค่า FORWARD

คำสั่งนี้จะอนุญาตให้ส่งแพ็กเก็ต TCP ที่มีปลายทางเป็น IP 192.168.122.154 บนพอร์ต 3389 หากการเชื่อมต่อเป็นใหม่, ตั้งค่าแล้ว, หรือเกี่ยวข้อง.

sudo iptables -A FORWARD -p tcp -d 192.168.122.154 --dport 3389 -m state --state NEW,ESTABLISHED,RELATED -j ACCEPT

3. บันทึกการตั้งค่า iptables

คำสั่งนี้จะบันทึกการตั้งค่า iptables ปัจจุบันเพื่อไม่ให้กฎหายหลังจากการเริ่มระบบใหม่.

sudo iptables-save

หมายเหตุ: หากทำ NAT ในเซิฟเกมหรือเซอวิซที่มีการใช้ authenticate ด้วยไอพีอาจจำเป็นต้องใช้ คำสั่ง:

sudo iptables -t nat -A POSTROUTING -j MASQUERADE

เพื่อให้เปลี่ยนไอพีของไคเอนเป็น Public IP

Share article:
View more articles
D

DriteStudio | ไดรท์สตูดิโอ

Cloud, VPS, Hosting and Colocation provider in Thailand

Operated by Craft Intertech (Thailand) Co., Ltd.

DRITESTUDIO
DRITESTUDIODigital Infrastructure

100/280 Soi 17, Delight Village, Bang Khun Thian - Chaitalay, Phanthai Norasing, Samut Sakhon 74000

Services

  • VPS Hosting
  • Web Hosting
  • Dedicated Server
  • Colocation
  • Security Solutions

Company

  • About Us
  • Contact Us
  • System Status

Resources

  • Documentation
  • Help Center
  • Articles

Legal

  • Terms of Service
  • Privacy Policy
  • Refund Policy

© 2026 Craft Intertech (Thailand) Co., Ltd. All rights reserved.

We use cookies

We use cookies to enhance your browsing experience, analyze site traffic, and personalize content. By clicking "Accept All", you consent to our use of cookies. Privacy Policy