Linux - Netzwerk und Serveradminstration Firewall Rocky

Aus Xinux Wiki
Zur Navigation springen Zur Suche springen

Firewall

Routing und Masquerading

  • Damit die Firewall als Internet-Router fungieren kann, muss die Quell-IP der Pakete umgeschrieben werden
  • Dazu müssen Firewall-Regeln unter [nftables Masquerade|nftables]] erstellt werden, das machen wir weiter unten.

Wir klonen das Rocky-Template

Folgendes stellen wir ein

Attribut Wert Netzwerk / Typ
Name fw -
RAM 4 GB -
CPU 4 Kerne -
1. NIC WAN NAT / Bridge (Extern)
2. NIC DMZ Internes Netzwerk (Client-Netz)
3. NIC LAN Internes Netzwerk (Demilitarized Zone)
4. NIC SERVER Internes Netzwerk (Server-Netz)

Erklärung

  • XX = Platznummer
  • Y = Klassensaal

Hostname

  • hostnamectl hostname fw.it2XX.int

firewalld deaktivieren

firewalld und nftables gleichzeitig führen zu Konflikten – firewalld wird dauerhaft deaktiviert
  • sudo systemctl disable --now firewalld

Interfaces

  • cat /etc/NetworkManager/system-connections/
Alle Interfaces mit nmcli konfigurieren
WAN
nmcli con mod enp0s3 ipv4.addresses 192.168.Y.2XX/24
nmcli con mod enp0s3 ipv4.gateway 192.168.Y.254
nmcli con mod enp0s3 ipv4.method manual
nmcli con mod enp0s3 connection.autoconnect yes
nmcli con up enp0s3
Statische Route für 10.88.0.0/16
nmcli con mod enp0s3 +ipv4.routes "10.88.0.0/16 192.168.Y.88"
nmcli con up enp0s3
DMZ
nmcli con mod enp0s8 ipv4.addresses 10.88.2XX.1/24
nmcli con mod enp0s8 ipv4.method manual
nmcli con mod enp0s8 connection.autoconnect yes
nmcli con up enp0s8
LAN
nmcli con mod enp0s9 ipv4.addresses 172.26.2XX.1/24
nmcli con mod enp0s9 ipv4.method manual
nmcli con mod enp0s9 connection.autoconnect yes
nmcli con up enp0s9
SERVERS
nmcli con mod enp0s10 ipv4.addresses 10.2XX.1.1/24
nmcli con mod enp0s10 ipv4.method manual
nmcli con mod enp0s10 connection.autoconnect yes
nmcli con up enp0s10

Hosts

  • cat /etc/hosts
127.0.0.1        localhost
127.0.1.1        fw.it2XX.int fw
# The following lines are desirable for IPv6 capable hosts
::1      localhost ip6-localhost ip6-loopback
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters

Resolver

DNS wird über nmcli gesetzt
nmcli con mod enp0s3 ipv4.dns 192.168.Y.88
nmcli con mod enp0s3 ipv4.dns-search it2XX.int
nmcli con up enp0s3
Hinweis
/etc/resolv.conf wird unter Rocky von NetworkManager automatisch verwaltet – nicht manuell bearbeiten!

NAT mit nftables

Datei erstellen, alles was drin ist kann raus
  • cat /etc/nftables.conf
#!/usr/sbin/nft -f
# Variablen
define LAN = 172.26.2XX.0/24
define SERVER = 10.2XX.1.0/24
define DMZ = 10.88.2XX.0/24
# Alte Regeln löschen (flush)
flush ruleset
# NAT-Tabelle erstellen/verwenden
table ip nat {
    chain postrouting {
        type nat hook postrouting priority 100; policy accept;
        
        # DMZ nach 192.168.Y.0/24 - kein NAT (RETURN)
        ip saddr $DMZ ip daddr 192.168.Y.0/24 return
        
        # DMZ nach 10.88.0.0/16 - kein NAT (RETURN)
        ip saddr $DMZ ip daddr 10.88.0.0/16 return
        
        # DMZ nach außen (enp0s3) - Masquerade
        ip saddr $DMZ oif enp0s3 masquerade
        
        # LAN nach außen - Masquerade
        ip saddr $LAN oif enp0s3 masquerade
        
        # SERVERS nach außen - Masquerade
        ip saddr $SERVER oif enp0s3 masquerade
    }
}
Firewall aktivieren
  • sudo systemctl enable --now nftables

Forward

  • echo "net.ipv4.ip_forward=1" > /etc/sysctl.d/99-ipforward.conf
  • sysctl -p /etc/sysctl.d/99-ipforward.conf

Reboot

  • systemctl reboot