加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – iptables错误:未知选项–dport

发布时间:2020-12-13 18:45:07 所属栏目:Linux 来源:网络整理
导读:在定义规则时,命令iptables不再识别最常用的选项之一:–dport. 我收到此错误: [root@dragonweyr /home/calyodelphi]# iptables -A INPUT --dport 7777 -j ACCEPT_TCP_UDPiptables v1.4.7: unknown option `--dport'Try `iptables -h' or 'iptables --help'
在定义规则时,命令iptables不再识别最常用的选项之一:–dport.

我收到此错误:

[root@dragonweyr /home/calyodelphi]# iptables -A INPUT --dport 7777 -j ACCEPT_TCP_UDP
iptables v1.4.7: unknown option `--dport'
Try `iptables -h' or 'iptables --help' for more information.

上面的add rule命令只是启用Terraria连接的示例.

这是我目前作为一个准确的iptables配置(listiptables别名为iptables -L -v -line-numbers),而且很明显–dport在过去有效:

root@dragonweyr /home/calyodelphi]# listiptables 
Chain INPUT (policy DROP 0 packets,0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         
1       39  4368 ACCEPT     all  --  lo     any     anywhere             anywhere            
2      114 10257 ACCEPT     all  --  any    any     anywhere             anywhere            state RELATED,ESTABLISHED 
3        1    64 ACCEPT     tcp  --  eth1   any     anywhere             anywhere            tcp dpt:EtherNet/IP-1 
4       72 11610 ACCEPT     all  --  eth1   any     anywhere             anywhere            

Chain FORWARD (policy ACCEPT 0 packets,0 bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain OUTPUT (policy ACCEPT 91 packets,10045 bytes)
num   pkts bytes target     prot opt in     out     source               destination         

Chain ACCEPT_TCP_UDP (0 references)
num   pkts bytes target     prot opt in     out     source               destination         
1        0     0 ACCEPT     tcp  --  any    any     anywhere             anywhere

我也试图定义一个自定义链(灵感来自this question)接受tcp& udp连接,这样我就不必为我想要启用tcp和udp的所有东西定义两个规则(例如Minecraft或Terraria服务器,或者完全是另一个服务).但即使这样也行不通:

[root@dragonweyr /home/calyodelphi]# iptables -P ACCEPT_TCP_UDP DROP
iptables: Bad built-in chain name.

这有点令人沮丧,用礼貌的语言来说(与此有关的诅咒会让水手告诉我看着我的嘴).我的Google-fu非常糟糕,所以我还没有找到任何一个可行的解决方案.我在路由器上运行CentOS 6.5.你们可以提供的任何帮助和指示都会很棒.

编辑:

奖金问题:我也计划配置端口转发.是否仍然需要设置规则来接受特定端口上的传入连接?

解决方法

首先给出-p选项,如-p tcp或-p udp.

例子:

iptables -A INPUT -p tcp –dport 22 -m state –state NEW -j DROP

iptables -A INPUT -p udp –dport 53 –sport 1024:65535 -j ACCEPT

您也可以尝试-p all但我从未这样做过,并且在示例中没有找到太多的支持.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读