linux防火牆iptables的筆記

2021-08-01 07:46:45 字數 2121 閱讀 5269

防火牆新增規則

iptables -a forward -d 2.0.0.0/32 -p tcp -m multiport --dports 2,9999 -m comment --comment "ec" -j r8
1.防火牆規則清空

iptables [-t tables ] [ -fxz ]

-f: 清除所有已制定的規則

-x: 清除使用者自定義鏈

-z: 將所有

chain

的計數和統計歸零

例:iptables -f

2.定義防火牆預設策略(policy)

iptables [ -t nat ] -p [input, output, forward] [accept,drop]

-p: 定義策略(

policy

),注意為大寫

accept:接受資料報

drop:丟棄資料報

例:iptables -p input drop

3.資料報基礎對比:ip

、網路及介面裝置

iptabless [-ai 鏈名

] [-io

網路介面

] [-p

協議] [-s

源位址] [-d

目的位址

] -j [accept|drop|reject|log]

-ai 鏈名

: -a:

新增一條規則,放在原規則追後面

-i: 插入一條規則,預設放在第一條前面

-io 網路介面:

-i:資料報所進入的網路介面

-o: 資料報所傳出的網路介面

-p 協定:設定資料報格式:

tcp,udp,icmp

和all

-s **

ip/

ip:192.168.1.2

網路:192.168.1.0/24

,192.168.1.0/255.255.255.0

-d 目的網路:同

-s,目的

ip位址或網路

-j: 後面的操作,主要有

accept

接受, drop

丟棄, reject

拒絕,log記錄

例:iptables -a input -i eth0  -s 192.168.1.2 -j accept

iptabless [-ai 鏈名

] [-io

網路介面

] [-p

協議] [-s

源位址][-- sport

埠範圍

] [-d

目的位址

] [--dport

埠範圍

]-j [accept|drop|reject|log]

例:iptables -a input -i eth1 -p tcp -s 192.168.1.2 --sport 22:88 -j drop

備註:因為tcp

和udp

資料報才具有埠號,所以想要使用

--sport,--dport

時,要加上

-tcp

或-udp

才可以。

4.iptables 外掛程式模組:

state

iptables -a input [-m state] [--state 狀態]

invalid:無效的或破損的資料報

related:這個資料報為主機傳送的資料報的響應

established:已經連線成功的連線狀態

new:想要建立連線的的資料報狀態

例:iptables -a input -m state --state related,established

iptables的基本語法格式

iptables [-t 表名] 命令選項 [鏈名] [條件匹配] [-j 目標動作或跳轉]

說明:表名、鏈名用於指定 iptables命令所操作的表和鏈,命令選項用於指定管理iptables規則的方式(比如:插入、增加、刪除、檢視等;條件匹配用於指定對符合什麼樣 條件的資料報進行處理;目標動作或跳轉用於指定資料報的處理方式(比如允許通過、拒絕、丟棄、跳轉(jump)給其它鏈處理。

iptables命令的管理控制選項

iptable防火牆詳解

一.基本格式 1.iptable t 表 命令選項 連名 匹配條件 j 動作 2.常用命令選項如下 二.舉例 iptable t filter f 清空filter表中所有規則 iptable t filter z 清空filter表中的計數器值 iptable t filter x 清除filte...

iptable防火牆詳解

一.基本格式 1.iptable t 表 命令選項 連名 匹配條件 j 動作 2.常用命令選項如下 二.舉例 iptables t filter f 清空filter表中所有規則 iptables t filter z 清空filter表中的計數器值 iptables t filter x 清除fi...

iptable防火牆詳解

iptable防火牆詳解 一.基本格式 1.iptable t 表 命令選項 連名 匹配條件 j 動作 2.常用命令選項如下 二.舉例 iptable t filter f 清空filter表中所有規則 iptable t filter z 清空filter表中的計數器值 iptable t fil...