我试图改变ip_forward从0到1,但失败了,即使在是Xubuntu 11.10 root权限。我在使用 Ubuntu 11.10 时没有类似的问题
chiaki@chiaki:~$ sudo echo 1 > /proc/sys/net/ipv4/ip_forward
bash: /proc/sys/net/ipv4/ip_forward: Permission denied
Run Code Online (Sandbox Code Playgroud)
任何的想法?
Pan*_*her 21
你不能这么容易地重新定向sudo。有几种潜在的解决方案,包括tee.
您可以重定向到您在调用 时拥有的文件sudo,例如您的主目录中的文件,而不是系统文件。
例子
# 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
Run Code Online (Sandbox Code Playgroud)
使用sudo bash -c并引用整个命令
sudo bash -c 'echo 1 > /proc/sys/net/ipv4/ip_forward'
Run Code Online (Sandbox Code Playgroud)
用 tee
echo "1" | sudo tee /proc/sys/net/ipv4/ip_forward
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
37594 次 |
| 最近记录: |