Debian 8에서 iptable 규칙을 저장할 때 권한이 거부되었습니다.

Debian 8에서 iptable 규칙을 저장할 때 권한이 거부되었습니다.

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

변경한 후 /etc/iptables/rules.v4저장하려고 합니다.

sudo iptables-save > /etc/iptables/rules.v4

오류 메시지가 나타납니다-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

그리고

sudo sh -c "iptables-save > /etc/iptables/rules.v4"

이렇게 하면 netstat -tulnp | grep 443출력이 나오지 않습니다.

답변1

이 작업에는 다음 2가지 권한이 포함됩니다.

  1. 읽기 허용iptables-save
  2. 쓰기 권한/etc/iptables/rules.v4

두 번째 필요한 권한에는 sudo를 사용할 수 없습니다.

게시한 마지막 명령이 작동해야 합니다. 그렇지 않으면 다음 명령을 사용하여 루트 쉘을 삭제하도록 변경 -C하십시오 -c.

sudo su -

답변2

tee당신은 그것을 잘못 사용하고 있습니다 . 이 명령은 iptables-save무엇을 생성합니까 ?~해야 한다저장되어 표준 출력으로 전송됩니다. 이 tee명령은 stdout을 읽고 iptables-save이를 지정된 파일에 써야 합니다.

루트 셸을 사용하지 않고 경로를 저장하는 올바른 방법은 iptables-save내용을 경로로 파이프한 tee다음 표준 출력을 파일에 저장하는 것입니다.

sudo iptables-save | sudo tee /etc/iptables/rules.v4

답변3

나는 같은 문제가 있었고 지금 해결되었습니다.

  1. rule.v4에서 그룹을 사용자로 변경

    sudo chgrp "usergroup" /etc/iptables/rules.v*
    
  2. 그룹에 대한 쓰기 권한을 활성화합니다.

    sudo chmod 664 /etc/iptables/rules.v*
    
  3. 다시 시도하십시오

    sudo iptables-save > /etc/iptables/rules.v4
    

이것은 나에게 도움이 되었으며 도움이 되기를 바랍니다.

관련 정보