歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> Linux系統下iptables基本配置方法

Linux系統下iptables基本配置方法

日期:2017/2/28 16:18:49   编辑:Linux教程

1、查看本機關於IPTABLES的設置情況
[[email protected] /]# iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination

Chain FORWARD (policy ACCEPT)
target prot opt source destination

Chain OUTPUT (policy ACCEPT)
target prot opt source destination

Chain RH-Lokkit-0-50-INPUT (0 references)
target prot opt source destination

2、清除原有規則
[[email protected] /]# iptables -F

3、保存配置的規則並生效,每次更新規則後都需要操作
[[email protected] /]# /etc/rc.d/init.d/iptables save
[[email protected] /]# service iptables restart

4、設定預設規則
[[email protected] /]# iptables -P INPUT DROP
[[email protected] /]# iptables -P OUTPUT ACCEPT
[[email protected] /]# iptables -P FORWARD DROP
上面的意思是,當超出了IPTABLES裡filter表裡的兩個鏈規則(INPUT,FORWARD)時,不在這兩個規則裡的數據包怎麼處理呢,那就是DROP(放棄).
而對於OUTPUT鏈,也就是流出的包,不用做太多限制,而是采取ACCEPT,也就是說,不在著個規則裡的包怎麼辦呢,那就是通過.

5、添加新設規則示例
#為了能采用遠程SSH登陸,要開啟22端口.
[[email protected] /]# iptables -A INPUT -p tcp --dport 22 -j ACCEPT

#打開WEB服務端口的tcp協議
iptables -A INPUT -p tcp --dport 80 -j ACCEPT

#打開POP3服務端口的tcp協議
[[email protected] /]# iptables -A INPUT -p tcp --dport 110 -j ACCEPT

#打開SMTP服務端口的tcp協議
[[email protected] /]# iptables -A INPUT -p tcp --dport 25 -j ACCEPT

#打開FTP服務端口的tcp協議
[[email protected] /]# iptables -A INPUT -p tcp --dport 21 -j ACCEPT
[[email protected] /]# iptables -A INPUT -p tcp --dport 20 -j ACCEPT

#允許IP地址為202.106.12.130這台主機連接本地的SSH服務端口
[[email protected] /]# iptables -A INPUT -p tcp -s 202.106.12.130 --dport 22 -j ACCEPT

#允許DNS服務端口的tcp數據包流入
[[email protected] /]# iptables -A INPUT -p tcp --dport 53 -j ACCEPT

Copyright © Linux教程網 All Rights Reserved