iptables转发端口错误-该名称没有链/目标/匹配


11

我正在尝试在Ubuntu 12.04 LTS服务器上配置iptables以将端口443转发到8443。

但是当我运行此命令时:

sudo iptables -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443

我收到以下错误:

iptables: No chain/target/match by that name.

我的iptables当前配置:

$ sudo iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination         
ACCEPT     tcp  --  anywhere             anywhere             tcp dpt:https
DROP       tcp  --  anywhere             anywhere             tcp dpt:http

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination         

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination 

我想念什么或做错什么?

Answers:


18

因为PREROUTING链属于NAT表,而不是FILTER表。如果未按-t选项明确提及任何表,则FILTER假定为。

因此,您需要使用来提及表类型-t nat

sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443

请注意,MANGLE并且RAW表也​​具有PREROUTING链,但是由于您仅重定向端口,因此大概是在寻找NAT表。


它仍然给我同样的错误。这个答案仍然有效吗?
piepi,

@piepi是的。应该是有效的。也许您应该详细询问您的问题。
heemayl

赞成,也许您可​​以回答这个类似的问题:askubuntu.com/questions/1140644/…–
WinEunuuchs2Unix

3

PREROUTING链仅适用于nat,mangle和raw表。
iptables假定使用过滤器表,因此您必须指定其中之一,例如。iptables -t nat ...


3

运行docker命令时出现类似错误

docker run -d -p 8084:8080 knockdata/zeppelin-highcharts


d9c5d34f500d621585470b0e70b915395fcb6b3437859e0f610dbb58d51faf25
docker: Error response from daemon: driver failed programming external connectivity on endpoint elegant_jang  
(7ca0f5ad689f5443ce7533f66b4a86c34d2dbd9d076bac4812288dd3f6a76698):  
iptables failed: iptables --wait -t nat -A DOCKER -p tcp -d 0/0 --dport 8084 -j DNAT --to-destination 172.17.0.2:8080 
! -i docker0: iptables: No chain/target/match by that name.
(exit status 1).

我能够通过重新安装docker-engine来修复它

apt-get remove docker-engine
apt-get install docker-engine

0

您可以安装(配置服务器安全和防火墙)并使用以下设置。

nano /etc/csf/csf.conf
SYNFLOOD = "" => SYNFLOOD = "1"
CONNLIMIT = "" => CONNLIMIT = "80;75,443;75,21;50”
PORTFLOOD = "" => PORTFLOOD = "80;tcp;5;250"
SYSLOG = “0” => SYSLOG = "1"
DOCKER = “0” => DOCKER = "1"

nano /etc/csf/csfpost.sh

#!/bin/sh

echo "[DOCKER] Setting up FW rules."

iptables -N DOCKER

iptables -t nat -N DOCKER

iptables -t nat -A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER

iptables -t nat -A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER

# Masquerade outbound connections from containers
iptables -t nat -A POSTROUTING -s 172.17.0.0/16 ! -o docker0 -j MASQUERADE

# Accept established connections to the docker containers
iptables -t filter -N DOCKER
iptables -t filter -A FORWARD -o docker0 -j DOCKER
iptables -t filter -A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j 
ACCEPT

# Allow docker containers to communicate with themselves & outside world
iptables -t filter -A FORWARD -i docker0 ! -o docker0 -j ACCEPT
iptables -t filter -A FORWARD -i docker0 -o docker0 -j ACCEPT

echo "[DOCKER] Done."

注意:此配置还可以防止您受到基本的DDOS攻击。

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.