IP Forwarding can be turned on temporarily or permanently. We'll first go through the steps to turn on IP forwarding temporarily. I'd like to remind all of you that these commands will only work if you have the proper permissions. This can either be in the form of a root password which can be used with the "su" command or by having relevant privileges for the "sudo" command.
Temporary:
sysctl -w net.ipv4.ip_forward=1
or
echo 1 > /proc/sys/net/ipv4/ip_forward
Either of these commands will turn on IP forwarding in the Linux kernel. Unfortunately, these settings will be lost the next time you reboot your computer. To make them permanent, you have to save the settings in a file.
These settings are stored in the file sysctl.conf in the /etc folder. To edit this file, use your favorite editor. I prefer nano for small tasks, so here's what I type:
sudo nano -w /etc/sysctl.conf
This will open the relevant file in nano. Inside, search for the parameter "net.ipv4.ip_forward". You can search for text using the key combination "Ctrl + W". If it's in the file, it should be as "net.ipv4.ip_forward = 0". Change the 0 to 1. If the setting is not present in the file, make a new line at the end of the file and add the following:
net.ipv4.ip_forward = 1
Then, just press "Ctrl + X" to save and exit the editor. This will make the change permanent and IP forwarding will be turned on automatically at every bootup. To use the newly changed configuration file without having to restart your computer, just type the command "sysctl -p /etc/sysctl.conf".