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

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

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

Linux Updated: January 16, 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 ไม่ยากเท่าที่คิด แต่เป็นสิ่งที่สำคัญมากเพื่อป้องกันระบบของคุณจากภัยคุกคามที่อาจเกิดขึ้น

D

DRITESTUDIO

DRITESTUDIO COMPANY LIMITED - Cloud, VPS, Hosting and Colocation provider in Thailand

Manage your cookie settings

We use different types of cookies to optimize your experience on our website. Click on the categories below to learn more and customize your preferences. Note that blocking some types of cookies may impact your experience.

Necessary Cookies

These cookies are essential for the website to function properly. They enable basic functions like page navigation and access to secure areas.

View cookies used
  • Session cookies (session management)
  • Security cookies (CSRF protection)
Always On

Functional Cookies

These cookies enable personalized features like language preferences and theme settings. Without these, some features may not work properly.

View cookies used
  • lang (language preference)
  • theme (dark/light mode)

Analytics Cookies

These cookies help us understand how visitors interact with our website by collecting and reporting information anonymously.

View cookies used
  • _ga (Google Analytics)
  • _gid (Google Analytics)

Marketing Cookies

These cookies are used to track visitors across websites to display relevant advertisements based on your interests.

View cookies used
  • Advertising cookies
  • Remarketing pixels

Privacy Policy