Time for action – enabling IP forwarding
To enable IP forwarding on Linux-based operating systems, we can use any of the following methods.
Using the
sysctl
command:sysctl -w net.ipv4.ip_forward=1
This method doesn't need a reboot and will enable IP forwarding on the fly but will not be preserved after a reboot.
Using the
sysctl
configuration file, we can add the following line in the/etc/sysctl.conf
file:net.ipv4.ip_forward = 1
To enable the changes made to the
/etc/sysctl.conf
file, we need to run the following command:sysctl -p /etc/sysctl.conf
These changes will be preserved after a reboot.
Enabling IP forwarding on BSD operating systems is almost similar. We can use any of the following methods:
Using the
sysctl
command.sysctl -w net.inet.ip.forwarding=1
This method doesn't need a reboot and will enable IP forwarding on the fly but will not be preserved after a reboot. Please note that we don't need the
-w
option on OpenBSD and DragonFlyBSD.We can add the following line in the
/etc/rc.conf...