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

Bridged networking on VM host and hairpin NAT

· 52CE 我爱测

I have one host running Proxmox VE. I set up 3 virtual bridges vmbr[0-2] to handle my networking needs: vmbr0 runs directly on the main interface for VMs with public IPs, vmbr1 allows for NATed VMs, and vmbr2 is a host-only netwo…

问题原文

原帖链接 · rapht · CC BY-SA 3.0

I have one host running Proxmox VE.

I set up 3 virtual bridges vmbr[0-2] to handle my networking needs: vmbr0 runs directly on the main interface for VMs with public IPs, vmbr1 allows for NATed VMs, and vmbr2 is a host-only network. Let's say my main public IP is 12.34.56.78.

For the NAT to work, I set up the following iptables ruleset:

-A PREROUTING -d 12.34.56.78 -i vmbr0 -p tcp -m multiport --dports 80,443 -j DNAT --to-destination 192.168.1.101
# and other rules like this one for different ports to different local IPs

-A POSTROUTING -s 192.168.10.0/24 -o vmbr0 -j SNAT --to-source 12.34.56.78

Now let's say I have a VM on vmbr1 with IP 192.168.1.102.

This machine cannot access the webserver at 192.168.1.101 using the public IP 12.34.56.78.

I initially thought that the POSTROUTING directive above was enough for hairpin NAT to work.

Having read the canonical Loopback to forwarded Public IP address from local network - Hairpin NAT and multiple other answers on the same variant, I tried :

  • setting -P [INPUT|FORWARD|OUTPUT] ACCEPT temporarily on the host to check if it could be caused by some filtering rules

  • adding -A POSTROUTING -d 192.168.1.101 -p tcp --dport 80 -j MASQUERADE to the ruleset, trying it both before and after the current POSTROUTING rule

but still, it does not work.

Ideas?

Thanks.

已采纳解答

原帖链接 · user5870571 · CC BY-SA 3.0

To do the hairpin NAT method you will need to enter the commands below.

iptables -t nat -A PREROUTING -d 12.34.56.78 -i vmbr1 -p tcp -m multiport --dports 80,443 -j DNAT \
    --to-destination 192.168.1.101   
iptables -t nat -A POSTROUTING -s 192.168.10.0/24 -o vmbr1 -d 192.168.1.254 -p tcp \
    --dport 80 -j SNAT --to-source 192.168.1.101

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

资料来源与适用范围

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

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

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