I know that I can enable IP forward by echoing 1 to /proc/sys/net/ipv4/ip_forward, but how can I make this permanent?

By the way I want another method rather than start up scripts, is there any?


Edit /etc/sysctl.conf and search for the following lines:

# Uncomment the next line to enable packet forwarding for IPv4

Uncomment net.ipv4.ip_forward=1:

# Uncomment the next line to enable packet forwarding for IPv4

Or in one line command :

sudo sysctl -w net.ipv4.ip_forward=1
| improve this answer | |
  • 8
    sudo sysctl -w net.ipv4.ip_forward=1 doesn't make it permanent... @ least on a raspberry pi I tested... – Philippe Gachoud Oct 22 '17 at 15:37
  • do you need to reboot too? or is there a way to "live" apply it too – user230910 May 25 '18 at 21:38
  • @user230910 No need to reboot if using sudo sysctl -w ... – Eric Carvalho May 29 '18 at 15:51
  • -w immediately enables the setting. It does not make it persistent though! – ws6079 Apr 27 at 13:26

Permanent setting using /etc/sysctl.conf

If we want to make this configuration permanent the best way to do it is using the file /etc/sysctl.conf where we can add a line containing net.ipv4.ip_forward = 1

net.ipv4.ip_forward = 1

If you already have an entry net.ipv4.ip_forward with the value 0 you can change that to 1.

To enable the changes made in sysctl.conf you will need to run the command:

sudo sysctl -p /etc/sysctl.conf

On RedHat based systems this is also enabled when restarting the network service:

service network restart

and on Debian/Ubuntu systems this can be also done restarting the procps service:

sudo /etc/init.d/procps restart

Source: How to Enable IP Forwarding in Linux

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.