DriteStudio
DRITESTUDIOCloud Infrastructure
Home
ArticlesAbout UsContactStatus
0%
วิธีทำไฟล์วอลเบื่องต้นในลินุกซ์
Back to articles

วิธีทำไฟล์วอลเบื่องต้นในลินุกซ์

การป้องกันระบบคอมพิวเตอร์จากการเข้าถึงที่ไม่ได้รับอนุญาตเป็นสิ่งที่สำคัญในยุคดิจิทัลนี้ และ "ไฟร์วอลล์" เป็นเครื่องมือที่สำคัญในการทำให้ระบบของเราปลอดภัย

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

การตั้งค่าไฟร์วอลล์พื้นฐานใน Linux ด้วย IPTables

ติดตั้ง IPTables

ถ้ายังไม่ได้ติดตั้ง iptables, คุณสามารถทำได้ด้วยคำสั่ง:

sudo apt-get install iptables

ตั้งกฏพื้นฐานเริ่มต้น

ตั้งค่าให้ปฏิเสธการเข้าถึงทั้งหมดก่อน:

sudo iptables -P INPUT DROP
sudo iptables -P FORWARD DROP
sudo iptables -P OUTPUT ACCEPT

อนุญาตการเชื่อมต่อเข้าและออกจากเครื่อง

ถ้าคุณต้องการอนุญาตให้การเชื่อมต่อเข้าและออกจากเครื่องทำงาน:

sudo iptables -A INPUT -i eth0 -j ACCEPT
sudo iptables -A OUTPUT -o eth0 -j ACCEPT

อนุญาตการเชื่อมต่อที่เกี่ยวข้องและตอบกลับ

sudo iptables -A INPUT -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT

การบล็อก IP หรือช่วง IP ที่เฉพาะเจาะจง

(แทนที่ xxx.xxx.xxx.xxx ด้วย IP ที่คุณต้องการบล็อก)

sudo iptables -A INPUT -s xxx.xxx.xxx.xxx -j DROP

การบันทึกกฎไฟร์วอลล์

เพื่อให้การตั้งค่านี้ยังคงอยู่หลังจากการรีสตาทเครื่อง, คุณต้องบันทึกกฎ:

sudo sh -c 'iptables-save > /etc/iptables.rules'

และคุณอาจต้องการตั้งค่าให้กฎเหล่านี้โหลดขึ้นมาอัตโนมัติเมื่อเริ่มต้นระบบ.

การตรวจสอบกฎไฟร์วอลล์

sudo iptables -L

บทสรุป

การตั้งค่าไฟร์วอลล์ใน Linux ด้วย iptables ไม่ยากเท่าที่คิด แต่เป็นสิ่งที่สำคัญมากเพื่อป้องกันระบบของคุณจากภัยคุกคามที่อาจเกิดขึ้น

Share article:
View more articles
D

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

Cloud, VPS, Hosting and Colocation provider in Thailand

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

DRITESTUDIOCloud Infrastructure

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

Services

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

Company

  • About Us
  • Contact Us
  • System Status

Support

  • Support Ticket
  • Documentation
  • Help Center

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

Privacy PolicyTerms of ServiceRefund Policy

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