iptables 命令详解

iptables -h

  1. iptables v1.4.21
  2. Usage: iptables -[ACD] chain rule-specification [options]
  3. iptables -I chain [rulenum] rule-specification [options]
  4. iptables -R chain rulenum rule-specification [options]
  5. iptables -D chain rulenum [options]
  6. iptables -[LS] [chain [rulenum]] [options]
  7. iptables -[FZ] [chain] [options]
  8. iptables -[NX] chain
  9. iptables -E old-chain-name new-chain-name
  10. iptables -P chain target [options]
  11. iptables -h (print this help information)
  12. Commands:
  13. Either long or short options are allowed.
  14. --append -A chain Append to chain
  15. --check -C chain Check for the existence of a rule
  16. --delete -D chain Delete matching rule from chain
  17. --delete -D chain rulenum
  18. Delete rule rulenum (1 = first) from chain
  19. --insert -I chain [rulenum]
  20. Insert in chain as rulenum (default 1=first)
  21. --replace -R chain rulenum
  22. Replace rule rulenum (1 = first) in chain
  23. --list -L [chain [rulenum]]
  24. List the rules in a chain or all chains
  25. --list-rules -S [chain [rulenum]]
  26. Print the rules in a chain or all chains
  27. --flush -F [chain] Delete all rules in chain or all chains
  28. --zero -Z [chain [rulenum]]
  29. Zero counters in chain or all chains
  30. --new -N chain Create a new user-defined chain
  31. --delete-chain
  32. -X [chain] Delete a user-defined chain
  33. --policy -P chain target
  34. Change policy on chain to target
  35. --rename-chain
  36. -E old-chain new-chain
  37. Change chain name, (moving any references)
  38. Options:
  39. --ipv4 -4 Nothing (line is ignored by ip6tables-restore)
  40. --ipv6 -6 Error (line is ignored by iptables-restore)
  41. [!] --protocol -p proto protocol: by number or name, eg. `tcp'
  42. [!] --source -s address[/mask][...]
  43. source specification
  44. [!] --destination -d address[/mask][...]
  45. destination specification
  46. [!] --in-interface -i input name[+]
  47. network interface name ([+] for wildcard)
  48. --jump -j target
  49. target for rule (may load target extension)
  50. --goto -g chain
  51. jump to chain with no return
  52. --match -m match
  53. extended match (may load extension)
  54. --numeric -n numeric output of addresses and ports
  55. [!] --out-interface -o output name[+]
  56. network interface name ([+] for wildcard)
  57. --table -t table table to manipulate (default: `filter')
  58. --verbose -v verbose mode
  59. --wait -w [seconds] maximum wait to acquire xtables lock before give up
  60. --wait-interval -W [usecs] wait time to try to acquire xtables lock
  61. default is 1 second
  62. --line-numbers print line numbers when listing
  63. --exact -x expand numbers (display exact values)
  64. [!] --fragment -f match second or further fragments only
  65. --modprobe=<command> try to insert modules using this command
  66. --set-counters PKTS BYTES set the counter during insert/append
  67. [!] --version -V print package version.

常用参数

  1. --table -t table table to manipulate (default: `filter')
  2. --list -L [chain [rulenum]]
  3. List the rules in a chain or all chains
  4. --verbose -v verbose mode

查看filter表中的规则

  • iptables -vL INPUT ``` Chain INPUT (policy ACCEPT 0 packets, 0 bytes) pkts bytes target prot opt in out source destination
    473 53337 ACCEPT all — any any anywhere anywhere ctstate RELATED,ESTABLISHED 33 2772 ACCEPT all — lo any anywhere anywhere
    722 70195 INPUT_direct all — any any anywhere anywhere
    722 70195 INPUT_ZONES_SOURCE all — any any anywhere anywhere
    722 70195 INPUT_ZONES all — any any anywhere anywhere
    30 2043 DROP all — any any anywhere anywhere ctstate INVALID 692 68152 REJECT all — any any anywhere anywhere reject-with icmp-host-prohibited
  1. ```
  2. pkts:对应规则匹配到的报文的个数。
  3. bytes:对应匹配到的报文包的大小总和。
  4. target:规则对应的target,往往表示规则对应的”动作”,即规则匹配成功后需要采取的措施。
  5. prot:表示规则对应的协议,是否只针对某些协议应用此规则。
  6. opt:表示规则对应的选项。
  7. in:表示数据包由哪个接口(网卡)流入,我们可以设置通过哪块网卡流入的报文需要匹配当前规则。
  8. out:表示数据包由哪个接口(网卡)流出,我们可以设置通过哪块网卡流出的报文需要匹配当前规则。
  9. source:表示规则对应的源头地址,可以是一个IP,也可以是一个网段。
  10. destination:表示规则对应的目标地址。可以是一个IP,也可以是一个网段。