2016年3月12日 星期六

iptables 摘要


sudo iptables -L -n

sudo iptables-save

阻來源 IP
sudo iptables -I INPUT -s 192.168.100.100 -j REJECT

刪除一條 iptables 規則,"INPUT 2" 代表 iptables list 中的第二條規格。
sudo iptables -D INPUT 2

將目前的防火牆設定備份為自訂檔案 /etc/iptables-custom
sudo iptables-save >/etc/iptables-custom

使用自訂檔案 /etc/iptables-custom 覆蓋防火牆設定
sudo iptables-restore /etc/iptables-custom

保存並重新啟動
sudo chkconfig iptables on
sudo service iptables save
sudo service iptables restart
※  iptables 規則一經設定新增或刪除立即生效,但如不儲存重新啟動後會載入舊設定檔。

Disable Ping using iptables
sudo iptables -I INPUT -p icmp --icmp-type echo-request -j REJECT

參考一
參考二
Disable Ping

範例
 [root@host ~]# iptables-save
# Generated by iptables-save v1.4.7 on Sat Mar 12 21:53:55 2016
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [1620522:1635253221]
-A INPUT -s 192.168.100.22/32 -j REJECT --reject-with icmp-port-unreachable
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 25 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 993 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 995 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 110 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 143 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited


沒有留言:

張貼留言