ssh隧道正常工作时,NAT端口转发不起作用

时间:2018-10-06 09:05:23

标签: apache iptables portforwarding lxc

我有一个LXC容器apache2安装(容器在192.168.122.179:80上侦听)。

主机为10.138.141.216。

如果我通过ssh建立隧道:  ssh -L 45678:192.168.122.179:80 myuser@10.138.141.216 从我的电脑上,我得到了apache2页面(浏览器到http://localhost:45678

但是,如果我断开ssh隧道并仅使用iptables http://10.138.141.216:45678,将无法正常工作:

[~]$ sudo iptables -t nat -L -n -v
Chain PREROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    9   564 DNAT       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:45678 to:192.168.122.179:80

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

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

Chain POSTROUTING (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 RETURN     all  --  *      *       192.168.122.0/24     224.0.0.0/24
    2   656 RETURN     all  --  *      *       192.168.122.0/24     255.255.255.255
  606 36360 MASQUERADE  tcp  --  *      *       192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535
    0     0 MASQUERADE  udp  --  *      *       192.168.122.0/24    !192.168.122.0/24     masq ports: 1024-65535
  725  101K MASQUERADE  all  --  *      *       192.168.122.0/24    !192.168.122.0/24

每当我在浏览器中刷新页面时,我都可以看到pkts和字节数发生了变化,但是我得到的只是“无法访问此站点”。

因此ssh隧道有效,而iptables规则不起作用...

更新:

使用tcpdump可以看到“ tcp port eba无法访问”,为什么?

14:46:40.672318 IP 10.79.41.37.57504 > mymachine.eba: Flags [S], seq 2646922897, win 8192, options [mss 1360,nop,wscale 8,nop,nop,sackOK,unknown-33 0x21cc167ee1203a070000], length 0
14:46:40.672402 IP mymachine > 10.79.41.37: ICMP mymachine tcp port eba unreachable, length 72

wget http://192.168.122.179从主机内部运行...

2 个答案:

答案 0 :(得分:1)

我不知道为什么,但是默认情况下LXC添加了以下规则:

# solution 3

fun2 <- function(x, y, a) (1 / a) * exp(-x^2 - y^2) # same as in question

integral2a <- function (fun, xmin, xmax, ymin, ymax, ..., 
  sector = FALSE, reltol = 1e-06, abstol = 0, maxlist = 5000, 
  singular = FALSE, vectorized = TRUE) {}
body(integral2a) <- body(integral2)
environment(integral2a) <- environment(integral2)

integral2a(fun2,
          xmin = 0,
          xmax = 1,
          ymin = 0,
          ymax = 1,
          a = 1)$Q
## [1] 0.5577463

这些在使用时不可见

iptables -t任何 -L -n -v

删除“ -t any”显示它们。 删除这些规则可以解决问题。

答案 1 :(得分:0)

Apache通常由主机配置。每个主机都监听来自特定域名的请求。

为了使主机可访问,您需要侦听IP本身或获取主机名,或在Apache主机配置中设置默认主机。

您可以使用wget或curl在localhost上执行get请求来测试主机配置是否有效。

如果Apache工作正常,请确保没有任何冲突的iptables规则。