iptables Command Usage Basics (02)

Source: Internet
Author: User

A. Iptables command

rule: try to match each message flowing through it according to the specified matching criteria, and once the match is successful, the processing action specified after the rule is processed;

Matching condition: It is divided into basic matching condition and extended matching condition, and the extended matching condition is divided into implicit extension and explicit extension.

Basic matching Criteria: Source address, Destination address, transmission protocol;

Extended matching Criteria: the need to use the extension module to specify the matching criteria;

Implicit extension: A protocol-related extension that has been specified in the basic matching criteria;

Explicit extension : Other extended matching conditions outside the implicit extension;

Processing action: Divided into basic action and extended action;

Basic action: Accept,drop,reject

Extended action: need to use the extension module, but not explicitly specified, only need to indicate the action;


Two. Questions to consider when adding a rule

(1) where the message flows: to determine which chain the rule is added to;

(2) Function of implementation: used to determine which table to add rules to;

(3) The direction of the message: used to determine which is the "source", which is the "target";

(4) match condition: used to write the rules that correctly match the target message;


Three. iptables command use Format

IP les [-t table] {-a|-c|-d} chain rule-specification


ip6tables [-t table] {-a|-c|-d} chain rule-specification


iptables [-t table]-I chain [rulenum] Rule-specification


iptables [-T table]-R chain Rulenum rule-specification


iptables [-t table]-D chain Rulenum


iptables [-t table]-s [chain [Rulenum]]


iptables [-t table] {-f|-l|-z} [chain [Rulenum]] [options ...]


iptables [-t table]-n Chain


iptables [-T table]-X [chain]


iptables [-t table]-p chain Target


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


Rule-specification = [matches ...] [Target]


Match =-M matchname [per-match-options]


target =-j targetname [per-target-options] Tab


Rule Management Format : iptables [-t table] COMMAND chain Creteria [-m-m matchname[per-match-options]] [-j targetname[per-target- Options]]


- T table: Indicates the table to be managed, and the default is filter;


COMMANDS:

chain Management:

     -p:iptables [-t table] -p  chain target, defines the default policy for the chain, and its target can generally be used with accept or drop;           -n:iptables [-t table] -n chain, custom rule chain; only the default chain can be invoked by a rule, so each custom chain has its reference count;           -x:iptables [-t table] -x [ Chain], delete the chain of custom and is empty reference count of 0;           -f:iptables [-t  table] -f [chain [rulenum]] [options.], empties the specified chain, or deletes the rule on the specified chain;           -E:iptables [-t table] -E old-chain-name  New-chain-name, rename the chain with a custom reference count of 0;           -z:iptables [- T table] -z  [chain[rulenum]] [options.], set the rule counter to 0; 


rules :

-a:append, iptables [-t table]-A chain rule-specification, append rule to the specified chain tail;-i:insert, iptables [-t table]-I chain [ Rulenum] rule-specification, insert rule to specified position in chain, default to Chain head,-d:delete,iptables [-t table]-D chainrule-specification or Iptab Les [-t table]-D chain Rulenum, deletes the specified rule on the specified chain,-r:replace,iptables [-t table]-R chain Rulenumrule-specification, which will Replaces the specified rule on the specified chain with the new rule;


View:

        -l:list, iptables [-t table] -l [ Chain [rulenum]] [options ...]                 -N: Digital Format;                 -v:verbose, detailed format information;                          -VV,-VVV, more detailed format information                     --line-numbers: Shows the number of rules on the chain;                    -x:exactly, displays the exact value of the counter The results shown by;      have so many meanings:     pkts bytes target      prot opt in     out     source                Destination        pkts: The number of messages that are matched to this rule;         bytes: The sum of the sizes of the messages that are matched to this rule;         Target: Handle the goal (the target can be a user-defined chain);         prot: Protocol {tcp,udp,icmp}         opt: Optional         in: Packet Inflow interface                  out: Packet Outflow interface          source: Source Address          Destination: Destination Address



Four. Counter

Each rule and the default policy for the chain have their own two counters, respectively:

(1) Pkts: The number of messages that are matched to this rule;

(2) Bytes: The sum of the size of the message that is matched to this rule;


Five: Save and reload rules

CENTOS6:

Save :

(1) Service Iptables Save

/etc/sysconfig/iptables file;

(2) Iptables-save >/path/to/somefile

Overloading :

(1) Service iptables restart

(2) Iptables-restore </path/from/somefile


CENTOS7: Introduced a new iptables front-end Management Service tool FIREWALLD

Firewalld through the front-end management tools: Firewalld-cmd and Firewalld-config, which are more powerful and perfect, so their rules are more complex, in order to maintain the same use of iptables on CENTOS6 to manage rules, You need to turn off and disable the FIREWALLD service on CENTOS7 first, as follows:

(1) Systemctl stop Firewalld.service

(2) systemctl disable Firewalld.service

























This article is from the "sub-another Linuxer" blog, be sure to keep this source http://yacheng0316.blog.51cto.com/11878883/1889979

iptables Command Usage Basics (02)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.