我有一个 Debian 12 服务器(公共 IP85.xxx.xxx.xxx
地址为enp6s0
),在网桥上运行一堆 LXC 容器cbr0
。
由于公共 IP 是动态的,我必须设置forward
规则prerouting
才能dnat
使传入请求到达容器。例如。端口 80/443 已连接到容器10.10.0.1
。这是我的nftables
规则:
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
ct state {established, related} accept
iifname lo accept
iifname cbr0 accept
ip protocol icmp accept
ip6 nexthdr icmpv6 accept
}
chain forward {
type filter hook forward priority 0; policy accept;
}
chain output {
type filter hook output priority 0;
}
}
table ip filter {
chain forward {
type filter hook forward priority 0; policy drop;
oifname enp6s0 iifname cbr0 accept
iifname enp6s0 oifname cbr0 ct state related, established accept
# Webproxy
iifname enp6s0 oifname cbr0 tcp dport 80 accept
iifname enp6s0 oifname cbr0 udp dport 80 accept
iifname enp6s0 oifname cbr0 tcp dport 443 accept
iifname enp6s0 oifname cbr0 udp dport 443 accept
}
}
table ip nat {
chain postrouting {
type nat hook postrouting priority 100; policy accept;
}
chain prerouting {
type nat hook prerouting priority -100; policy accept;
# Webproxy
iifname enp6s0 tcp dport 80 dnat to 10.10.0.1:80
iifname enp6s0 udp dport 80 dnat to 10.10.0.1:80
iifname enp6s0 tcp dport 443 dnat to 10.10.0.1:443
iifname enp6s0 udp dport 443 dnat to 10.10.0.1:443
}
}
现在的问题是:发夹NAT。我有多个容器托管网站,有时其中一些容器需要使用域名与其他容器进行通信。当他们对这些域运行 DNS 查询时,他们将获取主机 IP 并且通信失败:
如何在不诉诸 DNS 攻击的情况下解决这种情况?有没有办法nftables
在拥有动态IP的情况下设置在内部转发请求?上面的内容是如何实现iifname
的呢?
谢谢。