<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="zh-Hans-CN">
	<id>https://wiki.linuxsa.org/index.php?action=history&amp;feed=atom&amp;title=Debian%E9%85%8D%E7%BD%AEiptables</id>
	<title>Debian配置iptables - 版本历史</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.linuxsa.org/index.php?action=history&amp;feed=atom&amp;title=Debian%E9%85%8D%E7%BD%AEiptables"/>
	<link rel="alternate" type="text/html" href="https://wiki.linuxsa.org/index.php?title=Debian%E9%85%8D%E7%BD%AEiptables&amp;action=history"/>
	<updated>2026-04-23T09:21:17Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://wiki.linuxsa.org/index.php?title=Debian%E9%85%8D%E7%BD%AEiptables&amp;diff=276&amp;oldid=prev</id>
		<title>2020年2月26日 (三) 02:54 Evan</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxsa.org/index.php?title=Debian%E9%85%8D%E7%BD%AEiptables&amp;diff=276&amp;oldid=prev"/>
		<updated>2020-02-26T02:54:44Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新页面&lt;/b&gt;&lt;/p&gt;&lt;div&gt;=iptables=&lt;br /&gt;
Debian已有firewalld 放弃iptables&lt;br /&gt;
Debian默认已经安装iptables，查看规则iptables -L默认允许所有出入，这是非常不安全的，因此需要对规则进行调整。&lt;br /&gt;
&lt;br /&gt;
编辑配置文件：&lt;br /&gt;
 vim /etc/iptables.up.rules&lt;br /&gt;
&lt;br /&gt;
添加下面的规则，请根据实际情况调整：&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*filter&lt;br /&gt;
&lt;br /&gt;
#ssh&lt;br /&gt;
-A INPUT -p tcp --dport 22 -j ACCEPT&lt;br /&gt;
# Allows all loopback (lo0) traffic and drop all traffic to 127/8 that doesn&amp;#039;t use lo0&lt;br /&gt;
-A INPUT -i lo -j ACCEPT&lt;br /&gt;
-A INPUT ! -i lo -d 127.0.0.0/8 -j REJECT&lt;br /&gt;
&lt;br /&gt;
# Accepts all established inbound connections&lt;br /&gt;
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Allows all outbound traffic&lt;br /&gt;
# You could modify this to only allow certain traffic&lt;br /&gt;
-A OUTPUT -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Allows HTTP and HTTPS connections from anywhere (the normal ports for websites)&lt;br /&gt;
#-A INPUT -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
#-A INPUT -p tcp --dport 80 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Allows SSH connections &lt;br /&gt;
# The --dport number is the same as in /etc/ssh/sshd_config&lt;br /&gt;
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# Now you should read up on iptables rules and consider whether ssh access &lt;br /&gt;
# for everyone is really desired. Most likely you will only allow access from certain IPs.&lt;br /&gt;
&lt;br /&gt;
# Allow ping&lt;br /&gt;
#  note that blocking other types of icmp packets is considered a bad idea by some&lt;br /&gt;
#  remove -m icmp --icmp-type 8 from this line to allow all kinds of icmp:&lt;br /&gt;
#  https://security.stackexchange.com/questions/22711&lt;br /&gt;
#-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
# log iptables denied calls (access via &amp;#039;dmesg&amp;#039; command)&lt;br /&gt;
-A INPUT -m limit --limit 5/min -j LOG --log-prefix &amp;quot;iptables denied: &amp;quot; --log-level 7&lt;br /&gt;
&lt;br /&gt;
# Reject all other inbound - default deny unless explicitly allowed policy:&lt;br /&gt;
-A INPUT -j REJECT&lt;br /&gt;
-A FORWARD -j REJECT&lt;br /&gt;
&lt;br /&gt;
COMMIT  &amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
激活规则：&lt;br /&gt;
 iptables-restore &amp;lt; /etc/iptables.test.rules&lt;br /&gt;
&lt;br /&gt;
开机自动加载规则&lt;br /&gt;
编辑配置&lt;br /&gt;
 vi /etc/network/if-pre-up.d/iptables&lt;br /&gt;
&lt;br /&gt;
添加如下内容&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#!/bin/sh&lt;br /&gt;
 /sbin/iptables-restore &amp;lt; /etc/iptables.up.rules&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
添加执行权限&lt;br /&gt;
 chmod +x /etc/network/if-pre-up.d/iptables&lt;br /&gt;
&lt;br /&gt;
保存规则到主配置文件：&lt;br /&gt;
 iptables-save &amp;gt; /etc/iptables.up.rules&lt;br /&gt;
&lt;br /&gt;
=参考=&lt;br /&gt;
[[大话iptables]]&lt;br /&gt;
&lt;br /&gt;
[[Iptables模块]]&lt;br /&gt;
&lt;br /&gt;
[https://www.centos.bz/2017/10/debian%E9%85%8D%E7%BD%AEiptables/ Debian配置iptables]&lt;br /&gt;
&lt;br /&gt;
https://wiki.debian.org/iptables&lt;br /&gt;
&lt;br /&gt;
[[category:debian]] [[category:Security]]  [[category:ops]]&lt;/div&gt;</summary>
		<author><name>Evan</name></author>
	</entry>
</feed>