<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Lamp Blog</title>
	<atom:link href="http://www.lampblog.net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.lampblog.net</link>
	<description>站在Linux+Apache+MySQL+PHP技术上，进行搜索引擎优化，数据分析，网站优化</description>
	<lastBuildDate>Sat, 12 May 2012 02:19:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>linux下常用的20条iptables命令规则</title>
		<link>http://www.lampblog.net/2012/05/linux%e4%b8%8b%e5%b8%b8%e7%94%a8%e7%9a%8420%e6%9d%a1iptables%e5%91%bd%e4%bb%a4%e8%a7%84%e5%88%99/</link>
		<comments>http://www.lampblog.net/2012/05/linux%e4%b8%8b%e5%b8%b8%e7%94%a8%e7%9a%8420%e6%9d%a1iptables%e5%91%bd%e4%bb%a4%e8%a7%84%e5%88%99/#comments</comments>
		<pubDate>Sat, 12 May 2012 02:19:04 +0000</pubDate>
		<dc:creator>eagle</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.lampblog.net/?p=2337</guid>
		<description><![CDATA[This Linux based firewall is controlled by the program called iptables to handles filtering for IPv4, and ip6tables handles filtering for IPv6. I strongly recommend that you first read our quick tutorial that explains how to configure a host-based firewall called Netfilter (iptables) under CentOS / RHEL / Fedora / Redhat Enterprise Linux. This post list most [...]]]></description>
			<content:encoded><![CDATA[<p>This Linux based firewall is controlled by the program called iptables to handles filtering for IPv4, and ip6tables handles filtering for IPv6. I strongly recommend that you first read our quick tutorial that explains how to configure a host-based firewall called Netfilter (iptables) under CentOS / RHEL / Fedora / Redhat Enterprise Linux. This post list most common iptables solutions required by a new Linux user to secure his or her Linux operating system from intruders.</p>
<h2>IPTABLES Rules Example</h2>
<ul>
<li>Most of the actions listed in this post are written with the assumption that they will be executed by the root user running the bash or any other modern shell. Do not type commands on remote system as it will disconnect your access.</li>
<li>For demonstration purpose I&#8217;ve used RHEL 6.x, but the following command should work with any modern Linux distro.</li>
<li>This is NOT a tutorial on how to set iptables. See tutorial here. It is a quick cheat sheet to common iptables commands.</li>
</ul>
<h2>#1: Displaying the Status of Your Firewall</h2>
<p>Type the following command as root:<br />
<code># iptables -L -n -v</code><br />
Sample outputs:</p>
<pre>Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination</pre>
<p>Above output indicates that the firewall is not active. The following sample shows an active firewall:<br />
<code># iptables -L -n -v</code><br />
Sample outputs:</p>
<pre>Chain INPUT (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID
  394 43586 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
   93 17292 ACCEPT     all  --  br0    *       0.0.0.0/0            0.0.0.0/0
    1   142 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0
Chain FORWARD (policy DROP 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  br0    br0     0.0.0.0/0            0.0.0.0/0
    0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0           state INVALID
    0     0 TCPMSS     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x02 TCPMSS clamp to PMTU
    0     0 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
    0     0 wanin      all  --  vlan2  *       0.0.0.0/0            0.0.0.0/0
    0     0 wanout     all  --  *      vlan2   0.0.0.0/0            0.0.0.0/0
    0     0 ACCEPT     all  --  br0    *       0.0.0.0/0            0.0.0.0/0
Chain OUTPUT (policy ACCEPT 425 packets, 113K bytes)
 pkts bytes target     prot opt in     out     source               destination
Chain wanin (1 references)
 pkts bytes target     prot opt in     out     source               destination
Chain wanout (1 references)
 pkts bytes target     prot opt in     out     source               destination</pre>
<p>Where,</p>
<ul>
<li><strong>-L</strong> : List rules.</li>
<li><strong>-v</strong> : Display detailed information. This option makes the list command show the interface name, the rule options, and the TOS masks. The packet and byte counters are also listed, with the suffix &#8216;K&#8217;, &#8216;M&#8217; or &#8216;G&#8217; for 1000, 1,000,000 and 1,000,000,000 multipliers respectively.</li>
<li><strong>-n</strong> : Display IP address and port in numeric format. Do not use DNS to resolve names. This will speed up listing.</li>
</ul>
<h3>#1.1: To inspect firewall with line numbers, enter:</h3>
<p><code># iptables -n -L -v --line-numbers</code><br />
Sample outputs:</p>
<pre>Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    DROP       all  --  0.0.0.0/0            0.0.0.0/0           state INVALID
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
Chain FORWARD (policy DROP)
num  target     prot opt source               destination
1    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
2    DROP       all  --  0.0.0.0/0            0.0.0.0/0           state INVALID
3    TCPMSS     tcp  --  0.0.0.0/0            0.0.0.0/0           tcp flags:0x06/0x02 TCPMSS clamp to PMTU
4    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state RELATED,ESTABLISHED
5    wanin      all  --  0.0.0.0/0            0.0.0.0/0
6    wanout     all  --  0.0.0.0/0            0.0.0.0/0
7    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0
Chain OUTPUT (policy ACCEPT)
num  target     prot opt source               destination
Chain wanin (1 references)
num  target     prot opt source               destination
Chain wanout (1 references)
num  target     prot opt source               destination</pre>
<p>You can use line numbers to delete or insert new rules into the firewall.</p>
<h3>#1.2: To display INPUT or OUTPUT chain rules, enter:</h3>
<p><code># iptables -L INPUT -n -v<br />
# iptables -L OUTPUT -n -v --line-numbers</code></p>
<h2>#2: Stop / Start / Restart the Firewall</h2>
<p>If you are using CentOS / RHEL / Fedora Linux, enter:<br />
<code># service iptables stop<br />
# service iptables start<br />
# service iptables restart</code><br />
You can use the iptables command itself to stop the firewall and delete all rules:<br />
<code># iptables -F<br />
# iptables -X<br />
# iptables -t nat -F<br />
# iptables -t nat -X<br />
# iptables -t mangle -F<br />
# iptables -t mangle -X<br />
# iptables -P INPUT ACCEPT<br />
# iptables -P OUTPUT ACCEPT<br />
# iptables -P FORWARD ACCEPT</code><br />
Where,</p>
<ul>
<li><strong>-F</strong> : Deleting (flushing) all the rules.</li>
<li><strong>-X</strong> : Delete chain.</li>
<li><strong>-t table_name</strong> : Select table (called nat or mangle) and delete/flush rules.</li>
<li><strong>-P</strong> : Set the default policy (such as DROP, REJECT, or ACCEPT).</li>
</ul>
<h2>#3: Delete Firewall Rules</h2>
<p>To display line number along with other information for existing rules, enter:<br />
<code># iptables -L INPUT -n --line-numbers<br />
# iptables -L OUTPUT -n --line-numbers<br />
# iptables -L OUTPUT -n --line-numbers | less<br />
# iptables -L OUTPUT -n --line-numbers | grep 202.54.1.1</code><br />
You will get the list of IP. Look at the number on the left, then use number to delete it. For example delete line number 4, enter:<br />
<code># iptables -D INPUT 4</code><br />
OR find source IP 202.54.1.1 and delete from rule:<br />
<code># iptables -D INPUT -s 202.54.1.1 -j DROP</code><br />
Where,</p>
<ul>
<li><strong>-D </strong>: Delete one or more rules from the selected chain</li>
</ul>
<h2>#4: Insert Firewall Rules</h2>
<p>To insert one or more rules in the selected chain as the given rule number use the following syntax. First find out line numbers, enter:<br />
# iptables -L INPUT -n &#8211;line-numbers<br />
Sample outputs:</p>
<pre>Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    DROP       all  --  202.54.1.1           0.0.0.0/0
2    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state NEW,ESTABLISHED</pre>
<p>To insert rule between 1 and 2, enter:<br />
<code># iptables -I INPUT 2 -s 202.54.1.2 -j DROP</code><br />
To view updated rules, enter:<br />
<code># iptables -L INPUT -n --line-numbers</code><br />
Sample outputs:</p>
<pre>Chain INPUT (policy DROP)
num  target     prot opt source               destination
1    DROP       all  --  202.54.1.1           0.0.0.0/0
2    DROP       all  --  202.54.1.2           0.0.0.0/0
3    ACCEPT     all  --  0.0.0.0/0            0.0.0.0/0           state NEW,ESTABLISHED</pre>
<h2>#5: Save Firewall Rules</h2>
<p>To save firewall rules under CentOS / RHEL / Fedora Linux, enter:<br />
<code># service iptables save</code><br />
In this example, drop an IP and save firewall rules:<br />
<code># iptables -A INPUT -s 202.5.4.1 -j DROP<br />
# service iptables save</code><br />
For all other distros use the iptables-save command:<br />
<code># iptables-save &gt; /root/my.active.firewall.rules<br />
# cat /root/my.active.firewall.rules</code></p>
<h2>#6: Restore Firewall Rules</h2>
<p>To restore firewall rules form a file called /root/my.active.firewall.rules, enter:<br />
<code># iptables-restore &lt; /root/my.active.firewall.rules</code><br />
To restore firewall rules under CentOS / RHEL / Fedora Linux, enter:<br />
<code># service iptables restart</code></p>
<h2>#7: Set the Default Firewall Policies</h2>
<p>To drop all traffic:<br />
<code># iptables -P INPUT DROP<br />
# iptables -P OUTPUT DROP<br />
# iptables -P FORWARD DROP<br />
# iptables -L -v -n<br />
#### you will not able to connect anywhere as all traffic is dropped ###<br />
# ping cyberciti.biz<br />
# wget http://www.kernel.org/pub/linux/kernel/v3.0/testing/linux-3.2-rc5.tar.bz2</code></p>
<h3>#7.1: Only Block Incoming Traffic</h3>
<p>To drop all incoming / forwarded packets, but allow outgoing traffic, enter:<br />
<code># iptables -P INPUT DROP<br />
# iptables -P FORWARD DROP<br />
# iptables -P OUTPUT ACCEPT<br />
# iptables -A INPUT -m state --state NEW,ESTABLISHED -j ACCEPT<br />
# iptables -L -v -n<br />
### *** now ping and wget should work *** ###<br />
# ping cyberciti.biz<br />
# wget http://www.kernel.org/pub/linux/kernel/v3.0/testing/linux-3.2-rc5.tar.bz2</code></p>
<h2>#8:Drop Private Network Address On Public Interface</h2>
<p>IP spoofing is nothing but to stop the following IPv4 address ranges for private networks on your public interfaces. Packets with non-routable source addresses should be rejected using the following syntax:<br />
<code># iptables -A INPUT -i eth1 -s 192.168.0.0/24 -j DROP<br />
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP</code></p>
<h3>#8.1: IPv4 Address Ranges For Private Networks (make sure you block them on public interface)</h3>
<ul>
<li>10.0.0.0/8 -j (A)</li>
<li>172.16.0.0/12 (B)</li>
<li>192.168.0.0/16 (C)</li>
<li>224.0.0.0/4 (MULTICAST D)</li>
<li>240.0.0.0/5 (E)</li>
<li>127.0.0.0/8 (LOOPBACK)</li>
</ul>
<h2>#9: Blocking an IP Address (BLOCK IP)</h2>
<p>To block an attackers ip address called 1.2.3.4, enter:<br />
<code># iptables -A INPUT -s 1.2.3.4 -j DROP<br />
# iptables -A INPUT -s 192.168.0.0/24 -j DROP</code></p>
<h2>#10: Block Incoming Port Requests (BLOCK PORT)</h2>
<p>To block all service requests on port 80, enter:<br />
<code># iptables -A INPUT -p tcp --dport 80 -j DROP<br />
# iptables -A INPUT -i eth1 -p tcp --dport 80 -j DROP</code></p>
<p>To block port 80 only for an ip address 1.2.3.4, enter:<br />
<code># iptables -A INPUT -p tcp -s 1.2.3.4 --dport 80 -j DROP<br />
# iptables -A INPUT -i eth1 -p tcp -s 192.168.1.0/24 --dport 80 -j DROP</code></p>
<h2>#11: Block Outgoing IP Address</h2>
<p>To block outgoing traffic to a particular host or domain such as cyberciti.biz, enter:<br />
<code># host -t a cyberciti.biz</code><br />
Sample outputs:</p>
<pre>cyberciti.biz has address 75.126.153.206</pre>
<p>Note down its ip address and type the following to block all outgoing traffic to 75.126.153.206:<br />
<code># iptables -A OUTPUT -d 75.126.153.206 -j DROP</code><br />
You can use a subnet as follows:<br />
<code># iptables -A OUTPUT -d 192.168.1.0/24 -j DROP<br />
# iptables -A OUTPUT -o eth1 -d 192.168.1.0/24 -j DROP</code></p>
<h3>#11.1: Example &#8211; Block Facebook.com Domain</h3>
<p>First, find out all ip address of facebook.com, enter:<br />
<code># host -t a www.facebook.com</code><br />
Sample outputs:</p>
<pre>www.facebook.com has address 69.171.228.40</pre>
<p>Find CIDR for 69.171.228.40, enter:<br />
<code># whois 69.171.228.40 | grep CIDR</code><br />
Sample outputs:</p>
<pre>CIDR:           69.171.224.0/19</pre>
<p>To prevent outgoing access to www.facebook.com, enter:<br />
<code># iptables -A OUTPUT -p tcp -d 69.171.224.0/19 -j DROP</code><br />
You can also use domain name, enter:<br />
<code># iptables -A OUTPUT -p tcp -d www.facebook.com -j DROP<br />
# iptables -A OUTPUT -p tcp -d facebook.com -j DROP</code></p>
<p>From the iptables man page:</p>
<blockquote><p>&#8230; specifying any name to be resolved with a remote query such as DNS (e.g., facebook.com is a really bad idea), a network IP address (with /mask), or a plain IP address &#8230;</p></blockquote>
<h2>#12: Log and Drop Packets</h2>
<p>Type the following to log and block IP spoofing on public interface called eth1<br />
<code># iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j LOG --log-prefix "IP_SPOOF A: "<br />
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP</code><br />
By default everything is logged to /var/log/messages file.<br />
<code># tail -f /var/log/messages<br />
# grep --color 'IP SPOOF' /var/log/messages</code></p>
<h2>#13: Log and Drop Packets with Limited Number of Log Entries</h2>
<p>The -m limit module can limit the number of log entries created per time. This is used to prevent flooding your log file. To log and drop spoofing per 5 minutes, in bursts of at most 7 entries .<br />
<code># iptables -A INPUT -i eth1 -s 10.0.0.0/8 -m limit --limit 5/m --limit-burst 7 -j LOG --log-prefix "IP_SPOOF A: "<br />
# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP</code></p>
<h2>#14: Drop or Accept Traffic From Mac Address</h2>
<p>Use the following syntax:<br />
<code># iptables -A INPUT -m mac --mac-source 00:0F:EA:91:04:08 -j DROP<br />
## *only accept traffic for TCP port # 8080 from mac 00:0F:EA:91:04:07 * ##<br />
# iptables -A INPUT -p tcp --destination-port 22 -m mac --mac-source 00:0F:EA:91:04:07 -j ACCEPT</code></p>
<h2>#15: Block or Allow ICMP Ping Request</h2>
<p>Type the following command to block ICMP ping requests:<br />
<code># iptables -A INPUT -p icmp --icmp-type echo-request -j DROP<br />
# iptables -A INPUT -i eth1 -p icmp --icmp-type echo-request -j DROP</code><br />
Ping responses can also be limited to certain networks or hosts:<br />
<code># iptables -A INPUT -s 192.168.1.0/24 -p icmp --icmp-type echo-request -j ACCEPT</code><br />
The following only accepts limited type of ICMP requests:<br />
<code>### ** assumed that default INPUT policy set to DROP ** #############<br />
iptables -A INPUT -p icmp --icmp-type echo-reply -j ACCEPT<br />
iptables -A INPUT -p icmp --icmp-type destination-unreachable -j ACCEPT<br />
iptables -A INPUT -p icmp --icmp-type time-exceeded -j ACCEPT<br />
## ** all our server to respond to pings ** ##<br />
iptables -A INPUT -p icmp --icmp-type echo-request -j ACCEPT</code></p>
<h2>#16: Open Range of Ports</h2>
<p>Use the following syntax to open a range of ports:<br />
<code>iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 7000:7010 -j ACCEPT</code></p>
<h2>#17: Open Range of IP Addresses</h2>
<p>Use the following syntax to open a range of IP address:<br />
<code>## only accept connection to tcp port 80 (Apache) if ip is between 192.168.1.100 and 192.168.1.200 ##<br />
iptables -A INPUT -p tcp --destination-port 80 -m iprange --src-range 192.168.1.100-192.168.1.200 -j ACCEPT</code></p>
<p><code>## nat example ##<br />
iptables -t nat -A POSTROUTING -j SNAT --to-source 192.168.1.20-192.168.1.25<br />
</code></p>
<h2>#18: Established Connections and Restaring The Firewall</h2>
<p>When you restart the iptables service it will drop established connections as it unload modules from the system under RHEL / Fedora / CentOS Linux. Edit, /etc/sysconfig/iptables-config and set IPTABLES_MODULES_UNLOAD as follows:</p>
<pre>IPTABLES_MODULES_UNLOAD = no</pre>
<h2>#19: Help Iptables Flooding My Server Screen</h2>
<p>Use the crit log level to send messages to a log file instead of console:<br />
<code>iptables -A INPUT -s 1.2.3.4 -p tcp --destination-port 80 -j LOG --log-level crit</code></p>
<h2>#20: Block or Open Common Ports</h2>
<p>The following shows syntax for opening and closing common TCP and UDP ports:</p>
<pre> 
Replace ACCEPT with DROP to block port:
## open port ssh tcp port 22 ##
iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 22 -j ACCEPT

## open cups (printing service) udp/tcp port 631 for LAN users ##
iptables -A INPUT -s 192.168.1.0/24 -p udp -m udp --dport 631 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -p tcp -m tcp --dport 631 -j ACCEPT

## allow time sync via NTP for lan users (open udp port 123) ##
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p udp --dport 123 -j ACCEPT

## open tcp port 25 (smtp) for all ##
iptables -A INPUT -m state --state NEW -p tcp --dport 25 -j ACCEPT

# open dns server ports for all ##
iptables -A INPUT -m state --state NEW -p udp --dport 53 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 53 -j ACCEPT

## open http/https (Apache) server port to all ##
iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -m state --state NEW -p tcp --dport 443 -j ACCEPT

## open tcp port 110 (pop3) for all ##
iptables -A INPUT -m state --state NEW -p tcp --dport 110 -j ACCEPT

## open tcp port 143 (imap) for all ##
iptables -A INPUT -m state --state NEW -p tcp --dport 143 -j ACCEPT

## open access to Samba file server for lan users only ##
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 137 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 138 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 139 -j ACCEPT
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 445 -j ACCEPT

## open access to proxy server for lan users only ##
iptables -A INPUT -s 192.168.1.0/24 -m state --state NEW -p tcp --dport 3128 -j ACCEPT

## open access to mysql server for lan users only ##
iptables -I INPUT -p tcp --dport 3306 -j ACCEPT</pre>
<h2>#21: Restrict the Number of Parallel Connections To a Server Per Client IP</h2>
<p>You can use connlimit module to put such restrictions. To allow 3 ssh connections per client host, enter:<br />
<code># iptables -A INPUT -p tcp --syn --dport 22 -m connlimit --connlimit-above 3 -j REJECT</code></p>
<p>Set HTTP requests to 20:<br />
<code># iptables -p tcp --syn --dport 80 -m connlimit --connlimit-above 20 --connlimit-mask 24 -j DROP</code><br />
Where,</p>
<ol>
<li><strong>&#8211;connlimit-above 3</strong> : Match if the number of existing connections is above 3.</li>
<li><strong>&#8211;connlimit-mask 24</strong> : Group hosts using the prefix length. For IPv4, this must be a number between (including) 0 and 32.</li>
</ol>
<h2>#22: HowTO: Use iptables Like a Pro</h2>
<p>For more information about iptables, please see the manual page by typing man iptables from the command line:<br />
<code>$ man iptables</code><br />
You can see the help using the following syntax too:<br />
<code># iptables -h</code><br />
To see help with specific commands and targets, enter:<br />
<code># iptables -j DROP -h</code></p>
<h3>#22.1: Testing Your Firewall</h3>
<p>Find out if ports are open or not, enter:<br />
<code># netstat -tulpn</code><br />
Find out if tcp port 80 open or not, enter:<br />
<code># netstat -tulpn | grep :80</code><br />
If port 80 is not open, start the Apache, enter:<br />
<code># service httpd start</code><br />
Make sure iptables allowing access to the port 80:<br />
<code># iptables -L INPUT -v -n | grep 80</code><br />
Otherwise open port 80 using the iptables for all users:<br />
<code># iptables -A INPUT -m state --state NEW -p tcp --dport 80 -j ACCEPT<br />
# service iptables save</code><br />
Use the telnet command to see if firewall allows to connect to port 80:<br />
<code>$ telnet www.cyberciti.biz 80</code><br />
Sample outputs:</p>
<pre>Trying 75.126.153.206...
Connected to www.cyberciti.biz.
Escape character is '^]'.
^]
telnet&gt; quit
Connection closed.</pre>
<p>You can use nmap to probe your own server using the following syntax:<br />
<code>$ nmap -sS -p 80 www.cyberciti.biz</code><br />
Sample outputs:</p>
<pre>Starting Nmap 5.00 ( http://nmap.org ) at 2011-12-13 13:19 IST
Interesting ports on www.cyberciti.biz (75.126.153.206):
PORT   STATE SERVICE
80/tcp open  http
Nmap done: 1 IP address (1 host up) scanned in 1.00 seconds</pre>
<p>I also recommend you install and use sniffer such as tcpdupm and ngrep to test your firewall settings.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lampblog.net/2012/05/linux%e4%b8%8b%e5%b8%b8%e7%94%a8%e7%9a%8420%e6%9d%a1iptables%e5%91%bd%e4%bb%a4%e8%a7%84%e5%88%99/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>memadmin</title>
		<link>http://www.lampblog.net/2012/05/memadmin/</link>
		<comments>http://www.lampblog.net/2012/05/memadmin/#comments</comments>
		<pubDate>Sat, 12 May 2012 01:49:37 +0000</pubDate>
		<dc:creator>eagle</dc:creator>
				<category><![CDATA[Memcache & TT]]></category>

		<guid isPermaLink="false">http://www.lampblog.net/?p=2334</guid>
		<description><![CDATA[基于 PHP5 &#38; JQuery 的 Memcached 管理监控工具 MemAdmin是一款可视化的Memcached管理与监控工具，使用PHP开发，体积小，操作简单。 主要功能： &#160; 服务器参数监控：STATS、SETTINGS、ITEMS、SLABS、SIZES实时刷新 服务器性能监控：GET、DELETE、INCR、DECR、CAS等常用操作命中率实时监控 支持数据遍历，方便对存储内容进行监视 支持条件查询，筛选出满足条件的KEY或VALUE 数组、JSON等序列化字符反序列显示 兼容memcache协议的其他服务，如Tokyo Tyrant (遍历功能除外) 支持服务器连接池，多服务器管理切换方便简洁 项目主页：http://www.junopen.com/memadmin/]]></description>
			<content:encoded><![CDATA[<div id="describe">基于 PHP5 &amp; JQuery 的 Memcached 管理监控工具</div>
<div id="show">
<div id="showl">
<p>MemAdmin是一款可视化的Memcached管理与监控工具，使用PHP开发，体积小，操作简单。</p>
<p>主要功能：</p>
<p>&nbsp;</p>
<ul>
<li>服务器参数监控：STATS、SETTINGS、ITEMS、SLABS、SIZES实时刷新</li>
<li>服务器性能监控：GET、DELETE、INCR、DECR、CAS等常用操作命中率实时监控</li>
<li>支持数据遍历，方便对存储内容进行监视</li>
<li>支持条件查询，筛选出满足条件的KEY或VALUE</li>
<li>数组、JSON等序列化字符反序列显示</li>
<li>兼容memcache协议的其他服务，如Tokyo Tyrant (遍历功能除外)</li>
<li>支持服务器连接池，多服务器管理切换方便简洁</li>
</ul>
<div>项目主页：<a href="http://www.junopen.com/memadmin/">http://www.junopen.com/memadmin/</a></div>
</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.lampblog.net/2012/05/memadmin/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用iptables加强Memcache的安全性</title>
		<link>http://www.lampblog.net/2012/05/%e4%bd%bf%e7%94%a8iptables%e5%8a%a0%e5%bc%bamemcache%e7%9a%84%e5%ae%89%e5%85%a8%e6%80%a7/</link>
		<comments>http://www.lampblog.net/2012/05/%e4%bd%bf%e7%94%a8iptables%e5%8a%a0%e5%bc%bamemcache%e7%9a%84%e5%ae%89%e5%85%a8%e6%80%a7/#comments</comments>
		<pubDate>Fri, 11 May 2012 10:00:51 +0000</pubDate>
		<dc:creator>eagle</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[Ubuntu 命令]]></category>

		<guid isPermaLink="false">http://www.lampblog.net/?p=2331</guid>
		<description><![CDATA[Memcache服务器端都是直接通过客户端连接后直接操作，没有任何的验证过程，这样如果服务器是直接暴露在互联网上的话是比较危险，轻则数据泄露被其他无关人员查看，重则服务器被入侵，因为Mecache是以root权限运行的，况且里面可能存在一些我们未知的bug或者是缓冲区溢出的情况，这些都是我们未知的，所以危险性是可以预见的。为了安全起见，这里通过iptables对Memcach的连接做了限制，只有主机自己可以连接Memcahe，其他主机只能访问80和22端口程序。 代码如下 iptables -P INPUT DROP iptables -A INPUT -p tcp &#8211;dport ssh -j ACCEPT iptables -A INPUT -p tcp &#8211;dport 80 -j ACCEPT iptables -A INPUT -d 127.0.0.1 -j ACCEPT]]></description>
			<content:encoded><![CDATA[<p>Memcache服务器端都是直接通过客户端连接后直接操作，没有任何的验证过程，这样如果服务器是直接暴露在互联网上的话是比较危险，轻则数据泄露被其他无关人员查看，重则服务器被入侵，因为Mecache是以root权限运行的，况且里面可能存在一些我们未知的bug或者是缓冲区溢出的情况，这些都是我们未知的，所以危险性是可以预见的。为了安全起见，这里通过iptables对Memcach的连接做了限制，只有主机自己可以连接Memcahe，其他主机只能访问80和22端口程序。<br />
代码如下</p>
<p>iptables -P INPUT DROP<br />
iptables -A INPUT -p tcp &#8211;dport ssh -j ACCEPT<br />
iptables -A INPUT -p tcp &#8211;dport 80 -j ACCEPT<br />
iptables -A INPUT -d 127.0.0.1 -j ACCEPT</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lampblog.net/2012/05/%e4%bd%bf%e7%94%a8iptables%e5%8a%a0%e5%bc%bamemcache%e7%9a%84%e5%ae%89%e5%85%a8%e6%80%a7/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>清空iptables的方法</title>
		<link>http://www.lampblog.net/2012/05/%e6%b8%85%e7%a9%baiptables%e7%9a%84%e6%96%b9%e6%b3%95/</link>
		<comments>http://www.lampblog.net/2012/05/%e6%b8%85%e7%a9%baiptables%e7%9a%84%e6%96%b9%e6%b3%95/#comments</comments>
		<pubDate>Fri, 11 May 2012 08:52:15 +0000</pubDate>
		<dc:creator>eagle</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.lampblog.net/?p=2327</guid>
		<description><![CDATA[下面语句是清空iptables的方法 iptables -t nat -P PREROUTING ACCEPT iptables -t nat -P POSTROUTING ACCEPT iptables -t nat -P OUTPUT ACCEPT iptables -t nat -F iptables -t nat -X iptables -t mangle -P PREROUTING ACCEPT iptables -t mangle -P INPUT ACCEPT iptables -t mangle -P FORWARD ACCEPT iptables -t mangle -P OUTPUT ACCEPT iptables -t mangle -P [...]]]></description>
			<content:encoded><![CDATA[<p>下面语句是清空iptables的方法<br />
<code>iptables -t nat -P PREROUTING ACCEPT<br />
iptables -t nat -P POSTROUTING ACCEPT<br />
iptables -t nat -P OUTPUT ACCEPT<br />
iptables -t nat -F<br />
iptables -t nat -X<br />
iptables -t mangle -P PREROUTING ACCEPT<br />
iptables -t mangle -P INPUT ACCEPT<br />
iptables -t mangle -P FORWARD ACCEPT<br />
iptables -t mangle -P OUTPUT ACCEPT<br />
iptables -t mangle -P POSTROUTING ACCEPT<br />
iptables -t mangle -F<br />
iptables -t mangle -X<br />
iptables -t filter -P INPUT ACCEPT<br />
iptables -t filter -P FORWARD ACCEPT<br />
iptables -t filter -P OUTPUT ACCEPT<br />
iptables -t filter -F<br />
iptables -t filter -X</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.lampblog.net/2012/05/%e6%b8%85%e7%a9%baiptables%e7%9a%84%e6%96%b9%e6%b3%95/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>适合Web服务器的iptables规则</title>
		<link>http://www.lampblog.net/2012/05/%e9%80%82%e5%90%88web%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84iptables%e8%a7%84%e5%88%99/</link>
		<comments>http://www.lampblog.net/2012/05/%e9%80%82%e5%90%88web%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84iptables%e8%a7%84%e5%88%99/#comments</comments>
		<pubDate>Fri, 11 May 2012 06:38:10 +0000</pubDate>
		<dc:creator>eagle</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.lampblog.net/?p=2323</guid>
		<description><![CDATA[IPT=”/sbin/iptables” $IPT –delete-chain $IPT –flush $IPT -P INPUT DROP    #1 $IPT -P FORWARD DROP  #1 $IPT -P OUTPUT DROP   #1 $IPT -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT #2 $IPT -A INPUT -p tcp -m tcp –dport 80 -j ACCEPT #3 $IPT -A INPUT -p tcp -m tcp –dport 22 -j ACCEPT #3 [...]]]></description>
			<content:encoded><![CDATA[<div>
<ol title="Double click to hide line number.">
<li>IPT=”/sbin/iptables”</li>
<li>$IPT –delete-chain</li>
<li>$IPT –flush</li>
<li>$IPT -P INPUT DROP    #1</li>
<li>$IPT -P FORWARD DROP  #1</li>
<li>$IPT -P OUTPUT DROP   #1</li>
<li>$IPT -A INPUT -m state –state RELATED,ESTABLISHED -j ACCEPT #2</li>
<li>$IPT -A INPUT -p tcp -m tcp –dport 80 -j ACCEPT #3</li>
<li>$IPT -A INPUT -p tcp -m tcp –dport 22 -j ACCEPT #3</li>
<li>$IPT -A INPUT -p tcp -m tcp –dport 21 -j ACCEPT  #3</li>
<li>$IPT -A INPUT -p tcp -m tcp –dport 873 -j ACCEPT #3</li>
<li>$IPT -A INPUT -i lo -j ACCEPT #4</li>
<li>$IPT -A INPUT -p icmp -m icmp –icmp-type 8 -j ACCEPT  #5</li>
<li>$IPT -A INPUT -p icmp -m icmp –icmp-type 11 -j ACCEPT #5</li>
<li>$IPT -A OUTPUT -m state –state RELATED,ESTABLISHED -j ACCEPT #6</li>
<li>$IPT -A OUTPUT -p udp -m udp –dport 53 -j ACCEPT #7</li>
<li>$IPT -A OUTPUT -o lo -j ACCEPT #4</li>
<li>$IPT -A OUTPUT -p tcp -m tcp –dport 80 -j ACCEPT #8</li>
<li>$IPT -A OUTPUT -p tcp -m tcp –dport 25 -j ACCEPT #9</li>
<li>$IPT -A OUTPUT -p icmp -m icmp –icmp-type 8 -j ACCEPT  #10</li>
<li>$IPT -A OUTPUT -p icmp -m icmp –icmp-type 11 -j ACCEPT #10</li>
<li>service iptables save</li>
<li>service iptables restart</li>
</ol>
</div>
<p>存为脚本iptables.sh，执行sh iptables.sh自动配置防火墙。<br />
解释：<br />
#1、设置INPUT,FORWARD,OUTPUT链默认target为DROP，也就是外部与服务器不能通信。<br />
#2、设置当连接状态为RELATED和ESTABLISHED时，允许数据进入服务器。<br />
#3、设置外部客户端连接服务器端口80,22,21,873。<br />
#4、允许内部数据循回。<br />
#5、允许外部ping服务器 。<br />
#6、设置状态为RELATED和ESTABLISHED的数据可以从服务器发送到外部。<br />
#7、允许服务器使用外部dns解析域名。<br />
#8、设置服务器连接外部服务器端口80。<br />
#9、允许服务器发送邮件。<br />
#10、允许从服务器ping外部。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lampblog.net/2012/05/%e9%80%82%e5%90%88web%e6%9c%8d%e5%8a%a1%e5%99%a8%e7%9a%84iptables%e8%a7%84%e5%88%99/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>linux平台下防火墙iptables原理及用法简介</title>
		<link>http://www.lampblog.net/2012/05/linux%e5%b9%b3%e5%8f%b0%e4%b8%8b%e9%98%b2%e7%81%ab%e5%a2%99iptables%e5%8e%9f%e7%90%86%e5%8f%8a%e7%94%a8%e6%b3%95%e7%ae%80%e4%bb%8b/</link>
		<comments>http://www.lampblog.net/2012/05/linux%e5%b9%b3%e5%8f%b0%e4%b8%8b%e9%98%b2%e7%81%ab%e5%a2%99iptables%e5%8e%9f%e7%90%86%e5%8f%8a%e7%94%a8%e6%b3%95%e7%ae%80%e4%bb%8b/#comments</comments>
		<pubDate>Thu, 10 May 2012 06:54:17 +0000</pubDate>
		<dc:creator>eagle</dc:creator>
				<category><![CDATA[Ubuntu]]></category>

		<guid isPermaLink="false">http://www.lampblog.net/?p=2316</guid>
		<description><![CDATA[iptables简介     netfilter/iptables（简称为iptables）组成Linux平台下的包过滤防火墙，与大多数的Linux软件一样，这个包过滤防火墙是免费的，它可以代替昂贵的商业防火墙解决方案，完成封包过滤、封包重定向和网络地址转换（NAT）等功能。 iptables基础 规则（rules）其实就是网络管理员预定义的条件，规则一般的定义为“如果数据包头符合这样的条件，就这样处理这个数据包”。规则存储在内核空间的信息包过滤表中，这些规则分别指定了源地址、目的地址、传输协议（如TCP、UDP、ICMP）和服务类型（如HTTP、FTP和SMTP）等。当数据包与规则匹配时，iptables就根据规则所定义的方法来处理这些数据包，如放行（accept）、拒绝（reject）和丢弃（drop）等。配置防火墙的主要工作就是添加、修改和删除这些规则。 Iptables和netfilter的关系： 这是第一个要说的地方，Iptables和netfilter的关系是一个很容易让人搞不清的问题。很多的知道iptables却不知道netfilter。其实iptables只是Linux防火墙的管理工具而已，位于/sbin/iptables。真正实现防火墙功能的是netfilter，它是Linux内核中实现包过滤的内部结构。 iptables传输数据包的过程 ① 当一个数据包进入网卡时，它首先进入PREROUTING链，内核根据数据包目的IP判断是否需要转送出去。 ② 如果数据包就是进入本机的，它就会沿着图向下移动，到达INPUT链。数据包到了INPUT链后，任何进程都会收到它。本机上运行的程序可以发送数据包，这些数据包会经过OUTPUT链，然后到达POSTROUTING链输出。 ③ 如果数据包是要转发出去的，且内核允许转发，数据包就会如图所示向右移动，经过FORWARD链，然后到达POSTROUTING链输出。 Iptables的规则表和链： 表（tables）提供特定的功能，iptables内置了4个表，即filter表、nat表、mangle表和raw表，分别用于实现包过滤，网络地址转换、包重构(修改)和数据跟踪处理。    链（chains）是数据包传播的路径，每一条链其实就是众多规则中的一个检查清单，每一条链中可以有一条或数条规则。当一个数据包到达一个链时，iptables就会从链中第一条规则开始检查，看该数据包是否满足规则所定义的条件。如果满足，系统就会根据该条规则所定义的方法处理该数据包；否则iptables将继续检查下一条规则，如果该数据包不符合链中任一条规则，iptables就会根据该链预先定义的默认策略来处理数据包。 Iptables采用“表”和“链”的分层结构。在REHL4中是三张表五个链。现在REHL5成了四张表五个链了，不过多出来的那个表用的也不太多，所以基本还是和以前一样。下面罗列一下这四张表和五个链。注意一定要明白这些表和链的关系及作用。 规则表： 1.filter表——三个链：INPUT、FORWARD、OUTPUT 作用：过滤数据包  内核模块：iptables_filter. 2.Nat表——三个链：PREROUTING、POSTROUTING、OUTPUT 作用：用于网络地址转换（IP、端口） 内核模块：iptable_nat 3.Mangle表——五个链：PREROUTING、POSTROUTING、INPUT、OUTPUT、FORWARD 作用：修改数据包的服务类型、TTL、并且可以配置路由实现QOS内核模块：iptable_mangle(别看这个表这么麻烦，咱们设置策略时几乎都不会用到它) 4.Raw表——两个链：OUTPUT、PREROUTING 作用：决定数据包是否被状态跟踪机制处理  内核模块：iptable_raw (这个是REHL4没有的，不过不用怕，用的不多) 规则链： 1.INPUT——进来的数据包应用此规则链中的策略 2.OUTPUT——外出的数据包应用此规则链中的策略 3.FORWARD——转发数据包时应用此规则链中的策略 4.PREROUTING——对数据包作路由选择前应用此链中的规则 （记住！所有的数据包进来的时侯都先由这个链处理） 5.POSTROUTING——对数据包作路由选择后应用此链中的规则 （所有的数据包出来的时侯都先由这个链处理） 规则表之间的优先顺序： Raw——mangle——nat——filter 规则链之间的优先顺序（分三种情况）： 第一种情况：入站数据流向 从外界到达防火墙的数据包，先被PREROUTING规则链处理（是否修改数据包地址等），之后会进行路由选择（判断该数据包应该发往何处），如果数据包的目标主机是防火墙本机（比如说Internet用户访问防火墙主机中的web服务器的数据包），那么内核将其传给INPUT链进行处理（决定是否允许通过等），通过以后再交给系统上层的应用程序（比如Apache服务器）进行响应。 第二冲情况：转发数据流向 来自外界的数据包到达防火墙后，首先被PREROUTING规则链处理，之后会进行路由选择，如果数据包的目标地址是其它外部地址（比如局域网用户通过网关访问QQ站点的数据包），则内核将其传递给FORWARD链进行处理（是否转发或拦截），然后再交给POSTROUTING规则链（是否修改数据包的地址等）进行处理。 第三种情况：出站数据流向 防火墙本机向外部地址发送的数据包（比如在防火墙主机中测试公网DNS服务器时），首先被OUTPUT规则链处理，之后进行路由选择，然后传递给POSTROUTING规则链（是否修改数据包的地址等）进行处理。 管理和设置iptables规则 Iptables的基本语法格式： Iptables [-t 表名] 命令选项 ［链名］ [...]]]></description>
			<content:encoded><![CDATA[<p><strong>iptables简介</p>
<p></strong>    netfilter/iptables（简称为iptables）组成Linux平台下的包过滤防火墙，与大多数的Linux软件一样，这个包过滤防火墙是免费的，它可以代替昂贵的商业防火墙解决方案，完成封包过滤、封包重定向和网络地址转换（NAT）等功能。</p>
<p><strong>iptables基础<br />
</strong><br />
规则（rules）其实就是网络管理员预定义的条件，规则一般的定义为“如果数据包头符合这样的条件，就这样处理这个数据包”。规则存储在内核空间的信息包过滤表中，这些规则分别指定了源地址、目的地址、传输协议（如TCP、UDP、ICMP）和服务类型（如HTTP、FTP和SMTP）等。当数据包与规则匹配时，iptables就根据规则所定义的方法来处理这些数据包，如放行（accept）、拒绝（reject）和丢弃（drop）等。配置防火墙的主要工作就是添加、修改和删除这些规则。</p>
<p><strong>Iptables和netfilter的关系：</strong></p>
<p>这是第一个要说的地方，Iptables和netfilter的关系是一个很容易让人搞不清的问题。很多的知道iptables却不知道netfilter。其实iptables只是Linux防火墙的管理工具而已，位于/sbin/iptables。真正实现防火墙功能的是netfilter，它是Linux内核中实现包过滤的内部结构。</p>
<p><strong>iptables传输数据包的过程</strong></p>
<p>① 当一个数据包进入网卡时，它首先进入PREROUTING链，内核根据数据包目的IP判断是否需要转送出去。<br />
② 如果数据包就是进入本机的，它就会沿着图向下移动，到达INPUT链。数据包到了INPUT链后，任何进程都会收到它。本机上运行的程序可以发送数据包，这些数据包会经过OUTPUT链，然后到达POSTROUTING链输出。<br />
③ 如果数据包是要转发出去的，且内核允许转发，数据包就会如图所示向右移动，经过FORWARD链，然后到达POSTROUTING链输出。</p>
<div align="center"><a href="http://www.lampblog.net/wp-content/uploads/2012/05/iptables4.png"><img class="alignnone size-full wp-image-2317" title="iptables4" src="http://www.lampblog.net/wp-content/uploads/2012/05/iptables4.png" alt="" width="729" height="477" /></a></div>
<p><strong>Iptables的规则表和链：</strong></p>
<p>表（tables）提供特定的功能，iptables内置了4个表，即filter表、nat表、mangle表和raw表，分别用于实现包过滤，网络地址转换、包重构(修改)和数据跟踪处理。</p>
<p><strong>   </strong>链（chains）是数据包传播的路径，每一条链其实就是众多规则中的一个检查清单，每一条链中可以有一条或数条规则。当一个数据包到达一个链时，iptables就会从链中第一条规则开始检查，看该数据包是否满足规则所定义的条件。如果满足，系统就会根据该条规则所定义的方法处理该数据包；否则iptables将继续检查下一条规则，如果该数据包不符合链中任一条规则，iptables就会根据该链预先定义的默认策略来处理数据包。</p>
<p>Iptables采用“表”和“链”的分层结构。在REHL4中是三张表五个链。现在REHL5成了四张表五个链了，不过多出来的那个表用的也不太多，所以基本还是和以前一样。下面罗列一下这四张表和五个链。注意一定要明白这些表和链的关系及作用。</p>
<div align="center"><a href="http://www.lampblog.net/wp-content/uploads/2012/05/iptables3.png"><img class="alignnone size-full wp-image-2318" title="iptables3" src="http://www.lampblog.net/wp-content/uploads/2012/05/iptables3.png" alt="" width="749" height="428" /></a></div>
<p><strong>规则表：</p>
<p></strong>1.filter表——三个链：INPUT、FORWARD、OUTPUT<br />
作用：过滤数据包  内核模块：iptables_filter.<br />
2.Nat表——三个链：PREROUTING、POSTROUTING、OUTPUT<br />
作用：用于网络地址转换（IP、端口） 内核模块：iptable_nat<br />
3.Mangle表——五个链：PREROUTING、POSTROUTING、INPUT、OUTPUT、FORWARD<br />
作用：修改数据包的服务类型、TTL、并且可以配置路由实现QOS内核模块：iptable_mangle(别看这个表这么麻烦，咱们设置策略时几乎都不会用到它)<br />
4.Raw表——两个链：OUTPUT、PREROUTING<br />
作用：决定数据包是否被状态跟踪机制处理  内核模块：iptable_raw<br />
(这个是REHL4没有的，不过不用怕，用的不多)</p>
<p><strong>规则链：</p>
<p></strong>1.INPUT——进来的数据包应用此规则链中的策略<br />
2.OUTPUT——外出的数据包应用此规则链中的策略<br />
3.FORWARD——转发数据包时应用此规则链中的策略<br />
4.PREROUTING——对数据包作路由选择前应用此链中的规则<br />
（记住！所有的数据包进来的时侯都先由这个链处理）<br />
5.POSTROUTING——对数据包作路由选择后应用此链中的规则<br />
（所有的数据包出来的时侯都先由这个链处理）<br />
<strong>规则表之间的优先顺序：</p>
<p></strong>Raw——mangle——nat——filter<br />
规则链之间的优先顺序（分三种情况）：</p>
<p><strong>第一种情况：入站数据流向<br />
</strong><br />
从外界到达防火墙的数据包，先被PREROUTING规则链处理（是否修改数据包地址等），之后会进行路由选择（判断该数据包应该发往何处），如果数据包的目标主机是防火墙本机（比如说Internet用户访问防火墙主机中的web服务器的数据包），那么内核将其传给INPUT链进行处理（决定是否允许通过等），通过以后再交给系统上层的应用程序（比如Apache服务器）进行响应。</p>
<p><strong>第二冲情况：转发数据流向<br />
</strong><br />
来自外界的数据包到达防火墙后，首先被PREROUTING规则链处理，之后会进行路由选择，如果数据包的目标地址是其它外部地址（比如局域网用户通过网关访问QQ站点的数据包），则内核将其传递给FORWARD链进行处理（是否转发或拦截），然后再交给POSTROUTING规则链（是否修改数据包的地址等）进行处理。</p>
<p><strong>第三种情况：出站数据流向</strong><br />
防火墙本机向外部地址发送的数据包（比如在防火墙主机中测试公网DNS服务器时），首先被OUTPUT规则链处理，之后进行路由选择，然后传递给POSTROUTING规则链（是否修改数据包的地址等）进行处理。</p>
<p><strong>管理和设置iptables规则</strong></p>
<div align="center"><a href="http://www.lampblog.net/wp-content/uploads/2012/05/iptables1.jpg"><img class="alignnone size-full wp-image-2319" title="iptables1" src="http://www.lampblog.net/wp-content/uploads/2012/05/iptables1.jpg" alt="" width="690" height="365" /></a></div>
<div align="center"></div>
<div align="center">
<div align="center"><a href="http://www.lampblog.net/wp-content/uploads/2012/05/iptables2.jpg"><img class="alignnone size-full wp-image-2320" title="iptables2" src="http://www.lampblog.net/wp-content/uploads/2012/05/iptables2.jpg" alt="" width="690" height="465" /></a></div>
</div>
<p>Iptables的基本语法格式：<br />
Iptables [-t 表名] 命令选项 ［链名］ ［条件匹配］ ［-j 目标动作或跳转］<br />
说明：表名、链名用于指定iptables命令所操作的表和链，命令选项用于指定管理iptables规则的方式（比如：插入、增加、删除、查看等；条件匹配用于指定对符合什么样条件的数据包进行处理；目标动作或跳转用于指定数据包的处理方式（比如允许通过、拒绝、丢弃、跳转（Jump）给其它链处理。</p>
<p><strong>Iptables命令的管理控制选项：</strong></p>
<p>-A 在指定链的末尾添加（append）一条新的规则<br />
-D删除（delete）指定链中的某一条规则，可以按规则序号和内容删除<br />
-I在指定链中插入（insert）一条新的规则，默认在第一行添加<br />
-R修改、替换（replace）指定链中的某一条规则，可以按规则序号和内容替换<br />
-L列出（list）指定链中所有的规则进行查看<br />
-F清空（flush）<br />
-N新建（new-chain）一条用户自己定义的规则链<br />
-X删除指定表中用户自定义的规则链（delete-chain）<br />
-P设置指定链的默认策略（policy）<br />
-n使用数字形式（numeric）显示输出结果<br />
-v查看规则表详细信息（verbose）的信息<br />
-V查看版本(version)<br />
-h获取帮助（help）</p>
<p><strong>防火墙处理数据包的四种方式：</strong></p>
<p>ACCEPT 允许数据包通过<br />
DROP 直接丢弃数据包，不给任何回应信息<br />
REJECT 拒绝数据包通过，必要时会给数据发送端一个响应的信息。<br />
LOG在/var/log/messages文件中记录日志信息，然后将数据包传递给下一条规则</p>
<p><strong>iptables防火墙规则的保存与恢复<br />
</strong><br />
iptables-save把规则保存到文件中，再由目录rc.d下的脚本（/etc/rc.d/init.d/iptables）自动装载</p>
<p>使用命令iptables-save来保存规则。一般用</p>
<p>iptables-save &gt; /etc/sysconfig/iptables</p>
<p>生成保存规则的文件 /etc/sysconfig/iptables，</p>
<p>也可以用</p>
<p><span style="color: #dc143c;">service iptables save</span></p>
<p>它能把规则自动保存在/etc/sysconfig/iptables中。</p>
<p>当计算机启动时，rc.d下的脚本将用命令iptables-restore调用这个文件，从而就自动恢复了规则。</p>
<p><strong>删除INPUT链的第一条规则<br />
</strong><br />
<span style="color: #dc143c;">iptables -D INPUT 1</span></p>
<p><strong>Iptables防火墙常用的策略：<br />
</strong><br />
<span style="color: #dc143c;">1.拒绝进入防火墙的所有ICMP协议数据包</span><br />
iptables -I INPUT -p icmp -j REJECT</p>
<p>2.允许防火墙转发除ICMP协议以外的所有数据包<br />
iptables -A FORWARD -p ! icmp -j ACCEPT<br />
说明：使用“！”可以将条件取反。</p>
<p>3.拒绝转发来自192.168.1.10主机的数据，允许转发来自192.168.0.0/24网段的数据<br />
iptables -A FORWARD -s 192.168.1.11 -j REJECT<br />
iptables -A FORWARD -s 192.168.0.0/24 -j ACCEPT<br />
说明：注意要把拒绝的放在前面不然就不起作用了啊。</p>
<p>4.丢弃从外网接口（eth1）进入防火墙本机的源地址为私网地址的数据包<br />
iptables -A INPUT -i eth1 -s 192.168.0.0/16 -j DROP<br />
iptables -A INPUT -i eth1 -s 172.16.0.0/12 -j DROP<br />
iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP</p>
<p>5.封堵网段（192.168.1.0/24），两小时后解封。<br />
[root@server ~]# iptables -I INPUT -s 10.20.30.0/24 -j DROP<br />
[root@server ~]# iptables -I FORWARD -s 10.20.30.0/24 -j DROP<br />
[root@server ~]# at now +2 hours<br />
at&gt; iptables -D INPUT 1<br />
at&gt; iptables -D FORWARD 1<br />
说明：这个策略咱们借助crond计划任务来完成，就再好不过了。<br />
[1]+  Stopped     at now +2 hours</p>
<p><span style="color: #dc143c;">6.只允许管理员从202.13.0.0/16网段使用SSH远程登录防火墙主机。</span><br />
iptables -A INPUT -p tcp &#8211;dport 22 -s 202.13.0.0/16 -j ACCEPT<br />
iptables -A INPUT -p tcp &#8211;dport 22 -j DROP<br />
说明：这个用法比较适合对设备进行远程管理时使用，比如位于分公司中的SQL服务器需要被总公司的管理员管理时。</p>
<p>7.允许本机开放从TCP端口20-1024提供的应用服务。<br />
iptables -A INPUT -p tcp &#8211;dport 20:1024 -j ACCEPT<br />
iptables -A OUTPUT -p tcp &#8211;sport 20:1024 -j ACCEPT</p>
<p>8.允许转发来自192.168.0.0/24局域网段的DNS解析请求数据包。<br />
iptables -A FORWARD -s 192.168.0.0/24 -p udp &#8211;dport 53 -j ACCEPT<br />
iptables -A FORWARD -d 192.168.0.0/24 -p udp &#8211;sport 53 -j ACCEPT</p>
<p><span style="color: #dc143c;">9.禁止其他主机ping防火墙主机，但是允许从防火墙上ping其他主机</span><br />
iptables -I INPUT -p icmp &#8211;icmp-type Echo-Request -j DROP<br />
iptables -I INPUT -p icmp &#8211;icmp-type Echo-Reply -j ACCEPT<br />
iptables -I INPUT -p icmp &#8211;icmp-type destination-Unreachable -j ACCEPT</p>
<p>10.禁止转发来自MAC地址为00：0C：29：27：55：3F的和主机的数据包<br />
iptables -A FORWARD -m mac &#8211;mac-source 00:0c:29:27:55:3F -j DROP<br />
说明：iptables中使用“-m 模块关键字”的形式调用显示匹配。咱们这里用“-m mac –mac-source”来表示数据包的源MAC地址。</p>
<p>11.允许防火墙本机对外开放TCP端口20、21、25、110以及被动模式FTP端口1250-1280<br />
iptables -A INPUT -p tcp -m multiport &#8211;dport 20,21,25,110,1250:1280 -j ACCEPT<br />
说明：这里用“-m multiport –dport”来指定目的端口及范围</p>
<p>12.禁止转发源IP地址为192.168.1.20-192.168.1.99的TCP数据包。<br />
iptables -A FORWARD -p tcp -m iprange &#8211;src-range 192.168.1.20-192.168.1.99 -j DROP<br />
说明：此处用“-m –iprange –src-range”指定IP范围。</p>
<p>13.禁止转发与正常TCP连接无关的非—syn请求数据包。<br />
iptables -A FORWARD -m state &#8211;state NEW -p tcp ! &#8211;syn -j DROP<br />
说明：“-m state”表示数据包的连接状态，“NEW”表示与任何连接无关的，新的嘛！</p>
<p>14.拒绝访问防火墙的新数据包，但允许响应连接或与已有连接相关的数据包<br />
iptables -A INPUT -p tcp -m state &#8211;state NEW -j DROP<br />
iptables -A INPUT -p tcp -m state &#8211;state ESTABLISHED,RELATED -j ACCEPT<br />
说明：“ESTABLISHED”表示已经响应请求或者已经建立连接的数据包，“RELATED”表示与已建立的连接有相关性的，比如FTP数据连接等。</p>
<p><span style="color: #dc143c;">15.只开放本机的web服务（80）、FTP(20、21、20450-20480)，放行外部主机发住服务器其它端口的应答数据包，将其他入站数据包均予以丢弃处理。<br />
</span>iptables -I INPUT -p tcp -m multiport &#8211;dport 20,21,80 -j ACCEPT<br />
iptables -I INPUT -p tcp &#8211;dport 20450:20480 -j ACCEPT<br />
iptables -I INPUT -p tcp -m state &#8211;state ESTABLISHED -j ACCEPT<br />
iptables -P INPUT DROP</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lampblog.net/2012/05/linux%e5%b9%b3%e5%8f%b0%e4%b8%8b%e9%98%b2%e7%81%ab%e5%a2%99iptables%e5%8e%9f%e7%90%86%e5%8f%8a%e7%94%a8%e6%b3%95%e7%ae%80%e4%bb%8b/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>设置svn提交时必须填写注释</title>
		<link>http://www.lampblog.net/2012/04/%e8%ae%be%e7%bd%aesvn%e6%8f%90%e4%ba%a4%e6%97%b6%e5%bf%85%e9%a1%bb%e5%a1%ab%e5%86%99%e6%b3%a8%e9%87%8a/</link>
		<comments>http://www.lampblog.net/2012/04/%e8%ae%be%e7%bd%aesvn%e6%8f%90%e4%ba%a4%e6%97%b6%e5%bf%85%e9%a1%bb%e5%a1%ab%e5%86%99%e6%b3%a8%e9%87%8a/#comments</comments>
		<pubDate>Mon, 09 Apr 2012 09:38:59 +0000</pubDate>
		<dc:creator>eagle</dc:creator>
				<category><![CDATA[SVN]]></category>

		<guid isPermaLink="false">http://www.lampblog.net/?p=2311</guid>
		<description><![CDATA[如何设置SVN版本控制工具必须写注释才能提交： 当我们用tortoisesvn等SVN工具提交代码时，有很多人不喜欢写注释的而直接提交，这样一来代码版本多了，根本搞不清，哪个版本改了什么东西？所以如果加一些注释的话，我们看起来，也方便很多。所以在提交的时候，我会强制要求，写注释。如果对svn的安装配置不怎么了解，请参考：linux svn安装和配置，不结合apache 1, cd /home/svnuser/www/svn_test svn_test是一个代码仓库 2,mv ./hooks/pre-commit.tmpl ./hooks/pre-commit 将代码仓库根目录下，hooks文件夹中的pre-commit.tmpl文件重命名为pre-commit 3,vim ./hooks/pre-commit REPOS="$1" TXN="$2" # Make sure that the log message contains some text. SVNLOOK=/usr/bin/svnlook $SVNLOOK log -t "$TXN" "$REPOS" &#124; \ grep "[a-zA-Z0-9]" &#62; /dev/null &#124;&#124; exit 1 # Exit on all errors. set -e # Check that the author of this commit [...]]]></description>
			<content:encoded><![CDATA[<p>如何设置SVN版本控制工具必须写注释才能提交：<br />
当我们用tortoisesvn等SVN工具提交代码时，有很多人不喜欢写注释的而直接提交，这样一来代码版本多了，根本搞不清，哪个版本改了什么东西？所以如果加一些注释的话，我们看起来，也方便很多。所以在提交的时候，我会强制要求，写注释。如果对svn的安装配置不怎么了解，请参考：linux svn安装和配置，不结合apache<br />
1, cd /home/svnuser/www/svn_test svn_test是一个代码仓库<br />
2,mv ./hooks/pre-commit.tmpl ./hooks/pre-commit 将代码仓库根目录下，hooks文件夹中的pre-commit.tmpl文件重命名为pre-commit<br />
3,vim ./hooks/pre-commit</p>
<pre>
REPOS="$1"
TXN="$2"
# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
$SVNLOOK log -t "$TXN" "$REPOS" | \
grep "[a-zA-Z0-9]" &gt; /dev/null || exit 1
# Exit on all errors.
set -e
# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
"$REPOS"/hooks/commit-access-control.pl "$REPOS" $TXN \
"$REPOS"/hooks/commit-access-control.cfg 

# All checks passed, so allow the commit.
exit 0
</pre>
<p>上面是修改前的，看一下，下面的，修改后的。</p>
<pre>
REPOS="$1"
TXN="$2"
# Make sure that the log message contains some text.
SVNLOOK=/usr/bin/svnlook
LOGMSG=`$SVNLOOK log -t $TXN $REPOS | wc -m` //定义个变量，注意这里不是单引号
#$SVNLOOK log -t "$TXN" "$REPOS" | \ //把这一行和下面的一行注释掉
# grep "[a-zA-Z0-9]" &gt; /dev/null || exit 1 

echo $LOGMSG &gt; /home/administrator/www/aaa.txt //为了测试变量用的，查看$LOGMSG有没有值,最后要注释掉
if [ "$LOGMSG" -lt 48 ] //这里为什么是48呢，一个汉字对应16个字符
then
echo "\n至少输入4个汉字" &gt;&amp;2 //必须填四个汉字
exit 1
fi 

# Exit on all errors.
#set -e 

# Check that the author of this commit has the rights to perform
# the commit on the files and directories being modified.
#"$REPOS"/hooks/commit-access-control.pl "$REPOS" $TXN \ //把这一行和下面的一行注释掉。
# "$REPOS"/hooks/commit-access-control.cfg 

# All checks passed, so allow the commit.
exit 0
</pre>
<p>4,保存后，我们要给pre-commit这个文件，加可执行权限chmod +x pre-commit,有一点在说一下就是$SVNLOOK 前面的不是单引号，具体shell语法，请参考shell手册</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lampblog.net/2012/04/%e8%ae%be%e7%bd%aesvn%e6%8f%90%e4%ba%a4%e6%97%b6%e5%bf%85%e9%a1%bb%e5%a1%ab%e5%86%99%e6%b3%a8%e9%87%8a/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento产品类型说明</title>
		<link>http://www.lampblog.net/2012/03/magento%e4%ba%a7%e5%93%81%e7%b1%bb%e5%9e%8b%e8%af%b4%e6%98%8e/</link>
		<comments>http://www.lampblog.net/2012/03/magento%e4%ba%a7%e5%93%81%e7%b1%bb%e5%9e%8b%e8%af%b4%e6%98%8e/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 02:13:29 +0000</pubDate>
		<dc:creator>eagle</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://www.lampblog.net/?p=2307</guid>
		<description><![CDATA[Magento有六种产品类型：简单产品、分组产品、可配置产品、虚拟产品、捆绑产品和可下载产品，在添加产品时需要进行选择。所以我们有必要清楚每一种类型的含义： 简单产品：我们先了解一下Simple Product，因为这是所有产品类型的基础类型。正如其名，Simple Product是网店上最简单的产品，通过店主定义Simple Product的一些属性，就可以创建个性化的产品了。这类产品包含所有系统属性（因为所有类型的产品都有这些属性），你也可以给它添加Simple Attribute。比如一个简单Simple Product例子 – 西装。作为网店上面的一个独立的产品项目，店主可以为他定义颜色是黑色，有三个纽扣。那么当客户浏览网店的时候看到这件产品的颜色和纽扣的数量之后，他会决定是否购买这件西装。 分组产品：一样的理解，一个Grouped Product跟Configurable Product非常相似，也是一个可以在一个产品页面同时显示多个不同产品的功能。然而，它是显示不同的方式（Fashion）。还是上面的例子，刚才新添加上去的那些西装不要，只是那件有三个纽扣的黑色西装。在卖这件西装的同时，你还在卖西裤和衬衫，看起来这三个产品是一套的。仅使用Simple Product功能，每件产品都有单独的页面，共三个页面。但是，你比较有商业头脑，觉得这应该是一起销售的，因为它们是一套的。Grouped Product就可以很容易实现这个功能，只要创建一个Grouped Product（你可以为它起个名字，这里暂时叫“三件套”吧），并且你要把刚才的三个Simple Product跟这个关联。现在在您的网站上，看看这个Grouped Product的页面，它分块地列出了这三个Simple Product的信息。这样做是提醒您的客户它们是一套的，而且鼓励他们一起购买这三件产品，不过它们还是可以选择购买单件。 可配置的产品：一个Configurable Product是一种给客户提供更多选择项的产品类型。以为Simple Product是Configurable Product的基础，所以让我们继续用上面的西装作为例子。除了上面提到那件西装外，你开始销售不同型号的西装：深蓝色的版本，以及一个有四个纽扣的版本（有黑色和深蓝色的）。如果你只使用Simple Product功能的话，您需要创建三个新的Simple Product（深蓝色/3个按钮，黑色/4个按钮，以及深蓝色/ 4个按钮）。而且你有四个产品页面，每个有不同的颜色或纽扣。如果使用Configurable Product，你就可以把这四个产品合成一个产品项，从而使您的客户通过选项保证找到他们喜欢的西装，同时使客户尽可能容易的浏览您的网店。一旦你已经创建了四个Simple西装，您可以创建一个Configurable西装，并且把四个Simple西装关联到Configurable西装上。在你创建Configurable西装的时候你不需要设置好颜色或纽扣数目，这些属性值都是在客户购买时自己选择的。这是一个可配置的产品，因为您的客户可以自己配置属性值。所以，你可以选择不在网站上显示四个Simple Product，而只显示一个Configurable Product。当您的客户浏览这个产品时，会在产品信息下方看到两个下拉菜单，一个是颜色选择（有黑色和深蓝色选项），另一个是纽扣数量选择（有3和4选项）。这些选项将决定他们选择了哪个对应的Simple Product。因为这些属性决定了哪个Simple Product，那么Magento就会在订单生成的时候关联到对应的Simple Product。为什么这样做呢？因为Configurable Product并不是一个实在的产品，它只是一个可以在一个产品页面同时显示多个不同产品的功能而已。 虚拟的产品：这是指一些无需库存和运输的商品，主要用于服务业。例如培训商品，销售课程，服务等； 捆绑产品：这是一种打包销售的模式，可以将数个商品打包一起销售； 可下载产品：主要用于软件，电子书等商品，你的商品可以上传到网站所在的服务器，也可以提供一个下载地址给顾客；]]></description>
			<content:encoded><![CDATA[<p>Magento有六种产品类型：简单产品、分组产品、可配置产品、虚拟产品、捆绑产品和可下载产品，在添加产品时需要进行选择。所以我们有必要清楚每一种类型的含义：</p>
<p><a href="http://www.lampblog.net/wp-content/uploads/2012/03/495x269-images-stories-Magento-Magento10.jpg"><img class="alignnone size-full wp-image-2308" title="495x269-images-stories-Magento-Magento10" src="http://www.lampblog.net/wp-content/uploads/2012/03/495x269-images-stories-Magento-Magento10.jpg" alt="" width="495" height="269" /></a></p>
<p><strong>简单产品</strong>：我们先了解一下Simple Product，因为这是所有产品类型的基础类型。正如其名，Simple Product是网店上最简单的产品，通过店主定义Simple Product的一些属性，就可以创建个性化的产品了。这类产品包含所有系统属性（因为所有类型的产品都有这些属性），你也可以给它添加Simple Attribute。比如一个简单Simple Product例子 – 西装。作为网店上面的一个独立的产品项目，店主可以为他定义颜色是黑色，有三个纽扣。那么当客户浏览网店的时候看到这件产品的颜色和纽扣的数量之后，他会决定是否购买这件西装。</p>
<p><strong>分组产品</strong>：一样的理解，一个Grouped Product跟Configurable Product非常相似，也是一个可以在一个产品页面同时显示多个不同产品的功能。然而，它是显示不同的方式（Fashion）。还是上面的例子，刚才新添加上去的那些西装不要，只是那件有三个纽扣的黑色西装。在卖这件西装的同时，你还在卖西裤和衬衫，看起来这三个产品是一套的。仅使用Simple Product功能，每件产品都有单独的页面，共三个页面。但是，你比较有商业头脑，觉得这应该是一起销售的，因为它们是一套的。Grouped Product就可以很容易实现这个功能，只要创建一个Grouped Product（你可以为它起个名字，这里暂时叫“三件套”吧），并且你要把刚才的三个Simple Product跟这个关联。现在在您的网站上，看看这个Grouped Product的页面，它分块地列出了这三个Simple Product的信息。这样做是提醒您的客户它们是一套的，而且鼓励他们一起购买这三件产品，不过它们还是可以选择购买单件。</p>
<p><strong>可配置的产品</strong>：一个Configurable Product是一种给客户提供更多选择项的产品类型。以为Simple Product是Configurable Product的基础，所以让我们继续用上面的西装作为例子。除了上面提到那件西装外，你开始销售不同型号的西装：深蓝色的版本，以及一个有四个纽扣的版本（有黑色和深蓝色的）。如果你只使用Simple Product功能的话，您需要创建三个新的Simple Product（深蓝色/3个按钮，黑色/4个按钮，以及深蓝色/ 4个按钮）。而且你有四个产品页面，每个有不同的颜色或纽扣。如果使用Configurable Product，你就可以把这四个产品合成一个产品项，从而使您的客户通过选项保证找到他们喜欢的西装，同时使客户尽可能容易的浏览您的网店。一旦你已经创建了四个Simple西装，您可以创建一个Configurable西装，并且把四个Simple西装关联到Configurable西装上。在你创建Configurable西装的时候你不需要设置好颜色或纽扣数目，这些属性值都是在客户购买时自己选择的。这是一个可配置的产品，因为您的客户可以自己配置属性值。所以，你可以选择不在网站上显示四个Simple Product，而只显示一个Configurable Product。当您的客户浏览这个产品时，会在产品信息下方看到两个下拉菜单，一个是颜色选择（有黑色和深蓝色选项），另一个是纽扣数量选择（有3和4选项）。这些选项将决定他们选择了哪个对应的Simple Product。因为这些属性决定了哪个Simple Product，那么Magento就会在订单生成的时候关联到对应的Simple Product。为什么这样做呢？因为Configurable Product并不是一个实在的产品，它只是一个可以在一个产品页面同时显示多个不同产品的功能而已。</p>
<p><strong>虚拟的产品</strong>：这是指一些无需库存和运输的商品，主要用于服务业。例如培训商品，销售课程，服务等；</p>
<p><strong>捆绑产品</strong>：这是一种打包销售的模式，可以将数个商品打包一起销售；</p>
<p><strong>可下载产品</strong>：主要用于软件，电子书等商品，你的商品可以上传到网站所在的服务器，也可以提供一个下载地址给顾客；</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lampblog.net/2012/03/magento%e4%ba%a7%e5%93%81%e7%b1%bb%e5%9e%8b%e8%af%b4%e6%98%8e/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Magento 架构(Architecture)</title>
		<link>http://www.lampblog.net/2012/03/magento-%e6%9e%b6%e6%9e%84architecture/</link>
		<comments>http://www.lampblog.net/2012/03/magento-%e6%9e%b6%e6%9e%84architecture/#comments</comments>
		<pubDate>Wed, 28 Mar 2012 01:34:18 +0000</pubDate>
		<dc:creator>eagle</dc:creator>
				<category><![CDATA[Magento]]></category>

		<guid isPermaLink="false">http://www.lampblog.net/?p=2301</guid>
		<description><![CDATA[本节介绍Magento的架构，包括 1).请求响应流程图 2).magento各模块间的依赖关系 3).Magento数据库设计 一.Magento系统请求响应流程图 下面是具体请求步骤分析 用户向浏览器发出请求 浏览器向magento所在的服务器发出请求，magento的Controllers捕捉该请求并分发 Controller使用Oject Models,此时Magento的Model开始config(加载config.xml,system.xml,layout下的*.xml 等所有配置文件) Object Model 返回相应的数据(大部分是系统配置信息请研究Class Mage_Core_Model_Config和相关的类) Controller 根据layout下的*.xml的配置信息使用相应的Layouts Layout 使用Blocks(Blocks是Layout的骨架) Blocks使用Object Model(哈哈，这步是天经地义的，不通过Model使用数据库等相关的资源，Blocks就是巧妇难为无米之炊) Object Model 使用数据库资源 使用DB 返回DB资源 返回Datas给Object(主意Magento的Datas被加工成Object了) 返回datas对应的Object给Block Block使用Helpers(哈哈，Helpers其实就是打杂的，正如其名，作用完成一些特定的功能:更多Helpers参看：Mage_Core_Helper_Abstract 这是个高级话题，在system.xml配置的时候必须指定Helper) Helpers使用Object Models资源(Helpers打杂的最终目的-搞点东西回来) Object返回Helpers请求的资源 Helpers return HTML(哈哈，Helpers打杂主要就是处理一些HTML相关的东西)给Blocks Blocks使用Templates(不适用Template怎么把内容显示出来,这步也天经地义,没必要解释) Templates使用Helpers(Helpers有时需要配合一下Templates，如Helpers用于控制图像的显示等功能) Helpers 返回HTML或者data给Template Template返回HTML给Blocks(block其实就是页面的一部分自定义的区域) 返回HTML 返回HTML Controller使用Helpers(主要处理URLs相关的东西) &#8230;&#8230;..下面就不用解释了，不懂得google一下 二.Magento模块依赖关系图 模块之间的依赖没什么内容好说的，关键就是Mage_Core，还有非常重要的一点就是，参照上图来研究Magento Database 效率蛮高的。 三.Magento数据库设计 MAGENTO_v1.3.2.4&#8212;Database_Diagram 下载下来慢慢看了，这是最新的]]></description>
			<content:encoded><![CDATA[<p>本节介绍Magento的架构，包括</p>
<p>1).请求响应流程图</p>
<p>2).magento各模块间的依赖关系</p>
<h3>3).Magento数据库设计</h3>
<h3>一.Magento系统请求响应流程图</h3>
<p><a href="http://www.lampblog.net/wp-content/uploads/2012/03/face186e-be80-3847-8e60-5e72287f2f68.png"><img class="alignnone size-full wp-image-2302" title="face186e-be80-3847-8e60-5e72287f2f68" src="http://www.lampblog.net/wp-content/uploads/2012/03/face186e-be80-3847-8e60-5e72287f2f68.png" alt="" width="900" height="634" /></a></p>
<p>下面是具体请求步骤分析</p>
<ol>
<li>用户向浏览器发出请求</li>
<li>浏览器向magento所在的服务器发出请求，magento的Controllers捕捉该请求并分发</li>
<li>Controller使用Oject Models,此时Magento的Model开始config(加载config.xml,system.xml,layout下的*.xml 等所有配置文件)</li>
<li>Object Model 返回相应的数据(大部分是系统配置信息请研究Class Mage_Core_Model_Config和相关的类)</li>
<li>Controller 根据layout下的*.xml的配置信息使用相应的Layouts</li>
<li>Layout 使用Blocks(Blocks是Layout的骨架)</li>
<li>Blocks使用Object Model(哈哈，这步是天经地义的，不通过Model使用数据库等相关的资源，Blocks就是巧妇难为无米之炊)</li>
<li>Object Model 使用数据库资源</li>
<li>使用DB</li>
<li>返回DB资源</li>
<li>返回Datas给Object(主意Magento的Datas被加工成Object了)</li>
<li>返回datas对应的Object给Block</li>
<li>Block使用Helpers(哈哈，Helpers其实就是打杂的，正如其名，作用完成一些特定的功能:更多Helpers参看：Mage_Core_Helper_Abstract 这是个高级话题，在system.xml配置的时候必须指定Helper)</li>
<li>Helpers使用Object Models资源(Helpers打杂的最终目的-搞点东西回来)</li>
<li>Object返回Helpers请求的资源</li>
<li>Helpers return HTML(哈哈，Helpers打杂主要就是处理一些HTML相关的东西)给Blocks</li>
<li>Blocks使用Templates(不适用Template怎么把内容显示出来,这步也天经地义,没必要解释)</li>
<li>Templates使用Helpers(Helpers有时需要配合一下Templates，如Helpers用于控制图像的显示等功能)</li>
<li>Helpers 返回HTML或者data给Template</li>
<li>Template返回HTML给Blocks(block其实就是页面的一部分自定义的区域)</li>
<li>返回HTML</li>
<li>返回HTML</li>
<li>Controller使用Helpers(主要处理URLs相关的东西)</li>
<li>&#8230;&#8230;..下面就不用解释了，不懂得google一下</li>
</ol>
<h3>二.Magento模块依赖关系图</h3>
<p><a href="http://www.lampblog.net/wp-content/uploads/2012/03/42872435-6de1-3231-a402-23612939bb18.png"><img class="alignnone size-full wp-image-2303" title="42872435-6de1-3231-a402-23612939bb18" src="http://www.lampblog.net/wp-content/uploads/2012/03/42872435-6de1-3231-a402-23612939bb18.png" alt="" width="900" height="846" /></a></p>
<p>模块之间的依赖没什么内容好说的，关键就是Mage_Core，<strong>还有非常重要的一点就是，参照上图来研究Magento Database 效率蛮高的。</strong></p>
<h3><strong></strong>三.Magento数据库设计</h3>
<p><a href="http://www.lampblog.net/wp-content/uploads/2012/03/MAGENTO_v1.3.2.4-Database_Diagram.pdf">MAGENTO_v1.3.2.4&#8212;Database_Diagram</a></p>
<p>下载下来慢慢看了，这是最新的</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lampblog.net/2012/03/magento-%e6%9e%b6%e6%9e%84architecture/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>通过rsync+inotify-tools+ssh实现触发式远程实时同步</title>
		<link>http://www.lampblog.net/2012/03/%e9%80%9a%e8%bf%87rsyncinotify-toolsssh%e5%ae%9e%e7%8e%b0%e8%a7%a6%e5%8f%91%e5%bc%8f%e8%bf%9c%e7%a8%8b%e5%ae%9e%e6%97%b6%e5%90%8c%e6%ad%a5/</link>
		<comments>http://www.lampblog.net/2012/03/%e9%80%9a%e8%bf%87rsyncinotify-toolsssh%e5%ae%9e%e7%8e%b0%e8%a7%a6%e5%8f%91%e5%bc%8f%e8%bf%9c%e7%a8%8b%e5%ae%9e%e6%97%b6%e5%90%8c%e6%ad%a5/#comments</comments>
		<pubDate>Sat, 24 Mar 2012 06:12:59 +0000</pubDate>
		<dc:creator>eagle</dc:creator>
				<category><![CDATA[Ubuntu]]></category>
		<category><![CDATA[WEB架构]]></category>

		<guid isPermaLink="false">http://www.lampblog.net/?p=2297</guid>
		<description><![CDATA[文件的同步镜像在很多地方都需要用到，因此rsync这款免费软件得到了广泛的应用，包括在Windows平台上，都已经有了支持rsync的“cwRsyncServer”。 但是，我们一般都是通过结合crontab计划任务来实现文件同步的，这样做的缺点是效率低，不能做到实时同步。当然可以同编写一个脚本，时时监控！ 现在，在Linux平台下我们可以利用3.0内核的inotify监控文件系统机制，通过inotify-tools来实现实时同步了。 介绍inotify： Inotify 是一个 Linux特性，它监控文件系统操作，比如读取、写入和创建。Inotify 反应灵敏，用法非常简单，并且比 cron 任务的繁忙轮询高效得多。学习如何将 inotify 集成到您的应用程序中，并发现一组可用来进一步自动化系统治理的命令行工具。 具体操作如下： 1.安装所需软件 目前各大Linux发行版本都已经具有了rsync与inotify-tools的软件包，推荐通过apt-get等方式进行安装。 Ubuntu: [root@server1 ~]# apt-get install rsync inotify-tools 2.配置ssh key信任 建议通过普通用户进行操作，理由是通过root操作本身就危险，免密码登陆的root就更危险了。 在两台服务器上创建rsync用户 [root@server1 ~]# useradd -m rsync [root@server1 ~]# passwd rsync [root@server2 ~]# useradd -m rsync [root@server2 ~]# passwd rsync [root@server1 ~]# su – rsync [rsync@server1 ~]$ ssh-keygen -t rsa 在提示保存私钥（key）和公钥（public [...]]]></description>
			<content:encoded><![CDATA[<p>文件的同步镜像在很多地方都需要用到，因此rsync这款免费软件得到了广泛的应用，包括在Windows平台上，都已经有了支持rsync的“cwRsyncServer”。<br />
但是，我们一般都是通过结合crontab计划任务来实现文件同步的，这样做的缺点是效率低，不能做到实时同步。当然可以同编写一个脚本，时时监控！<br />
现在，在Linux平台下我们可以利用3.0内核的inotify监控文件系统机制，通过inotify-tools来实现实时同步了。</p>
<p>介绍inotify：</p>
<p>Inotify 是一个 Linux特性，它监控文件系统操作，比如读取、写入和创建。Inotify 反应灵敏，用法非常简单，并且比 cron 任务的繁忙轮询高效得多。学习如何将 inotify 集成到您的应用程序中，并发现一组可用来进一步自动化系统治理的命令行工具。<br />
具体操作如下：</p>
<p><strong>1.安装所需软件</strong><br />
目前各大Linux发行版本都已经具有了rsync与inotify-tools的软件包，推荐通过apt-get等方式进行安装。</p>
<p>Ubuntu:<br />
[root@server1 ~]# apt-get install rsync inotify-tools</p>
<p><strong>2.配置ssh key信任</strong><br />
建议通过普通用户进行操作，理由是通过root操作本身就危险，免密码登陆的root就更危险了。</p>
<p>在两台服务器上创建rsync用户<br />
[root@server1 ~]# useradd -m rsync<br />
[root@server1 ~]# passwd rsync<br />
[root@server2 ~]# useradd -m rsync<br />
[root@server2 ~]# passwd rsync</p>
<p>[root@server1 ~]# su – rsync<br />
[rsync@server1 ~]$ ssh-keygen -t rsa<br />
在提示保存私钥（key）和公钥（public key）的位置时，使用默认值；<br />
在提示是否需要私钥密码（passphrase）时，直接敲回车，即不使用私钥密码。<br />
之后，将生成一对密钥，id_rsa（私钥文件）和id_rsa.pub（公钥文件），保存在/home/rsync/.ssh/目录下。</p>
<p>将公钥添加到远程主机的 authorized_keys 文件中<br />
将文件上传到远程主机（假设远程主机IP为192.168.1.226）<br />
[rsync@server1 ~]$ scp ~/.ssh/id_rsa.pub rsync@192.168.1.226:/home/rsync/</p>
<p>使用rsync用户SSH到登陆到远程主机，并将公钥添加到 authorized_keys 文件中<br />
[rsync@server2 ~]$ mkdir .ssh<br />
[rsync@server2 ~]$ chmod 700 .ssh<br />
[rsync@server2 ~]$ mv ~/id_rsa.pub ~/.ssh/authorized_keys</p>
<p>重启SSH服务<br />
[root@server1 ~]# /etc/init.d/sshd restart<br />
[root@server2 ~]# /etc/init.d/sshd restart</p>
<p><strong>3.创建inotify_rsync.sh脚本</strong><br />
[root@server1 ~]# su – rsync<br />
[rsync@server1 ~]# vim inotify_rsync.sh</p>
<pre>
#!/bin/sh
SRC=/home/rsync/www
DST=rsync@192.168.1.226:/home/rsync/
INWT=/usr/bin/inotifywait
RSYNC=/usr/bin/rsync
$INWT -mrq -e create,move,delete,modify $SRC | while read D E F ; do
$RSYNC -aHqz --delete --exclude "\.svn" $SRC $DST
done
</pre>
<p>相关注解如下：<br />
/usr/bin/inotifywait -mrq -e modify,delete,create,attrib ${src}<br />
-m 是保持一直监听<br />
-r 是递归查看目录<br />
-q 是打印出事件<br />
-e create,move,delete,modify,attrib 是指 “监听 创建 移动 删除 写入 权限” 事件</p>
<p>/usr/bin/rsync -ahqzt &#8211;delete $SRC $DST<br />
-a 存档模式<br />
-h 保存硬连接<br />
-q 制止非错误信息<br />
-z 压缩文件数据在传输<br />
-t 维护修改时间<br />
-delete 删除于多余文件</p>
<p>要排除同步某个目录时，为rsync添加&#8211;exculde=PATTERN参数，注意，路径是相对路径，具体查看man rsync。<br />
要排除某个目录的事件监听的处理时，为inotifywait添加&#8211;exclude或&#8211;excludei参数，具体查看man inotifywait。</p>
<p>inotifywait 命令产生三个返回值，分别是“日期，时间，文件” 这3个返回值会做为参数传给read，因此脚本中的“while read D E F” 写法细化了返回值。</p>
<p>赋予脚本可执行权限<br />
[rsync@server1 ~]# chmod +x inotify_rsync.sh<br />
执行脚本<br />
[rsync@server1 ~]# /home/rsync/inotify_rsync.sh &amp;</p>
<p>设置脚本开机自启动<br />
[root@server1 ~]# cat “/root/inotify_rsync.sh &amp;” &gt;&gt; /etc/rc.local<br />
此处是以root添加开机自启动脚本，所以前面的ssh也要是root账号才行</p>
<p><strong>4.测试</strong><br />
首先在server1服务器的/home/rsync/test目录下创建文件或目录，然后再到server2的/home/rsync/test目录下查看，如果看到就说明成功了。<br />
[rsync@server1 ~]$ cd test<br />
[rsync@server1 test]$ touch a.txt<br />
注意：第一次SSH连接的时候可能需要输入一次密码，之后就不需要输入了。</p>
<p>[rsync@server2 ~]$ cd test<br />
[rsync@server2 test]$ ls<br />
a.txt</p>
<p>看到了a.txt文件，说明文件同步已经成功！</p>
]]></content:encoded>
			<wfw:commentRss>http://www.lampblog.net/2012/03/%e9%80%9a%e8%bf%87rsyncinotify-toolsssh%e5%ae%9e%e7%8e%b0%e8%a7%a6%e5%8f%91%e5%bc%8f%e8%bf%9c%e7%a8%8b%e5%ae%9e%e6%97%b6%e5%90%8c%e6%ad%a5/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

