AIX上通過IPSEC進行IP包過濾


AIX上的IPSEC

在AIX可以通過以下步驟打開IP Security
smitty ipsec4 --> Start/Stop IP Security --> Start IP Security [Now and After Reboot]
注意,此時請將 Deny All Non_Secure IP Packets [no]
敲Enter

Command: OK            stdout: yes           stderr: no
Before command completion, additional instructions may appear below.
ipsec_v4 Available
Default rule for IPv4 in ODM has been changed.
Successfully set default action to PERMIT

此時啟動,默認IPv4規則已經設置,同時默認動作是 PERMIT。
這時我們可以用命令查看一下設備狀態

lsdev -C -c ipsec
ipsec_v4 Available  IP Version 4 Security Extension
ipsec_v6 Available  IP Version 6 Security Extension

相關管理命令為: lsfilt mkfilt mvfilt chfilt ckfilt genfilt rmfilt

查看規則

lsfilt -v4 -O
1|permit|0.0.0.0|0.0.0.0|0.0.0.0|0.0.0.0|no|udp|eq|4001|eq|4001|both|both|no|all packets|0|all|0|||Default Rule
2|*** Dynamic filter placement rule for IKE tunnels ***|no
0|permit|0.0.0.0|0.0.0.0|0.0.0.0|0.0.0.0|yes|all|any|0|any|0|both|both|no|all packets|0|all|0|||Default Rule

我們可以通過smitty來進行增加規則。

smitty ipsec4 --> Advanced IP Security Configuration -> Configure IP Security Filter Rules -> Add an IP Security Filter Rules.

* Rule Action                                        [permit]
* IP Source Address                                  []
* IP Source Mask                                     []
  IP Destination Address                             []
  IP Destination Mask                                []
* Apply to Source Routing? (PERMIT/inbound only)     [yes]
* Protocol                                           [all]
* Source Port / ICMP Type Operation                  [any]
* Source Port Number / ICMP Type                     [0]
* Destination Port / ICMP Code Operation             [any]
* Destination Port Number / ICMP Type                [0]
* Routing                                            [both]
* Direction                                          [both]
* Log Control                                        [no]
* Fragmentation Control                              [0]
* Interface                                          []
  Expiration Time  (sec)                             []
  Pattern Type                                       [none]
  Pattern                                            []
  Description                                        []

genfilt命令增加規則

genfilt與以上操作有異曲同工之效,基本命令模式

genfilt -v 4|6 [ -n fid] [ -a D|P|I|L|E|H|S ] -s s_addr -m s_mask [-d d_addr] [ -M d_mask] [ -g Y|N ] [ -c protocol] [ -o s_opr] [ -p s_port] [ -O d_opr] [ -P d_port] [ -r R|L|B ] [ -w I|O|B ] [ -l Y|N ] [ -f Y|N|O|H ] [ -t tid] [ -i interface] [-D description] [-e expiration_time] [-x quoted_pattern] [-X pattern_filename ] [-C antivirus_filename]

-C antivirus_filename 指定抗病毒名。-C 標志意味着ClamAV病毒庫的一些版本。
-D description 描述介紹。
-v 4|6 指定IP版本
-n fid 所添加ID將會被添加至第 fid 條規則之前
-a Action D(eny) | P(ermit) | I(f) | (e)L(se) | E(ndif)。所有IF規則必須關聯ENDIF規則結束。
-s s_addr 源地址
-m s_mask 源地址掩碼
-d d_addr 目標地址
-M d_mask 目標地址掩碼
-g Y|N 用於Permit規則,默認為Y,表示過濾規則可以使用源路由的IP包。
-c protocol 協議,默認all。有效值udp/icmp/icmpv6/tcp/tcp.ack/ospf/ipip/esp/ah/all
-o s_opr | ICMP Code Opertion 源端口或者ICMP類型 操作。有效值:lt/le/gt/ge/eq/neq/any。默認any,當-c ospf時,必須為any。
-p s_port 源端口或ICMP類型。
-O d_opr | ICMP Code Opertion 目標端口或者ICMP類型 操作。有效值:lt/le/gt/ge/eq/neq/any。默認any,當-c ospf時,必須為any。
-P d_port 目標端口或ICMP類型
-r R|L|B 路由,默認B。指定規則是用於R(轉發包)、L(發往或來自本機的包)、B(兩者都使用)
-w I|O|B 默認B。指定規則應用於I(輸入包)、O(輸出包)、B(兩者都使用)。使用代-x -X或-C 模式是使用O選項無效,使用B有效,但只檢查輸入包。
-l Y|N 是否記錄(匹配規則的包)日志,默認N。
-f Y|N|O|H 分段控制、默認為Y(所有包)。N(未分段包)、O(只用於分段和分段頭)、H(只應用於分段頭和未分段)。
-t tid 指定於該規則相關的通道標識,所有匹配包都要經過此通道。不指定此項,規則只作用於非流量通道。
-i interface 指定接口卡,默認為all。
-e expiration_time 過期時間(秒)。
-x pattern 匹配模式
-X patternfile 匹配模式文件。每行一個模式
常用舉例:

genfilt -v 4 -a P -s 192.168.0.1 -m 255.255.255.0 -d 192.168.0.88 -M 255.255.255.255 [-o any] [-p 0] -O eq -P 22 [-r B] [-w B] -l Y [-f Y] [-i all] -D "permit lan host visit port 22" [-e 0]

默認情況下我們加限制22端口的話,對所有的包都會進行規則匹配。可以利用默認的設置而進行簡略

genfilt -v 4 -a P -s 192.168.0.1 -m 255.255.255.0 -d 192.168.0.88 -M 255.255.255.255 -O eq -P 22
genfilt -v 4 -a D -O eq -P 22

使命令生效

mkfilt -v 4|6 [-d] [-u] [-z P|D] [-g start|stop] -i

-u 激活rule table中的所有狀態的規則。與-d 互斥
-d 停止表中規則。與-u 互斥
-z 使默認規則(最后一條)執行P或者D動作。
-g 日志啟動與停止
-i 與-u一起使用,激活所有"active"狀態規則。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM