Firewall erlaubt SSH nur von einem vordefinierten IP-Host oder AS-Nummer-Netz

Firewall erlaubt SSH nur von einem vordefinierten IP-Host oder AS-Nummer-Netz

Ich verwende CentOS Linux Release 7.9.2009 in der Minimalinstallation und Firewall.

[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

Es gibt ähnliche Fragen, d. h.Hier aber keine der Antworten dort funktioniert. Ich würde das gerne tun, ohne Reichweitenregeln zu verwenden.

Das Ziel besteht darin, SSH nur von einer bestimmten IP-Adresse im Internet zuzulassen. Um dieses Verhalten zu simulieren, habe ich ein Labor mit 3 Maschinen in verschiedenen VLANs eingerichtet und das Routing zwischen ihnen in meinem internen Netzwerk eingerichtet.

Der Server ist in diesem Fall der

10.192.210.10/24 

und zwei SSH-Clients:

10.192.52.50/24
10.192.57.6/24

Jetzt habe ich meine eigene Internet-Zone erstellt und sie mit den Befehlen als Standard festgelegt

//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 

danach sieht meine einzige Netzwerkschnittstelle so aus

[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: 

Ich kann jedoch immer noch eine SSH-Verbindung vom Host 10.192.52.50/32 herstellen. Was mir hier fehlt

Dieiptables -nvL -t filterDer Befehl sagt mir, dass es mehrere Ketten gibt, die immer noch akzeptieren. Sollte das nicht auf DROP eingestellt werden? Und wenn ja, wie kann man es so einstellen, dass der gesamte Datenverkehr außer vom Host 10.192.57.6/32 abgelehnt wird?

[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

eine direkteVerknüpfungvon RedHat sagt uns, dass wir dazu das Ziel festlegen müssen. Aber das habe ich bereits im vorherigen Schritt getan und kann immer noch eine Verbindung von 10.192.52.50/32 herstellen, was nicht das erwartete Verhalten ist.

Ergänzung durch Hinzufügen der gewünschten Ausgabe des Befehls

[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: 

verwandte Informationen