비표준 포트에서 SSH 포트를 열려고 합니다. 예를 들어 12452
다음 명령을 사용했지만 아무 것도 작동하지 않았습니다.
iptables -I INPUT -p tcp --dport 12452 -j ACCEPT
iptables -I OUTPUT -p tcp --dport 12452 -j ACCEPT
iptables -I DOCKER-USER -p tcp --dport 12452 -j ACCEPT
또한 firewalld
내가 사용한 활성 영역은 docker이므로 다음을 사용했습니다.
firewall-cmd --zone=docker --add-port=12452/tcp
여전히 작동하지 않습니다...하지만 실제로 현재 사용하고 있는 SSH 포트 22 규칙이 어디에도 열려 있지 않다는 것을 깨달았습니다! 규칙에도 없습니다 iptables
!
참고: ufw
이전에 설치한 후 방금 제거했습니다.
내 iptables-save
결과는 다음과 같습니다.
# Generated by iptables-save v1.8.7 on Mon Aug 14 20:51:29 2023
*filter
:INPUT ACCEPT [0:0]
:FORWARD DROP [0:0]
:OUTPUT ACCEPT [0:0]
:DOCKER - [0:0]
:DOCKER-INGRESS - [0:0]
:DOCKER-ISOLATION-STAGE-1 - [0:0]
:DOCKER-ISOLATION-STAGE-2 - [0:0]
:DOCKER-USER - [0:0]
:f2b-sshd - [0:0]
-A INPUT -p tcp -m multiport --dports 22 -j f2b-sshd
-A FORWARD -j DOCKER-USER
-A FORWARD -j DOCKER-INGRESS
-A FORWARD -j DOCKER-ISOLATION-STAGE-1
-A FORWARD -o docker0 -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker0 -j DOCKER
-A FORWARD -i docker0 ! -o docker0 -j ACCEPT
-A FORWARD -i docker0 -o docker0 -j ACCEPT
-A FORWARD -o docker_gwbridge -m conntrack --ctstate RELATED,ESTABLISHED -j ACCEPT
-A FORWARD -o docker_gwbridge -j DOCKER
-A FORWARD -i docker_gwbridge ! -o docker_gwbridge -j ACCEPT
-A FORWARD -i docker_gwbridge -o docker_gwbridge -j DROP
-A DOCKER-INGRESS -p tcp -m tcp --dport 443 -j ACCEPT
-A DOCKER-INGRESS -p tcp -m state --state RELATED,ESTABLISHED -m tcp --sport 443 -j ACCEPT
-A DOCKER-INGRESS -j RETURN
-A DOCKER-ISOLATION-STAGE-1 -i docker0 ! -o docker0 -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -i docker_gwbridge ! -o docker_gwbridge -j DOCKER-ISOLATION-STAGE-2
-A DOCKER-ISOLATION-STAGE-1 -j RETURN
-A DOCKER-ISOLATION-STAGE-2 -o docker0 -j DROP
-A DOCKER-ISOLATION-STAGE-2 -o docker_gwbridge -j DROP
-A DOCKER-ISOLATION-STAGE-2 -j RETURN
-A DOCKER-USER -j RETURN
-A f2b-sshd -j RETURN
COMMIT
# Completed on Mon Aug 14 20:51:29 2023
# Generated by iptables-save v1.8.7 on Mon Aug 14 20:51:29 2023
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
:DOCKER - [0:0]
:DOCKER-INGRESS - [0:0]
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER-INGRESS
-A PREROUTING -m addrtype --dst-type LOCAL -j DOCKER
-A OUTPUT -m addrtype --dst-type LOCAL -j DOCKER-INGRESS
-A OUTPUT ! -d 127.0.0.0/8 -m addrtype --dst-type LOCAL -j DOCKER
-A POSTROUTING -o docker_gwbridge -m addrtype --src-type LOCAL -j MASQUERADE
-A POSTROUTING -s x.x.x.x/x ! -o docker0 -j MASQUERADE
-A POSTROUTING -s x.x.x.x/x ! -o docker_gwbridge -j MASQUERADE
-A DOCKER -i docker0 -j RETURN
-A DOCKER -i docker_gwbridge -j RETURN
-A DOCKER-INGRESS -p tcp -m tcp --dport 443 -j DNAT --to-destination x.x.x.x:x
-A DOCKER-INGRESS -j RETURN
COMMIT
# Completed on Mon Aug 14 20:51:29 2023
출력은 firewall-cmd --zone=docker --list-all
다음과 같습니다:
docker (active)
target: ACCEPT
icmp-block-inversion: no
interfaces: docker0 docker_gwbridge
sources:
services:
ports: 12452/tcp
protocols:
forward: yes
masquerade: no
forward-ports:
source-ports:
icmp-blocks:
rich rules:
답변1
왜인지는 모르겠지만 firewalld
아직도 존이 사용되고 있는 것 같습니다 public
!
이렇게 공공장소에서 포트를 열어보았습니다
firewall-cmd --zone=public --add-port=12452/tcp
놀랍게도 작동합니다!