ip forwarding - permission denied

Cef cef at optus.net
Fri Apr 1 06:40:38 UTC 2005


On Fri, 1 Apr 2005 15:38, david wrote:
> sudo echo 1 > /proc/sys/net/ipv4/ip_forward
>
> But all I get is "permission denied" and I don't understand why. Does
> anyone know what I'm missing here?

The way shell redirection works, the command gets broken up like so:

"sudo echo 1"

which gets redirectred to:

"/proc/sys/net/ipv4/ip_forward"

ie: it uses your permissions, not that of the sudo'd command.

What you need to do is the following:

sudo sh -c "echo 1 > /proc/sys/net/ipv4/ip_forward"

This tells sudo to run a shell (sh) and pass the command you want to run to it 
(which includes the redirect). Look at 'man sudo' in the EXAMPLES section for 
more on this.

Note however that you can also use the sysctl program (which has been 
described in another reply) to do what you want also. If you want to make 
such changes stick over reboots, look at 'man sysctl.conf' for more info on 
how create settings to be used on boot by sysctl (in /etc/sysctl.conf).

-- 
 Stuart Young - aka Cefiar - cef at optus.net




More information about the ubuntu-users mailing list