sudo and Redirection
sudo echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/99-fw.conf fails with "Permission denied". Why?
sudo echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/99-fw.conf
Choose one answer
The > redirection is done by your unprivileged shell before sudo even runs, so the file is opened as you.
>
echo is a shell builtin, and sudo can only run programs that exist on disk.
echo
Files in /etc/sysctl.d/ are protected by the kernel and can only be changed with sysctl -w, even by a root process writing to them.
/etc/sysctl.d/
sysctl -w
sudo drops write access to /etc unless you pass -E to keep the environment.
/etc
-E