在 Debian 8 中保存 iptable 规则时权限被拒绝

Pet*_*ahn 5 linux bash debian

我想在我的 Debian 8 服务器中打开端口 443,但出现权限被拒绝错误。

我的 rules.v4 文件看起来像:

# Generated by iptables-save v1.4.21 on Wed Feb 15 14:42:03 2017
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [208710:151335680]
-A INPUT -p icmp -m comment --comment "000 accept all icmp" -j ACCEPT
-A INPUT -i lo -m comment --comment "001 accept all to lo interface" -j ACCEPT
-A INPUT -m comment --comment "002 accept related established rules" -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m multiport --dports 22 -m comment --comment "099 allow ssh access" -j ACCEPT
-A INPUT -p tcp -m multiport --dports 80,443 -m comment --comment "100 allow http and https access" -j ACCEPT
-A INPUT -p tcp -m multiport --dports 1122 -m comment --comment "150 allow phpmyadmin access" -j ACCEPT
-A INPUT -m comment --comment "999 drop all" -j DROP
COMMIT
# Completed on Wed Feb 15 14:42:03 2017
Run Code Online (Sandbox Code Playgroud)

在进行更改后,/etc/iptables/rules.v4我尝试保存

sudo iptables-save > /etc/iptables/rules.v4
Run Code Online (Sandbox Code Playgroud)

我收到错误信息 -bash: /etc/iptables/rules.v4: Permission denied

当文件存在时,我尝试使用sudo bash -C "iptables-save > /etc/iptables/rules.v4"i get no such file or directory

我也试过 tee

sudo tee iptables-save > /etc/iptables/rules.v4
Run Code Online (Sandbox Code Playgroud)

sudo sh -c "iptables-save > /etc/iptables/rules.v4"
Run Code Online (Sandbox Code Playgroud)

当我这样做时,netstat -tulnp | grep 443我没有输出。

Bru*_*779 10

此操作涉及2个权限:

  1. 阅读许可 iptables-save
  2. 写入权限 /etc/iptables/rules.v4

您不能对所需的第二个权限使用 sudo。

您发布的最后一个命令应该可以工作,否则使用

sudo su -
Run Code Online (Sandbox Code Playgroud)

  • -u 检查 UDP [看这里](http://netstat.net/) 是 apache 监听端口 443 (2认同)