방화벽은 사전 정의된 하나의 IP 호스트 또는 AS 번호 net에서만 SSH를 허용합니다.

방화벽은 사전 정의된 하나의 IP 호스트 또는 AS 번호 net에서만 SSH를 허용합니다.

최소 설치 및 방화벽으로 CentOS Linux 릴리스 7.9.2009를 사용하고 있습니다.

[root@centosmin firewalld]# uname -a
Linux centosmin 3.10.0-1160.6.1.el7.x86_64 #1 SMP Tue Nov 17 13:59:11 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

비슷한 질문이 있습니다. 즉여기 하지만 거기에는 어떤 응답도 작동하지 않습니다. 도달 규칙을 사용하지 않고 그렇게 하고 싶습니다.

인터넷의 특정 IP 주소에서만 ssh를 허용하는 것이 목표입니다. 이 동작을 시뮬레이션하기 위해 서로 다른 VLAN에 3개의 컴퓨터가 있는 랩을 설정하고 내부 네트워크에서 이들 간의 라우팅을 설정했습니다.

이 경우 서버는

10.192.210.10/24 

두 개의 SSH 클라이언트:

10.192.52.50/24
10.192.57.6/24

이제 나만의 인터넷 연결 영역을 만들고 다음 명령을 사용하여 기본값으로 설정했습니다.

//create new zone called internet
firewall-cmd  --permanent --new-zone=internet

// add the only ip address that should be able to connect to ssh
firewall-cmd --zone=internet --add-source=10.192.57.6/32

firewall-cmd --zone=internet --add-service=ssh

// here i make sure that i manually add the interface if it is not already add it and then remove it
firewall-cmd --zone=internet –add-interface=ens3
firewall-cmd --zone=internet --remove-interface=ens3


firewall-cmd --zone=internet --set-target=DROP
firewall-cmd --set-default-zone=internet

// save the current runtime to premanent rules
firewall-cmd --runtime-to-permanent

firewall-cmd --reload 

그 후 내 유일한 네트워크 인터페이스는 다음과 같습니다

[root@centosmin firewalld]# firewall-cmd --list-all 
internet (active) 
 target: DROP 
 icmp-block-inversion: no 
 interfaces:  
 sources: 10.192.57.6/32 
 services: ssh 
 ports:  
 protocols:  
 masquerade: no 
 forward-ports:  
 source-ports:  
 icmp-blocks:  
 rich rules: 

하지만 여전히 10.192.52.50/32 호스트에서 SSH에 연결할 수 있습니다. 내가 여기서 놓치고 있는 것

그만큼iptables -nvL -t filter명령은 아직 accept 인 체인이 여러 개 있다는 것을 알려줍니다. DROP으로 설정하면 안 되나요? 그렇다면 호스트 10.192.57.6/32를 제외한 모든 트래픽을 거부하도록 설정하는 방법은 무엇입니까?

[root@centosmin firewalld]# iptables -nvL -t filter 
Chain INPUT (policy ACCEPT 0 packets, 0 bytes) 
pkts bytes target     prot opt in     out     source               destination          
 459 34244 ACCEPT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate RELATED,ESTABLISHED 
   0     0 ACCEPT     all  --  lo     *       0.0.0.0/0            0.0.0.0/0            
   0     0 INPUT_direct  all  --  *      *       0.0.0.0/0            0.0.0.0/0            
   0     0 INPUT_ZONES_SOURCE  all  --  *      *       0.0.0.0/0            0.0.0.0/0            
   0     0 INPUT_ZONES  all  --  *      *       0.0.0.0/0            0.0.0.0/0            
   0     0 DROP       all  --  *      *       0.0.0.0/0            0.0.0.0/0            ctstate INVALID 
   0     0 REJECT     all  --  *      *       0.0.0.0/0            0.0.0.0/0            reject-with icmp-host-prohibited

직접링크RedHat에서는 이를 위해서는 목표를 설정해야 한다고 말합니다. 하지만 이전 단계에서 이미 해당 작업을 수행했으며 여전히 10.192.52.50/32에서 연결할 수 있는데 이는 예상된 동작이 아닙니다.

명령의 요청된 출력을 추가하는 추가

[root@centosmin firewalld]# firewall-cmd --list-all-zones
block
  target: %%REJECT%%
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


dmz
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


drop
  target: DROP
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


external
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: ssh
  ports: 
  protocols: 
  masquerade: yes
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


home
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: dhcpv6-client mdns samba-client ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


internal
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: dhcpv6-client mdns samba-client ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


internet (active)
  target: DROP
  icmp-block-inversion: no
  interfaces: 
  sources: 10.192.57.6/32
  services: ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


public (active)
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 10.192.57.6
  services: ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


trusted
  target: ACCEPT
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: 
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 


work
  target: default
  icmp-block-inversion: no
  interfaces: 
  sources: 
  services: dhcpv6-client ssh
  ports: 
  protocols: 
  masquerade: no
  forward-ports: 
  source-ports: 
  icmp-blocks: 
  rich rules: 

관련 정보