天天看點

打開Ubuntu的IPv4轉發功能

隻需要在/etc/systtl.conf檔案中添加一句net.ipv4.ip_forward = 1

咱們來個進階點的:sudo  echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf     完美

             但是提示:Permission denied 

明明已經使用了sudo,為什麼?

在網上得到的答案:

You can't use 

sudo

 to affect output redirection; 

>

 and 

>>

 (and, for completeness, 

<

) are effected with the privilege of the calling user, because redirection is done by the calling shell, not the called subprocess.

文章中給了2種飯方法:把sysctl.conf拷貝到别處,修改後再拷貝回去

                                     sudo /bin/su -c "echo 'net.ipv4.ip_forward = 1' >> /etc/sysctl.conf"

還可以切到root使用者:sudo su,如下圖:

打開Ubuntu的IPv4轉發功能

連結:https://serverfault.com/questions/540492/sudo-echo-bla-etc-sysctl-conf-permission-denied

繼續閱讀