使用用戶空間命令iptables實現包過濾

使用用戶空間命令iptables實現包過濾<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

1、          打開內核的包轉發功能

# echo “<?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />1”>/froc/sys/net/ipv4/ip_forward

或修改/etc/sysconfig/network

FORWARD_IPV4=false  FORWARD_IPV4=true

2、          Iptables規則要素

一條iptables 規則基本上包含5個要素

——>指定表(tablefilter,nat,mangle 過濾使用filter

——>指定操作命令(command)添加、刪除、更新

——>指定鏈(chainsINPUT OUTPUT FORWARD

——>指定規則匹配器(matcher

——>指定目標動作(targetACCEPTDROPREJECTLOGTOS

注:iptables 中的指令均需區分大小寫

3、          iptables 語法的簡化形式

iptables [-t table] CMD [chain] [rule-matcher] [-j target]

table爲表名,CMD爲操作指令,chain爲鏈名,rule-matcher爲規則匹配器,target爲目標動作

4、          制定永久性規則

保存和恢復規則集,用下面的命令轉儲內存中的內核規則集

/etc/sysconfig/iptablesiptables守護進程調用的默認規則集文件

# /sbin/iptables-save>/etc/sysconfig/iptables

//恢復原來的規則集

# /sbin/iptables-restore</etc/sysconfig/iptables

iptables在下次啓動時規則還能使用

(1) 使用iptables啓動腳本實現  /etc/rc.d/init.d/iptables

使用下面命令保存規則

# service iptables save

(2)在自定義腳本中用iptables命令直接創建規則集,在啓動時執行這個腳本 例:/etc/fw/rules

在啓動腳本中/etc/rc.d/rc.local中加入

If [ -x /etc/fw/rules];then /etc/fw/rules; fi;

建議使用ntsysv命令關閉iptables守護進程

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章