<?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_iptables%E9%98%B2%E7%81%AB%E5%A2%99%E5%9F%BA%E7%A1%80</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_iptables%E9%98%B2%E7%81%AB%E5%A2%99%E5%9F%BA%E7%A1%80"/>
	<link rel="alternate" type="text/html" href="https://wiki.linuxsa.org/index.php?title=Debian_iptables%E9%98%B2%E7%81%AB%E5%A2%99%E5%9F%BA%E7%A1%80&amp;action=history"/>
	<updated>2026-04-17T10:07:35Z</updated>
	<subtitle>本wiki上该页面的版本历史</subtitle>
	<generator>MediaWiki 1.43.1</generator>
	<entry>
		<id>https://wiki.linuxsa.org/index.php?title=Debian_iptables%E9%98%B2%E7%81%AB%E5%A2%99%E5%9F%BA%E7%A1%80&amp;diff=268&amp;oldid=prev</id>
		<title>2020年2月27日 (四) 09:03 Evan</title>
		<link rel="alternate" type="text/html" href="https://wiki.linuxsa.org/index.php?title=Debian_iptables%E9%98%B2%E7%81%AB%E5%A2%99%E5%9F%BA%E7%A1%80&amp;diff=268&amp;oldid=prev"/>
		<updated>2020-02-27T09:03:32Z</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;=Notice=&lt;br /&gt;
建议这个 firewalld 能安装 但是使用有点问题 放弃 2020&lt;br /&gt;
[[Ufw on debian]]&lt;br /&gt;
=install =&lt;br /&gt;
 apt install iptables&lt;br /&gt;
Debian已有firewalld 放弃iptables&lt;br /&gt;
&lt;br /&gt;
好像系统是自带的呢&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Debian配置iptables]]&lt;br /&gt;
&lt;br /&gt;
=来几个小例子=&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
#这个多端口应该是不行的 &lt;br /&gt;
iptables -A INPUT -p tcp -m muliport --dports 21,22,25,80,110 -j ACCEPT&lt;br /&gt;
&lt;br /&gt;
iptables -A INPUT -p tcp -m muliport --dports 21,22,25,80,110 -j DROP &lt;br /&gt;
&lt;br /&gt;
iptables -L -n --line-number&lt;br /&gt;
&lt;br /&gt;
查看设置的规则: sudo iptables -nvL --line-numbers&lt;br /&gt;
插入一条规则到INPUT链第6的位置: sudo iptables -I INPUT 6 -j DROP &lt;br /&gt;
修改INPUT链的第6条规则: sudo iptables -R INPUT 6 -j ACCEPT &lt;br /&gt;
删除INPUT链第6条规则: sudo iptables -D INPUT 6&lt;br /&gt;
&lt;br /&gt;
#保存配置  但是这个保存 机器重启就没了&lt;br /&gt;
iptables-save&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==官方例子==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
*filter&lt;br /&gt;
 &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 443 -j ACCEPT&lt;br /&gt;
 &lt;br /&gt;
# Allows SSH connections for script kiddies&lt;br /&gt;
# THE -dport NUMBER IS THE SAME ONE YOU SET UP IN THE SSHD_CONFIG FILE&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;
-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&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=开机自启动 自动加载实现=&lt;br /&gt;
&lt;br /&gt;
== iptables-persistent==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
apt  install iptables-persistent&lt;br /&gt;
&lt;br /&gt;
Save your firewall rules with this command:&lt;br /&gt;
      &lt;br /&gt;
debain9  or  Ubuntu 16.04 Server&lt;br /&gt;
netfilter-persistent save #这个为保存 &lt;br /&gt;
netfilter-persistent reload&lt;br /&gt;
&lt;br /&gt;
用iptables 删除的 好像不生效  只能在 配置 文件 /etc/iptables/rules.v4 删除 &lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== 写入文件 ==&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
1、将iptables配置保存到/etc/iptables，这个文件名可以自己定义，与下面的配置一致即可&lt;br /&gt;
&lt;br /&gt;
 iptables-save &amp;gt; /etc/iptables&lt;br /&gt;
&lt;br /&gt;
2、创建自启动配置文件，并授于可执行权限&lt;br /&gt;
 touch /etc/network/if-pre-up.d/iptables&lt;br /&gt;
 chmod +x /etc/network/if-pre-up.d/iptables&lt;br /&gt;
&lt;br /&gt;
3、编辑该自启动配置文件，内容为启动网络时恢复iptables配置&lt;br /&gt;
 vim /etc/network/if-pre-up.d/iptables&lt;br /&gt;
&lt;br /&gt;
文件内容如下：&lt;br /&gt;
 #!/bin/sh&lt;br /&gt;
 /sbin/iptables-restore &amp;lt; /etc/iptables&lt;br /&gt;
 &lt;br /&gt;
4、:wq保存配置文件并退出即可，以后在修改完iptables配置之后只要再次执行下面的命令保存即可&lt;br /&gt;
 iptables-save &amp;gt; /etc/iptables&lt;br /&gt;
&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
https://packages.debian.org/search?keywords=iptables-persistent&lt;br /&gt;
&lt;br /&gt;
=参考=&lt;br /&gt;
&lt;br /&gt;
https://wiki.debian.org/iptables&lt;br /&gt;
&lt;br /&gt;
https://wiki.debian.org/DebianFirewall&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[http://www.slyar.com/blog/vps-debian-iptables.html VPS安全之iptables基本配置(Debian)]&lt;br /&gt;
&lt;br /&gt;
[http://blog.linuxchina.net/?p=2813 myblog Ubuntu使用ufw或iptables配置防火墙]&lt;br /&gt;
&lt;br /&gt;
[https://www.thomas-krenn.com/en/wiki/Saving_Iptables_Firewall_Rules_Permanently Saving Iptables Firewall Rules Permanently]&lt;br /&gt;
&lt;br /&gt;
[http://chuansong.me/n/1490519851248 Debian/Ubuntu下使用iptables-persistent持久化iptables规则]&lt;br /&gt;
&lt;br /&gt;
[https://linuxconfig.org/how-to-install-missing-ifconfig-command-on-debian-linux How to install missing ifconfig command on Debian ]&lt;br /&gt;
&lt;br /&gt;
[http://salogs.com/news/2015/08/20/iptables-save/ 保存iptable规则并开机自动加载]&lt;br /&gt;
&lt;br /&gt;
[https://www.tennfy.com/2552.html Debian VPS下使用iptables防火墙]&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 [[category:ops]]   [[category:Security]]&lt;/div&gt;</summary>
		<author><name>Evan</name></author>
	</entry>
</feed>