I have a small question regarding using
sudo with output redirect
>. To enable IP forwrding, someone can use the command:
echo 1 > /proc/sys/net/ipv4/ip_forward
Executing this command will give permission denied as it requires root privileges. However, executing the same command with
sudo gives also permission denied error! It seems that output redirect
> does not inherit the permissions of the preceding command
echo. Is this right?
As a workaround I do:
echo 1 | sudo tee /proc/sys/net/ipv4/ip_forward
Is this the best way to do it? Am I missing something?
Please, note that this is an example and it applies to all commands that use output redirect.