个人工具
登录
查看“IptablesHowTo”的源代码 - Ubuntu中文
页面
讨论
查看源代码
历史
搜索
导航
首页
最近更改
随机页面
页面分类
帮助
编辑
编辑指南
沙盒
新闻动态
字词处理
工具
链入页面
相关更改
特殊页面
页面信息
查看“IptablesHowTo”的源代码
来自Ubuntu中文
←
IptablesHowTo
跳转至:
导航
,
搜索
因为以下原因,你没有权限编辑本页:
您所请求的操作仅限于该用户组的用户使用:
用户
您可以查看与复制此页面的源代码。
=== Allowing Incoming Traffic on Specific Ports 开放指定的端口 === You could start by blocking traffic, but you might be working over SSH, where you would need to allow SSH before blocking everything else. To allow incoming traffic on port 22 (traditionally used by SSH), you could tell iptables to allow all TCP traffic on port 22 of your network adapter. 刚开始时您不妨阻断所有通信,但考虑到您将来可能要使用SSH,那么您要让iptables在使用默认规则丢弃报文之前,允许SSH报文通过。 要开放端口22(SSH的默认端口),您要告诉iptables允许接受到的所有目标端口为22的TCP报文通过。 <pre><nowiki> # iptables -A INPUT -p tcp -i eth0 --dport ssh -j ACCEPT </nowiki></pre> Specifically, this appends (-A) to the table INPUT the rule that any traffic to the interface (-i) eth0 on the destination port for ssh that iptables should jump (-j), or perform the action, ACCEPT. 执行上面的命令,一条规则会被追加到INPUT规则表的末尾(-A表示追加)。根据这条规则,对所有从接口eth0(-i指出对通过哪个接口的报文运用此规则)接收到的目标端口为22的报文,iptables要执行ACCEPT行动(-j指明当报文与规则相匹配时应采取的行动)。 Lets check the rules: (only the first few lines shown, you will see more) 我们来看看规则表中的情况:(这里只列出了开始的几行,您应该会看到更多内容) <pre><nowiki> # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:ssh </nowiki></pre> Now, let's allow all web traffic 现在我们开放端口80: <pre><nowiki> # iptables -A INPUT -p tcp -i eth0 --dport 80 -j ACCEPT </nowiki></pre> Checking our rules, we have 此时的规则表中的内容如下: <pre><nowiki> # iptables -L Chain INPUT (policy ACCEPT) target prot opt source destination ACCEPT all -- anywhere anywhere state RELATED,ESTABLISHED ACCEPT tcp -- anywhere anywhere tcp dpt:ssh ACCEPT tcp -- anywhere anywhere tcp dpt:www </nowiki></pre> We have specifically allowed tcp traffic to the ssh and web ports, but as we have not blocked anything, all traffic can still come in. 通过上述命令,我们已经代开了SSH和web服务的相应的端口,但由于没有阻断任何通信,因此所有的报文都能通过。
返回至
IptablesHowTo
。