【问题标题】:iptables are not forwarding any traffic to HAProxyiptables 没有将任何流量转发到 HAProxy
【发布时间】:2018-07-07 11:41:01
【问题描述】:

我遇到了以下问题:

我的路由器 (FritzBox) 设置为将所有传入流量(通过暴露的主机)转发到我的服务器 (192.168.0.1)

我有一个在 lxc 容器 (192.168.0.100) 上运行的 HAProxy,它将 http 流量转发到其他一些 lxc 容器 - 这工作正常。

问题是,当我运行以下命令(卷曲到我的代理)时,我得到了正确的答案:

curl --verbose --header 'Host: myrealdomain.tld' http://192.168.0.100


* Rebuilt URL to: http://192.168.0.100/
*   Trying 192.168.0.100...
* Connected to 192.168.0.100 (192.168.0.100) port 80 (#0)
> GET / HTTP/1.1
> Host: murdr.eu
> User-Agent: curl/7.47.0
> Accept: */*
>
* HTTP 1.0, assume close after body
< HTTP/1.0 503 Service Unavailable
< Cache-Control: no-cache
< Connection: close
< Content-Type: text/html
<
<html><body><h1>503 Service Unavailable</h1>
No server is available to handle this request.
</body></html>

* Closing connection 0

但是当运行相同的命令时(卷曲到我的服务器,它应该将流量转发到代理)我无法连接,因为连接被拒绝:

curl --verbose --header 'Host: myrealdomain.tld' http://192.168.0.1


* Rebuilt URL to: http://192.168.0.1/
*   Trying 192.168.0.1...
* connect to 192.168.0.1 port 80 failed: Connection refused
* Failed to connect to 192.168.0.1 port 80: Connection refused
* Closing connection 0
curl: (7) Failed to connect to 192.168.0.1 port 80: Connection refused

(myrealdomain.tld替换为我的真实域名,这里出于安全考虑我改了)

这是我的 iptables(我测试了各种东西并经常刷新,但没有任何效果)。

  • 我已经清除了它们,最好重新开始

iptables -L

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain FORWARD (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

iptables -L -t nat

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination

Chain INPUT (policy ACCEPT)
target     prot opt source               destination

Chain OUTPUT (policy ACCEPT)
target     prot opt source               destination

Chain POSTROUTING (policy ACCEPT)
target     prot opt source               destination

iptables -S(由 Luke Mlsna 提出)

-P INPUT ACCEPT
-P FORWARD ACCEPT
-P OUTPUT ACCEPT

apache2 正在我的服务器上运行。但我在设置代理容器和 iptables 后将其删除。

这里是开放的端口,没有 80 端口

lsof -i -P -n


COMMAND    PID            USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
systemd-n  938 systemd-network   19u  IPv6  33240      0t0  UDP [fe80::f64d:30ff:fe66:8010]:546
systemd-r  980 systemd-resolve   12u  IPv4  22967      0t0  UDP 127.0.0.53:53
systemd-r  980 systemd-resolve   13u  IPv4  22968      0t0  TCP 127.0.0.53:53 (LISTEN)
nmbd      1108            root   15u  IPv4  22474      0t0  UDP *:137
nmbd      1108            root   16u  IPv4  22475      0t0  UDP *:138
nmbd      1108            root   17u  IPv4  38559      0t0  UDP 192.168.0.1:137
nmbd      1108            root   18u  IPv4  38560      0t0  UDP 192.168.1.255:137
nmbd      1108            root   19u  IPv4  38561      0t0  UDP 192.168.0.1:138
nmbd      1108            root   20u  IPv4  38562      0t0  UDP 192.168.1.255:138
sshd      1200            root    3u  IPv4  25135      0t0  TCP *:22 (LISTEN)
sshd      1200            root    4u  IPv6  25137      0t0  TCP *:22 (LISTEN)
lxd       1273            root   13u  IPv6  27850      0t0  TCP *:8443 (LISTEN)
mysqld    1501           mysql   39u  IPv4  27943      0t0  TCP 127.0.0.1:3306 (LISTEN)
smbd      3606            root   32u  IPv6  37803      0t0  TCP *:445 (LISTEN)
smbd      3606            root   33u  IPv6  37804      0t0  TCP *:139 (LISTEN)
smbd      3606            root   34u  IPv4  37805      0t0  TCP *:445 (LISTEN)
smbd      3606            root   35u  IPv4  37806      0t0  TCP *:139 (LISTEN)
sshd      6140            root    3u  IPv4  59450      0t0  TCP 192.168.0.1:22->192.168.0.43:62339 (ESTABLISHED)
sshd      6350         unicorn    3u  IPv4  59450      0t0  TCP 192.168.0.1:22->192.168.0.43:62339 (ESTABLISHED)

【问题讨论】:

  • iptables -Siptables-save,我看不懂这种格式的废话。这看起来只是空白规则..?
  • 另外,你在/etc/sysctl.conf 中有ipv4.ip_forward=1set 吗?
  • 我已经添加了你对我的问题提出的问题,是的,它们现在是空白规则,因为没有任何效果(最好重新开始)
  • 是的,ipv4_forward 设置为 1
  • 503 = "你要求 HAproxy 代理一些不存在的东西" 它可能是代理 apache2 的东西,现在已经不存在了。所以它正在命中代理,但在那之后无处可去。

标签: haproxy iptables portforwarding


【解决方案1】:

我现在将我的流量从我的路由器直接发送到 HAProxy,中间没有服务器。 像魅力一样工作!

【讨论】:

    猜你喜欢
    • 2021-04-25
    • 1970-01-01
    • 2014-07-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-03
    • 2020-12-21
    相关资源
    最近更新 更多