大网数据广告活动
服务器运维问答

nftables ip6 route to localhost/ ipv6 nat to loopback

· 52CE 我爱测

I'm trying to route incoming http internet traffic to [::1]:8080 which is where my http server binds to. I'm using nftables on an IPv6-only device. If I add following rules: sudo nft flush ruleset sudo nft add table ip6 nat sudo …

问题原文

原帖链接 · adabru · CC BY-SA 4.0

I'm trying to route incoming http internet traffic to [::1]:8080 which is where my http server binds to. I'm using nftables on an IPv6-only device. If I add following rules:

  sudo nft flush ruleset
  sudo nft add table ip6 nat
  sudo nft add chain ip6 nat prerouting { type nat hook prerouting priority 0 \; }
  sudo nft add chain ip6 nat postrouting { type nat hook postrouting priority 100 \; }

  sudo nft add rule ip6 nat prerouting ip6 daddr [global-ip6] tcp dport 80 dnat to ::1 :8080

  sudo nft list ruleset

with resulting ruleset:

table ip6 nat {
  chain prerouting {
    type nat hook prerouting priority 0; policy accept;
    ip6 daddr [global-ip6] tcp dport http dnat to [::1]:http-alt
  }

  chain postrouting {
    type nat hook postrouting priority 100; policy accept;
  }
}

then requests to [global-ip6]:80 get swallowed (there is no connection refused error) but no connection is established.

If I use one of the rules

sudo nft add rule ip6 nat prerouting tcp dport 80 redirect to 8080

or

sudo nft add rule ip6 nat prerouting ip6 daddr [global-ip6] tcp dport 80 dnat to [global-ip6] :8080

and bind my program to [global-ip6]:8080, then communication works as expected.

Do you have an idea what I am missing? I tried out some rules in the postrouting and input chains but couldn't get it to work. Back with IPv4 and iptables I had to do sudo sysctl -w net.ipv4.conf.all.route_localnet=1, maybe there is a similar IPv6 flag?

已采纳解答

原帖链接 · Anton Danilov · CC BY-SA 4.0

Unfortunately you cannot achieve what you want with the nftables.

After the dnat target the destination address is rewritten to the loopback address (::1), and then the incoming packet is processed by the routing code. But any incoming packet with the loopback destination address has been received from outside MUST be dropped by RFC 4291 2.5.3. There aren't any sysctl variables to change this behavior.

You can run some proxy app, that will be accept connection on the external address and connects to the application that listens the loopback address.

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2019-07-17)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。