📄 00000009.htm
字号:
<HTML><HEAD> <TITLE>BBS水木清华站∶精华区</TITLE></HEAD><BODY><CENTER><H1>BBS水木清华站∶精华区</H1></CENTER>发信人: zixia (Do you zixia tonight), 信区: Linux <BR>标 题: 7. Using iptables <BR>发信站: BBS 水木清华站 (Wed Oct 11 01:18:02 2000) WWW-POST <BR> <BR> Linux 2.4 Packet Filtering HOWTO: Using iptables (p1 of <BR>20)
<BR> Next Previous Contents
<BR>Lin here a <BR>Ma
<BR> m ----------------------------------------------------------------------o
<BR>
<BR>7. Using iptables
<BR>
<BR>3.1iptables has a fairly detailed manual page (man iptables), and if you <BR>need
<BR> more detail on particulars. Those of you familiar with ipchains may <BR>simply
<BR> want to look at Differences Between iptables and ipchains; they are very
<BR> similar.
<BR>
<BR> There are several different things you can do with iptables. You start
<BR> with three built-in chains INPUT, OUTPUT and FORWARD which you can't
<BR> delete. Let's look at the operations to manage whole chains:
<BR> e,
<BR> 1. Create a new chain (-N).
<BR> 2. Delete an empty chain (-X). e
<BR> 3. Change the policy for a built-in chain. (-P). e
<BR> 4. List the rules in a chain (-L). <BR>on
<BR> 5. Flush the rules out of a chain (-F).
<BR> 6. Zero the packet and byte counters on all rules in a chain (-Z).
<BR>
<BR> There are several ways to manipulate rules inside a chain:
<BR>
<BR> 1. Append a new rule to a chain (-A).
<BR> 2. Insert a new rule at some position in a chain (-I).
<BR> 3. Replace a rule at some position in a chain (-R).
<BR> 4. Delete a rule at some position in a chain (-D). <BR>n
<BR> 5. Delete the first rule that matches in a chain (-D).
<BR>
<BR>7.1 What You'll See When Your Computer Starts Up
<BR>
<BR> iptables may be a module, called (`iptable_filter.o'), which should be
<BR> automatically loaded when you first run iptables. It can also be built
<BR> into the kernel permenantly.
<BR>
<BR> Before any iptables commands have been run (be careful: some <BR>distributions
<BR> will run iptables in their initialization scripts), there will be no <BR>rules
<BR> in any of the built-in chains (`INPUT', `FORWARD' and `OUTPUT'), all the
<BR> chains will have a policy of ACCEPT. You can alter the default policy of
<BR> the FORWARD chain by providing the `forward=0' option to the
<BR> iptable_filter module.
<BR>Lin here a <BR>Ma
<BR>7.2 Operations on a Single Rule o
<BR>
<BR> This is the bread-and-butter of packet filtering; manipulating rules. <BR>Most
<BR> commonly, you will probably use the append (-A) and delete (-D) commands.
<BR>3.1The others (-I for insert and -R for replace) are simple extensions of
<BR> these concepts.
<BR>
<BR> Each rule specifies a set of conditions the packet must meet, and what to
<BR> do if it meets them (a `target'). For example, you might want to drop all
<BR> ICMP packets coming from the IP address 127.0.0.1. So in this case our
<BR> conditions are that the protocol must be ICMP and that the source address
<BR> must be 127.0.0.1. Our target is `DROP'.
<BR> e,
<BR> 127.0.0.1 is the `loopback' interface, which you will have even if you
<BR> have no real network connection. You can use the `ping' program to e
<BR> generate such packets (it simply sends an ICMP type 8 (echo request) <BR>which
<BR> all cooperative hosts should obligingly respond to with an ICMP type 0 <BR>on
<BR> (echo reply) packet). This makes it useful for testing.
<BR>
<BR> # ping -c 1 127.0.0.1
<BR> PING 127.0.0.1 (127.0.0.1): 56 data bytes
<BR> 64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.2 ms
<BR>
<BR> --- 127.0.0.1 ping statistics ---
<BR> 1 packets transmitted, 1 packets received, 0% packet loss
<BR> round-trip min/avg/max = 0.2/0.2/0.2 ms <BR>n
<BR> # iptables -A INPUT -s 127.0.0.1 -p icmp -j DROP
<BR> # ping -c 1 127.0.0.1
<BR> PING 127.0.0.1 (127.0.0.1): 56 data bytes
<BR>
<BR> --- 127.0.0.1 ping statistics ---
<BR> 1 packets transmitted, 0 packets received, 100% packet loss
<BR> #
<BR>
<BR> You can see here that the first ping succeeds (the `-c 1' tells ping to
<BR>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -