3
$ sudo echo 1 >/proc/sys/net/ipv4/ip_forward 
bash: /proc/sys/net/ipv4/ip_forward: Permission denied

then I try to get write privilege, also failed.

$ sudo chmod a+wx /proc/sys/net/ipv4/ip_forward 
chmod: changing permissions of `/proc/sys/net/ipv4/ip_forward': Operation not permitted

what is wrong?

Victor S
  • 795
  • 5
  • 10
  • 18
  • 1
    should use $ sudo bash -c "echo 1 >/proc/sys/net/ipv4/ip_forward" – Victor S Aug 15 '13 at 14:43
  • related: [Redirect the output using `sudo`](http://askubuntu.com/q/20578/127745) – JonnyJD Aug 26 '14 at 08:53
  • 2
    Possible duplicate of [When using sudo with redirection, I get 'permission denied'](http://askubuntu.com/questions/230476/when-using-sudo-with-redirection-i-get-permission-denied) – David Foerster Feb 07 '16 at 19:10

4 Answers4

9

You are trying to change the kernel values. Be sure of what you are doing.

Okay here is how you can change the value of ip_forward with root privilege (sudo -i)

  • First check the value of ip_forward using command: sysctl -a | grep ip_forward
  • Now using sysctl -w <parameter=value> you change the value of ip_forward:
    • sysctl -w ip_forward=1
  • Make these changes to reflect in kernel using: sysctl -p
  • Do the first step once again to check the values.

I recommend you to go through the man page of sysctl

devav2
  • 35,738
  • 17
  • 79
  • 82
1

Edit file /etc/sysctl.conf and edit this section:

#net.ipv4.ip_forward = 0

to

net.ipv4.ip_forward = 1 (remove # sign)

then type command: sysctl -p
Last, reboot your system.

bummi
  • 394
  • 3
  • 9
  • 14
Bizax
  • 11
  • 1
0

To change this kernel value in kernel version 4.4+ (Ubuntu 16.04+), you need to do the following:

sudo sysctl -w net.ipv4.ip_forward=1
rouble
  • 141
  • 4
-1

Terminal:

sudo nano /proc/sys/net/ipv4 ip_forward

after change it, save with CTRL + O and exit with CTRL + X

Dimitri Podborski
  • 2,505
  • 16
  • 22
anon
  • 1
  • -1 Text editors are a bad way to edit kernel parameters since they're not real files even though they look a lot like them. – David Foerster Feb 07 '16 at 19:12