iptables 定義規則

2021-09-20 17:59:13 字數 1438 閱讀 1359

iptables定義規則的方式大概是這種格式:

iptables [-t table] command chain cretiria -j action

-t 表名:指定要操作的表

command:定義策略

chain:指定要操作的鏈

cretiria:定義匹配的標準(分為多個標準)

-j target:策略進行的動作

command

-l:顯示所選鏈的所有策略

-a:在所選擇的鏈最尾部新增一條新的策略

-d:從所選鏈中刪除策略

-r:替換所選中的鏈裡指定的策略

-i:從所選鏈中指定策略前面插入一條新的策略

-f:清空所選鏈的策略,如果不指定,清空所有

-z:將所選鏈的所有計數器歸零。

-n:根據使用者指定的名字建立新的鏈

-l :顯示所選鏈的所有策略

-a:在所選擇的鏈最尾部新增一條新的策略

-d:從所選鏈中刪除策略

-r:替換所選中的鏈裡指定的策略

-i:從所選鏈中指定策略前面插入一條新的策略

-f:清空所選鏈的策略,如果不指定,清空所有

-z:將所選鏈的所有計數器歸零。

-n:根據使用者指定的名字建立新的鏈

-x:刪除指定使用者自定義鏈

-e:對自定義鏈進行重新命名

-p:為鏈設定預設策略

在使用上述操作時還可以配合一下引數使用:

-v:該引數使輸出的內容詳細化

-x:使-l輸出時的計數器顯示準確的數值

-n:將ip位址和埠以數值的形式顯示

--line-numbers:在顯示策略時,輸入序號

--modprobe:指定iptables探測並裝載使用的模組

cretiria

匹配主機

-s:**位址          192.168.0.0/24

-d:目標位址          192.168.0.1

網路介面

-i lo                 從介面進來的

-o eth1               從介面出去的

反向選擇

-i eth0 『!』-s  192.168.0.0/24  

iptables -a input 『!』-s 192.168.0.0/24 -j reject

接埠並且接協議

-p tcp --dport 80   訪問我的目標埠為80的並且協議為tcp

-p udp --sport 53   訪問源埠為53的並且協議為udp

動作(target):

accept:放行

drop:丟棄

reject:拒絕

dnat:目標位址轉換

snat:源位址轉換

redirect:埠重定向

masquerade:位址偽裝

log:日誌

iptables 生產規則

bin bash etc init.d iptables stop iptables a input p tcp dport 80 j accept iptables a input p tcp dport 21 j accept iptables a input s 192.168.17.0 24...

IPTABLES 清空規則

iptables f 然後重新啟用的話 bin iptables.sh root ctc wh 1 176 iptables l chain input policy accept target prot opt source destination chain forward policy acc...

iptables 規則速查

iptables的命令規則速查,沒有為了方便 iptables a input p tcp dport 22 j ulog ulog nlgroup 2 iptables a input p tcp dport 22 j ulog ulog prefix ssh connection attempt...