天天看點

iptables man手冊翻譯

概要

iptables [-t table] -[AD] chain rule-specification [options]

iptables [-t table] -I chain [rulenum] rule-specification [options]

iptables [-t table] -R chain rulenum rule-specification [options]

iptables [-t table] -D chain rulenum [options]

iptables [-t table] -[LFZ] [chain] [options]

iptables [-t table] -N chain

iptables [-t table] -X [chain]

iptables [-t table] -P chain target [options]

iptables [-t table] -E old-chain-name new-chain-name

翻譯說明:

table:表

chain:鍊

rule:規則

option:選項

target:目标

ACCEPT:接受

DROP:丢棄

QUEUE:排隊

RETURN:傳回

  ACCEPT接受意思是讓這個包通過,DROP丢棄的意思是丢棄這個包,QUEUE排隊意思是将這個包傳給使用者空間。(一個使用者空間程序由不同的特定隊列處理程式來決定怎樣來接受這樣的包。2.4.x和2.6.x到2.6.13版的核心包含了"ip_queue"這個處理程式。2.6.14及以後版本的核心包含了"nfnetlink_queue"隊列處理程式。這種情況下的目标為QUEUE的包會被發送到隊列号位'0'的隊列。請看後文中NFQUUE目标的描述)RETURN傳回意味着停止周遊這個鍊,從前一個(調用的)鍊繼續下一條規則。如果到了一個内建鍊的末尾,或者比對了一個目标為RETURN的内建鍊規則,那麼就有這個鍊指定的目标來決定這個包的命運。

表:

目前一共有4個獨立的表(任何一個現存的表都依賴于核心的配置選項和加載的子產品)

-t, --table table

  這個選項指明了該條指令應該作用于哪一個包比對表。如果核心被配置為自動加載子產品,那麼核心就會自動嘗試加載恰當的未加載子產品。

下面列出了所有的表:

filter過濾器:

這個是預設表(如果沒有使用-t 選項)。它包含了内建鍊INPUT輸入(用于目的為本地socket的包),FORWARD轉發(用于經過經過本地轉發的包),和OUTPUT輸出(用于本地産生的包)。

nat:

這個表用于會建立一個新連接配接的包。它包括了3個内建鍊:PREROUTING路由前(用于改變剛剛收到還未route尋徑的包),OUTPUT(用于改變本地産生的還未route尋徑包),POSTROUTING(用于改變馬上就要發送的包)

mangle:

這個表用于一些特殊的包的内容。直到核心2.4.17,它有了兩個内建鍊:PREROUTING(用于改變尋徑routing前收到的包)和OUTPUT(用于改變尋徑前本地産生的包)。從核心2.4.18起,另外3個内建鍊也被支援:INPUT(用于收到給本機的包),FORWARD(用于改變經過本機轉發的包)和POSTROUTING(用于改變馬上就要發出的包)。

raw:

This table is used mainly for configuring exemptions from connection tracking in combination with the NOTRACK target.————這句話看了幾遍,大概意思自己是明白了,但是想了半天不知道怎樣翻譯才準确,大家自己看看英文吧。

它以更高的優先級注冊在netfilter鈎子上,是以會在ip_conntrack或者其它IP table前面調用。它提供了内建鍊:尋徑前PREROUTING(用于到達任何網卡的包),OUTPUT輸出(用于本地産生的包)。

選項

iptables支援的選項被分為幾個不同的組

  指令

  這些選項指明了要采取的動作。出下面進行特别說明的,在指令行指定其中的一個動作。對于長格式的指令和選項,你隻需要輸入足夠iptalbes可以區分出來是什麼指令的字母就可以了。

-A,--apend chain rule-specification

追加一條或多條規則到標明的鍊中。當源名字和(或)目的名字可以被解析為多個位址時,那麼被加入的這條規則适用于所有可能的位址;

-D, --delete chain rule-specification

-D, --delete chain rulenum

從所選的鍊中删除一條或者多條規則。這裡一共有兩個版本的指令格式:可以通過一個在鍊中的序号來指定這個規則(第1條規則序号為1)或者比對的規則。

-I,--insert chain [rulenum] rule-specification

以指定序号,插入一條或者多條規則到選擇的鍊中。是以,如果序号為1,那麼這些規則會被插入到這個鍊的頭部。這也是沒有指定規則序号的預設行為.

-R,--replace chain rulenum rule-specificaiton

取代選中鍊中的一條規則。如果源名字和目的名字可以被解析為多個位址,則指令失敗。規則從1開始計數。

-L,--list [chain]

列出選中鍊中的所有規則。如果沒有鍊選中,那麼所有就會列出所有鍊的規則。跟其他的iptables指令一樣,它會應用于一個指定的表中(預設情況下,是filter表),是以要列出所有NAT表的規則,需要使用指令 iptables -t nat -n -L

-F,--flush [chain]沖刷選中的鍊(如果沒有指明鍊,就會應用到所有的鍊)。這個指令等于一條條的删除所有的規則。

-Z,--zero [chain]

将所有鍊中的包和位元組計數器清零。可以指定-L,--list選項來在清零之前,顯示這些計數器。

-N,--new-chain chain建立一個給定名字的使用者自定義鍊。要求不能有這個名字的目标。

-X,--delete-chain [chain]删除指定的使用者自定義鍊。這要求必須沒有任何對這個鍊的引用。如果有引用的話,你需要先删除或者取代這些規則。這個鍊必須是空的。例如,不能包含任何的規則。如果沒有給定任何參數,它會嘗試删除每一個表中的非内建鍊。

-P,--policy chain target為鍊設定目标政策。可以跳轉到TARGETS節學習合法的目标。隻有内建鍊(非使用者自定義)可以有政策,和既不是内建也不是使用者的鍊可以成為政策目标。

-h,幫助

參數

下面的參數組成了規則的細節(被用于add,delete,insert,replace和append指令)

-p,--protocol [!]protocol

需要檢查的規則或者包的協定。可以指定tcp,udp,icmp,或者all。它也可以是一個數字,用于表示這些協定中的一個。允許的協定名字來自于/etc/protocols。協定簽的參數“!”用于對測試取反。數字0等于all。協定all可以比對任何協定,并且是沒有指明這個參數時的預設行為。

-s,--source [!]address[/mask]

指定源位址。位址可以是一個網絡名字,一個主機名(請注意指定任何名字,會導緻進行一個遠端的DNS解析,這不是一個好主意。),一個網絡IP位址(帶有/mask),或者一個直接的IP位址。這個掩碼可以是一個網絡掩碼,也可以是一個數字來指明掩碼左邊的“1”的個數。是以一個24的掩碼就是255.255.255.0。在位址前面的“!”用于對位址取反。标志--src是這個選項的一個别名。

-d, --destination [!] address[/mask]

指定目的位址。細節與-s類似。

-j,--jump target

指明了規則的目标。例如,當包比對規則時,要采取什麼動作。這個目标可以是一個使用者自定義的鍊(一個這個規則不在其中的鍊),一個特殊的内奸目标來立即決定包的命運,或者一個擴充。如果這個選項在規則中被省略(并且沒有使用-g),那麼比對了的這個規則對這個包沒有任何的影響,但是會增加這個規則的計數器。

-g,--goto chain

用于指明包需要進行一個使用者自定義鍊的處理。當時使用--jump轉到某個鍊中時,return不會繼續後面的鍊中處理,而是傳回至調用--jump的鍊中。而--goto與之不同。

-i,--in-interface [!]name

指定收到包的網卡(隻能應用于進入到INPUT,FORWARD和PREROUTING鍊的包)。當在網卡名字前使用“!”時,取相反的意思。如果網卡名字以“+”結尾,那麼任何一個以這個名字開頭的網卡都會被比對。如果這個選項被省略,那麼任何網卡名字都可以比對。

-o,--out-interface [!]name

指明發包的網卡名字(用于進入FORWARD,OUTPUT,和POSTROUTING鍊的包)。“!”的意思與前文相同。

[!] -f, --fragment

這意味這個規則隻應用于第二個和後面的分片包。因為分片時是沒有方法來的得到一個包的源或者目的端口(或者ICMP類型),這樣的包就不會比對以端口指定的規則。"!"的意思與前文相同。

-c, --set-counters PKTS BYTES

這個選項使管理者可以初始化一個規則的包和位元組的計數器(在INSERT,APPEND,REPLACE操作)

其他選項

可以指定下面的附加選項

-v, --verbose

詳細輸出。這個選項使list指令顯示網卡的名字,規則的選項,和TOS masks。包和位元組計數器也會以字尾“K”,“M”,或者“G”的形式顯示出來。對于追加,插入,删除和取代,詳細選項使這些被操作的規則列印出來。

-n, --numeric

數字格式輸出。IP位址和端口号以數字形式列印。預設情況下,程式會顯示主機名,網絡名字,或者服務的名字。

-x, --exact

擴充數字。顯示準确的包和位元組計數器的準确的值,來代替“K”,“M”,或者“G”。這個選項與“-L”指令相關。

--line-numbers

當列出規則時,在每個規則前加上行号,對應于規則在鍊中的位置。

--modprobe=command

當加入或者插入規則到一個連結中,使用command來加載必要的子產品(目标,比對擴充等)

附錄:

[root@localhost ~]# iptables --help
iptables v1.4.21

Usage: iptables -[ACD] chain rule-specification [options]
       iptables -I chain [rulenum] rule-specification [options]
       iptables -R chain rulenum rule-specification [options]
       iptables -D chain rulenum [options]
       iptables -[LS] [chain [rulenum]] [options]
       iptables -[FZ] [chain] [options]
       iptables -[NX] chain
       iptables -E old-chain-name new-chain-name
       iptables -P chain target [options]
       iptables -h (print this help information)

Commands:
Either long or short options are allowed.
  --append  -A chain            Append to chain
  --check   -C chain            Check for the existence of a rule
  --delete  -D chain            Delete matching rule from chain
  --delete  -D chain rulenum
                                Delete rule rulenum (1 = first) from chain
  --insert  -I chain [rulenum]
                                Insert in chain as rulenum (default 1=first)
  --replace -R chain rulenum
                                Replace rule rulenum (1 = first) in chain
  --list    -L [chain [rulenum]]
                                List the rules in a chain or all chains
  --list-rules -S [chain [rulenum]]
                                Print the rules in a chain or all chains
  --flush   -F [chain]          Delete all rules in  chain or all chains
  --zero    -Z [chain [rulenum]]
                                Zero counters in chain or all chains
  --new     -N chain            Create a new user-defined chain
  --delete-chain
            -X [chain]          Delete a user-defined chain
  --policy  -P chain target
                                Change policy on chain to target
  --rename-chain
            -E old-chain new-chain
                                Change chain name, (moving any references)
Options:
    --ipv4      -4              Nothing (line is ignored by ip6tables-restore)
    --ipv6      -6              Error (line is ignored by iptables-restore)
[!] --protocol  -p proto        protocol: by number or name, eg. `tcp'
[!] --source    -s address[/mask][...]
                                source specification
[!] --destination -d address[/mask][...]
                                destination specification
[!] --in-interface -i input name[+]
                                network interface name ([+] for wildcard)
 --jump -j target
                                target for rule (may load target extension)
  --goto      -g chain
                              jump to chain with no return
  --match       -m match
                                extended match (may load extension)
  --numeric     -n              numeric output of addresses and ports
[!] --out-interface -o output name[+]
                                network interface name ([+] for wildcard)
  --table       -t table        table to manipulate (default: `filter')
  --verbose     -v              verbose mode
  --wait        -w [seconds]    maximum wait to acquire xtables lock before give up
  --wait-interval -W [usecs]    wait time to try to acquire xtables lock
                                default is 1 second
  --line-numbers                print line numbers when listing
  --exact       -x              expand numbers (display exact values)
[!] --fragment  -f              match second or further fragments only
  --modprobe=<command>          try to insert modules using this command
  --set-counters PKTS BYTES     set the counter during insert/append
[!] --version   -V              print package version.