<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.riguz.com/index.php?action=history&amp;feed=atom&amp;title=CentOS%3Aiptables%E8%AE%BE%E7%BD%AE</id>
	<title>CentOS:iptables设置 - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.riguz.com/index.php?action=history&amp;feed=atom&amp;title=CentOS%3Aiptables%E8%AE%BE%E7%BD%AE"/>
	<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=CentOS:iptables%E8%AE%BE%E7%BD%AE&amp;action=history"/>
	<updated>2026-06-03T04:03:45Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.42.3</generator>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=CentOS:iptables%E8%AE%BE%E7%BD%AE&amp;diff=1283&amp;oldid=prev</id>
		<title>2015年8月27日 (四) 16:12 imported&gt;Soleverlee</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=CentOS:iptables%E8%AE%BE%E7%BD%AE&amp;diff=1283&amp;oldid=prev"/>
		<updated>2015-08-27T16:12:23Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2015年8月27日 (四) 16:12的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l42&quot;&gt;第42行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第42行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Image:CentOS_Iptables.png]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Image:CentOS_Iptables.png]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-side-deleted&quot;&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&lt;ins style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;&lt;/ins&gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;下面是配置后得到的iptables 文件：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;下面是配置后得到的iptables 文件：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>imported&gt;Soleverlee</name></author>
	</entry>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=CentOS:iptables%E8%AE%BE%E7%BD%AE&amp;diff=1282&amp;oldid=prev</id>
		<title>2015年8月27日 (四) 16:12 imported&gt;Soleverlee</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=CentOS:iptables%E8%AE%BE%E7%BD%AE&amp;diff=1282&amp;oldid=prev"/>
		<updated>2015-08-27T16:12:07Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table style=&quot;background-color: #fff; color: #202122;&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;zh-Hans-CN&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;←上一版本&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #202122; text-align: center;&quot;&gt;2015年8月27日 (四) 16:12的版本&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l41&quot;&gt;第41行：&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;第41行：&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;iptables -D INPUT -s ***.***.***.*** -j DROP&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;iptables -D INPUT -s ***.***.***.*** -j DROP&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;/source&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;−&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Image:CentOS_Iptables.png&lt;del style=&quot;font-weight: bold; text-decoration: none;&quot;&gt;|right&lt;/del&gt;]]&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot; data-marker=&quot;+&quot;&gt;&lt;/td&gt;&lt;td style=&quot;color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;[[Image:CentOS_Iptables.png]]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;下面是配置后得到的iptables 文件：&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;下面是配置后得到的iptables 文件：&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;td class=&quot;diff-marker&quot;&gt;&lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #202122; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;/table&gt;</summary>
		<author><name>imported&gt;Soleverlee</name></author>
	</entry>
	<entry>
		<id>https://wiki.riguz.com/index.php?title=CentOS:iptables%E8%AE%BE%E7%BD%AE&amp;diff=1281&amp;oldid=prev</id>
		<title>imported&gt;Soleverlee：​以“以下记录为阿里云服务器开启iptables。因为是SSH登录的，所以小心一启动防火墙，连接中断了噢~ 哈哈 &lt;source lang=&quot;bash&quot;&gt; #首先在...”为内容创建页面</title>
		<link rel="alternate" type="text/html" href="https://wiki.riguz.com/index.php?title=CentOS:iptables%E8%AE%BE%E7%BD%AE&amp;diff=1281&amp;oldid=prev"/>
		<updated>2015-08-27T16:11:26Z</updated>

		<summary type="html">&lt;p&gt;以“以下记录为阿里云服务器开启iptables。因为是SSH登录的，所以小心一启动防火墙，连接中断了噢~ 哈哈 &amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt; #首先在...”为内容创建页面&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;以下记录为阿里云服务器开启iptables。因为是SSH登录的，所以小心一启动防火墙，连接中断了噢~ 哈哈&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
#首先在清除前要将policy INPUT改成ACCEPT,表示接受一切请求。&lt;br /&gt;
#这个一定要先做，不然清空后可能会悲剧&lt;br /&gt;
iptables -P INPUT ACCEPT&lt;br /&gt;
#清空默认所有规则&lt;br /&gt;
iptables -F&lt;br /&gt;
#清空自定义的所有规则&lt;br /&gt;
iptables -X&lt;br /&gt;
#计数器置0&lt;br /&gt;
iptables -Z&lt;br /&gt;
&lt;br /&gt;
#允许来自于lo接口的数据包&lt;br /&gt;
#如果没有此规则，你将不能通过127.0.0.1访问本地服务，例如ping 127.0.0.1&lt;br /&gt;
iptables -A INPUT -i lo -j ACCEPT&lt;br /&gt;
#ssh端口22&lt;br /&gt;
iptables -A INPUT -p tcp --dport 22 -j ACCEPT&lt;br /&gt;
#FTP端口21&lt;br /&gt;
iptables -A INPUT -p tcp --dport 21 -j ACCEPT&lt;br /&gt;
#web服务端口80&lt;br /&gt;
iptables -A INPUT -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
#tomcat&lt;br /&gt;
iptables -A INPUT -p tcp --dport xxxx -j ACCEPT&lt;br /&gt;
#mysql&lt;br /&gt;
iptables -A INPUT -p tcp --dport xxxx -j ACCEPT&lt;br /&gt;
#允许icmp包通过,也就是允许ping&lt;br /&gt;
iptables -A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT&lt;br /&gt;
#允许所有对外请求的返回包&lt;br /&gt;
#本机对外请求相当于OUTPUT,对于返回数据包必须接收啊，这相当于INPUT了&lt;br /&gt;
iptables -A INPUT -m state --state ESTABLISHED -j ACCEPT&lt;br /&gt;
#如果要添加内网ip信任（接受其所有TCP请求）&lt;br /&gt;
iptables -A INPUT -p tcp -s 45.96.174.68 -j ACCEPT&lt;br /&gt;
#过滤所有非以上规则的请求&lt;br /&gt;
iptables -P INPUT DROP&lt;br /&gt;
#要封停一个IP，使用下面这条命令：&lt;br /&gt;
&lt;br /&gt;
iptables -I INPUT -s ***.***.***.*** -j DROP&lt;br /&gt;
&lt;br /&gt;
#要解封一个IP，使用下面这条命令:&lt;br /&gt;
&lt;br /&gt;
iptables -D INPUT -s ***.***.***.*** -j DROP&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
[[Image:CentOS_Iptables.png|right]]&lt;br /&gt;
下面是配置后得到的iptables 文件：&lt;br /&gt;
&amp;lt;source lang=&amp;quot;bash&amp;quot;&amp;gt;&lt;br /&gt;
# iptables-save &amp;gt; /etc/sysconfig/iptables&lt;br /&gt;
# Generated by iptables-save v1.4.7 on Fri Aug 28 00:04:35 2015&lt;br /&gt;
*filter&lt;br /&gt;
:INPUT DROP [1:40]&lt;br /&gt;
:FORWARD ACCEPT [0:0]&lt;br /&gt;
:OUTPUT ACCEPT [279:28212]&lt;br /&gt;
-A INPUT -i lo -j ACCEPT&lt;br /&gt;
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT&lt;br /&gt;
-A INPUT -p tcp -m tcp --dport 21 -j ACCEPT&lt;br /&gt;
-A INPUT -p tcp -m tcp --dport 80 -j ACCEPT&lt;br /&gt;
-A INPUT -p tcp -m tcp --dport 9306 -j ACCEPT&lt;br /&gt;
-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT&lt;br /&gt;
-A INPUT -m state --state ESTABLISHED -j ACCEPT&lt;br /&gt;
COMMIT&lt;br /&gt;
# Completed on Fri Aug 28 00:04:35 2015&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
[[Category:Linux/Unix]]&lt;/div&gt;</summary>
		<author><name>imported&gt;Soleverlee</name></author>
	</entry>
</feed>