
Ubuntu 에서 iptables 구성 파일을 변경했으며 /etc/iptables/filter
다시 로드하고 싶습니다. 매뉴얼 페이지를 읽고 구글링도 했지만 정보를 찾을 수 없었습니다. 도움을 주시면 감사하겠습니다.
답변1
일반적으로 방화벽 규칙은 구성 파일에 있습니다./etc/iptables.firewall.rules
파일에 정의된 규칙을 활성화하려면 해당 규칙을 다음으로 보내야 합니다 iptables-restore
(원하는 경우 다른 파일을 사용할 수 있음).
sudo iptables-restore < /etc/iptables.firewall.rules
다음을 통해 활성화되었는지 확인할 수 있습니다.
sudo iptables -L
컴퓨터를 부팅할 때마다 동일한 규칙을 활성화하려면 다음 파일을 만듭니다.
sudo nano /etc/network/if-pre-up.d/firewall
이 내용으로:
#!/bin/sh
/sbin/iptables-restore < /etc/iptables.firewall.rules
그리고 실행 권한을 부여합니다.
sudo chmod +x /etc/network/if-pre-up.d/firewall
도움이 되길 바랍니다 =)
다음 에 대한 예시 파일 /etc/iptables.firewall.rules
:
*filter
# Allow all loopback (lo0) traffic and drop all traffic to 127/8 that doesn't use lo0
-A INPUT -i lo -j ACCEPT
-A INPUT -d 127.0.0.0/8 -j REJECT
# Accept all established inbound connections
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
# Allow all outbound traffic - you can modify this to only allow certain traffic
-A OUTPUT -j ACCEPT
# Allow HTTP and HTTPS connections from anywhere (the normal ports for websites and SSL).
-A INPUT -p tcp --dport 80 -j ACCEPT
-A INPUT -p tcp --dport 443 -j ACCEPT
# Allow SSH connections
#
# The -dport number should be the same port number you set in sshd_config
#
-A INPUT -p tcp -m state --state NEW --dport 22 -j ACCEPT
# Allow ping
-A INPUT -p icmp -j ACCEPT
# Log iptables denied calls
-A INPUT -m limit --limit 5/min -j LOG --log-prefix "iptables denied: " --log-level 7
# Drop all other inbound - default deny unless explicitly allowed policy
-A INPUT -j DROP
-A FORWARD -j DROP
COMMIT
2021-08 편집:
Ubuntu 20.04.2 LTS로 업그레이드하는 데 문제가 발생했습니다. 의 위치가 에서 iptables-restore
로 변경되었습니다 ./sbin/iptables-restore
/usr/sbin/iptables-restore
시스템 위치를 확인하십시오. whereis iptables-restore
그렇지 않으면 네트워크 인터페이스가 올라가지 않습니다.
업그레이드 후 네트워크가 없으면 sudo systemctl status networking.service -l
제 경우에는 로 이유를 확인할 수 있습니다.
Failed to start Raise network interfaces.
if-pre-up.d/firewall: 2: /sbin/iptables-restore: not found
답변2
가장 쉬운 방법은 재부팅하는 것입니다(아래에서도 작동하지 않으면 재부팅하고 변경 사항이 적용되었는지 확인하세요).
두 번째로 쉬운 방법은 iptables 구성을 사용하여 데몬을 다시 시작하는 것입니다(google: restart daemon ubuntu).
예(구성에 따라 다름):
/etc/init.d/iptables restart
/etc/init.d/networking restart
/etc/init.d/firewall restart
답변3
규칙을 실행했다면 해당 규칙은 이미 실행 중이므로 다시 로드할 필요가 없습니다. 구성 파일이 있지만 실행되지 않은 경우 지금까지 본 가장 좋은 방법은 iptables-apply
(iptables 확장자)를 사용하는 것입니다.
iptables-apply -t 60 your_rules_file
그러면 60초(기본적으로 10초) 동안 규칙이 적용되고 확인하지 않으면 되돌려집니다. 규칙 때문에 시스템에서 쫓겨나는 경우(예: SSH를 통해 작업하는 경우)에 대비해 절약할 수 있습니다.
다음을 대체품으로 사용할 수 있습니다.
iptables-restore < your_rules_file; sleep 60; iptables-restore < clean_rules
답변4
조금 인터넷 검색을 한 후 이것이 iptables를 다시 시작하는 방법을 찾았습니다. . . sudo /etc/init.d/firewall 재시작