ตัวอย่าง
ต้องการติดตั้ง iptables ใน CentOS โดยเพิ่ม Rule ใน Input Chain ให้สามารถ Connect จาก Client ผ่าน Port 9999
1. สร้าง VM CentOS 7 ด้วย Vagrant
- สร้างไฟล์
Vagrantfile
- Boot VM ด้วย คำสั่ง
$ vagrant up
- Connect เข้า CentOS ผ่าน SSH
$ vagrant ssh
2. ติดตั้ง iptables
- ติดตั้ง
iptables-services
และ Enable ผ่านsystemctl
$ sudo yum install iptables-services
$ sudo systemctl enable iptables
$ sudo systemctl start iptables
3. ลบ Reject Rule
จากภาพจะเห็นว่าใน Input Chain มี Rule ที่ Reject all ในบรรทัดที่ 5 ให้ลบบรรทัดนี้ออก ด้วยคำสั่ง
$ sudo iptables -D INPUT 5
4. เพิ่ม Accept Rule สำหรับ Port 9999
$ sudo iptables -A INPUT -p tcp --dport 9999 -j ACCEPT
5. บันทึก Rule ใน iptables
$ sudo service iptables save
6. จำลอง HTTP Server ด้วย Python
$ python -m SimpleHTTPServer 9999
7. ทดสอบ Accept Rule ด้วย Web Browser
เข้าไปที่ http://192.168.50.10:9999