Solved Difference between gateway_enable="YES" and sysctl net.inet.ip.forwarding=1

Hi all,

Does gateway_enable in rc.conf have priority over net.inet.ip.forwarding in sysctl.conf? How do they relate to each other? When is the content of sysctl.conf processed, before or after rc.conf?
Thanks
 
Hello,

As far as I know, while /etc/sysctl.conf is processed before /etc/rc.conf during system startup, /etc/rc.conf generally takes precedence.

The gateway_enable="YES" setting in /etc/rc.conf is essentially a shortcut that sets net.inet.ip.forwarding=1 in sysctl.
Both achieve the same result of enabling IP forwarding, but using gateway_enable="YES" in rc.conf is recommended and more common.

If you set gateway_enable="YES" in /etc/rc.conf, it will enable IP forwarding regardless of the value in /etc/sysctl.conf. However, if you only set net.inet.ip.forwarding=1 in /etc/sysctl.conf without gateway_enable="YES" in /etc/rc.conf, IP forwarding will still be enabled.
 
Hi all,

Does gateway_enable in rc.conf have priority over net.inet.ip.forwarding in sysctl.conf? How do they relate to each other? When is the content of sysctl.conf processed, before or after rc.conf?
Thanks

gateway_enable is the intended interface (“API”) to tell FreeBSD (as a concept) that you want forwarding. net.inet.ip.forwarding is the knob that is turned to actually tell the kernel.

Short version: use gateway_enable as described in rc.conf(5)
 
Hello,

As far as I know, while /etc/sysctl.conf is processed before /etc/rc.conf during system startup, /etc/rc.conf generally takes precedence.
sysctl.conf is loaded by /etc/rc.d/sysctl, which is started by /etc/rc during boot. gateway_enable is handled by /etc/rc.d/routing. All the /etc/rc.d services are started by /etc/rc during boot and configured via rc.conf(5).

See the output of rcorder /etc/rc.d/* to see the order in which services are started during boot. /etc/rc.d/sysctl is one of the early ones.
The gateway_enable="YES" setting in /etc/rc.conf is essentially a shortcut that sets net.inet.ip.forwarding=1 in sysctl.
Both achieve the same result of enabling IP forwarding, but using gateway_enable="YES" in rc.conf is recommended and more common.
Ultimately, using gateway_enable is the recommended way. It is more idiomatic.
 
Back
Top