Bash /proc/sys/net/ipv4/ip_forward: Permission denied

The permission bits for the file /proc/sys/net/ipv4/ip_forward is:


with owner:group being root:root.

So only root can write to the file.

When you do:

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

as a normal user, you won't be able to write to the file due to insufficient permission.

You can do:

  • Use sudo and bash:

    sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
  • Use tee:

    echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward

Note that, you should use /etc/sysctl.conf for persistent operations on the /proc/sys subdirectories.

In a nutshell, to enable IP forwarding, you can just put the following in /etc/sysctl.conf:

net.ipv4.ip_forward = 1

Then run:

sudo sysctl -p

to have immediate effect.

This has the same effect as editing the file /proc/sys/net/ipv4/ip_forward directly, and not to mention far cleaner and of course persistent.