Friday, April 19, 2024
 Popular · Latest · Hot · Upcoming
21
rated 0 times [  21] [ 0]  / answers: 1 / hits: 38771  / 1 Year ago, fri, november 18, 2022, 2:06:57

I try to change ip_forward from 0 to 1 but fail, even with root permission in Xubuntu 11.10. I don't have such similar problem while using Ubuntu 11.10



chiaki@chiaki:~$ sudo echo 1 > /proc/sys/net/ipv4/ip_forward 
bash: /proc/sys/net/ipv4/ip_forward: Permission denied


any idea?


More From » 11.10

 Answers
0

You can not re-direct so easily with sudo. There are several potential solutions, including tee.



You can re-direct to files you own as the user calling sudo, such as files in your home directory, but not system files.



Example



# it works when re-direction to a location / file the user has permission to access
ubuntu@ubuntu:~$sudo echo "it works" > ~/file
ubuntu@ubuntu:~$cat file
it works

# But NOT if you do not have permission to access the target
ubuntu@ubuntu:~$sudo echo "it works" > /root/file
-bash: /root/file: Permission denied


Option one



use sudo bash -c and quote the entire command



sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'


Option two



Use tee



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

[#41306] Sunday, November 20, 2022, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
oargrou

Total Points: 336
Total Questions: 105
Total Answers: 113

Location: Vietnam
Member since Sun, Oct 18, 2020
4 Years ago
oargrou questions
Thu, May 13, 21, 16:38, 3 Years ago
Wed, Jul 21, 21, 01:38, 3 Years ago
Sat, May 15, 21, 17:39, 3 Years ago
Tue, May 24, 22, 14:58, 2 Years ago
Sat, Mar 19, 22, 05:22, 2 Years ago
;