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

IPv4 Forwarding (NAT) only works after toggling IPv4 forwarding to off then on

· 52CE 我爱测

This literally makes no sense and I'm stumped about why this is happening, but hear me out. Currently I'm using Proxmox 6 (Debian) and I created a NAT so VMs/LXC containers can communicate between them + having internet connectiv…

问题原文

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

This literally makes no sense and I'm stumped about why this is happening, but hear me out.

Currently I'm using Proxmox 6 (Debian) and I created a NAT so VMs/LXC containers can communicate between them + having internet connectivity to the outside world. I'm also using ufw for firewall stuff.

I was able to create the NAT connection fine, VMs can communicate between them, great!

...but internet connectivity doesn't work at all, why? I have no idea, but I found out that if I do this...

echo 0 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/ip_forward

The issue is magically fixed. Yes, ip_forward is enabled on UFW's config

#
# Configuration file for setting network variables. Please note these settings
# override /etc/sysctl.conf and /etc/sysctl.d. If you prefer to use
# /etc/sysctl.conf, please adjust IPT_SYSCTL in /etc/default/ufw. See
# Documentation/networking/ip-sysctl.txt in the kernel source code for more
# information.
#

# Uncomment this to allow this host to route packets between interfaces
net/ipv4/ip_forward=1
net/ipv6/conf/default/forwarding=1
net/ipv6/conf/all/forwarding=1

And if I reboot the machine and do cat /proc/sys/net/ipv4/ip_forward, the result is 1, but internet connectivity is broken until I toggle it on and off!

So I'm stumped, I have no idea why this is happen and while there is a dirty workaround (toggling it off and on) I wanted to know if there is a correctly to fix this issue.

已采纳解答

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

This is a bug in ifupdown2, dhcp interfaces are not being IPv4 forwarded by default, even if you set the forwarding in sysctl.conf

Here's a thread where spirit found out about this bug: https://forum.proxmox.com/threads/reloading-ifupdown2-breaks-internet-connectivity-within-containers-vms-until-toggling-ip-forward.78933/#post-349753

As a workaround, you can add ip-forward 1 to the /etc/network/interfaces or you can toggle IPv4 forwarding manually (just like what I did in the question)

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

资料来源与适用范围

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

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

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