Skip to content

ufw - Die einfache Firewall

Linux
3 1 362
  • Was ist ufw?

    Uncomplicated Firewall (ufw) — The Uncomplicated Firewall (ufw, and gufw - a Graphical User Interface version of the same) is a frontend for iptables and is particularly well-suited for host-based firewalls. Ufw provides a framework for managing netfilter, as well as a command-line interface for manipulating the firewall.

    Quelle: https://wiki.debian.org/Uncomplicated Firewall (ufw)

    ufw ist nur ein Frontend, im Hintergrund wird weiterhin iptables benutzt. Aber ufw ist wesentlich einfacher. Ja, ich kann mir nicht alles merken 😉

    Ich wollte das mal ausprobieren um zu schauen, ob das meine iptables Einstellungen ersetzen kann. Das hier behandelt ufw nur im Kontext einer Server Installation. Solltet ihr das für einen Desktop benötige, dafür gibt es gufw. Ok, auf geht's..

    Installation

    apt install ufw
    

    Standardeinstellungen

    root@test-server:~# ufw status
    Status: active
    
    To                         Action      From
    --                         ------      ----
    OpenSSH                    ALLOW       Anywhere                  
    OpenSSH (v6)               ALLOW       Anywhere (v6)
    

    Hier sieht man den Status, nachdem ich mittels Ansible einen Server in der Hetzner Cloud erstellt habe. Dazu setze ich ein paar Einstellungen, die wären.

        #####################
        # Setup UFW
        #####################
        - name: Enable UFW
           community.general.ufw:
           state: enabled
    
        - name: Set policy IN
          community.general.ufw:
            direction: incoming
            policy: deny
    
        - name: Set policy OUT
          community.general.ufw:
            direction: outgoing
            policy: allow
    
        - name: Set logging
          community.general.ufw:
            logging: 'on'
    
        - name: Allow OpenSSH rule
          community.general.ufw:
            rule: allow
            name: OpenSSH
    

    Auf der Konsole wäre das dann folgendes

    ufw default deny incoming
    ufw default allow outgoing
    ufw logging on
    ufw allow 22/tcp
    

    Ein

    ufw enable
    

    und die Firewall ist aktiv. Kann man mit

    root@test-server:~# ufw status
    Status: active
    
    To                         Action      From
    --                         ------      ----
    22/tcp                     ALLOW       Anywhere                  
    22/tcp (v6)                ALLOW       Anywhere (v6)  
    

    überprüfen. Ihr könnt auch mit

    iptables -L
    ip6tables -L
    

    die entsprechenden Einstellungen für iptables Euch anschauen.

    root@test-server:~# iptables -L
    Chain INPUT (policy DROP)
    target     prot opt source               destination         
    ufw-before-logging-input  all  --  anywhere             anywhere            
    ufw-before-input  all  --  anywhere             anywhere            
    ufw-after-input  all  --  anywhere             anywhere            
    ufw-after-logging-input  all  --  anywhere             anywhere            
    ufw-reject-input  all  --  anywhere             anywhere            
    ufw-track-input  all  --  anywhere             anywhere            
    
    Chain FORWARD (policy DROP)
    target     prot opt source               destination         
    ufw-before-logging-forward  all  --  anywhere             anywhere            
    ufw-before-forward  all  --  anywhere             anywhere            
    ufw-after-forward  all  --  anywhere             anywhere            
    ufw-after-logging-forward  all  --  anywhere             anywhere            
    ufw-reject-forward  all  --  anywhere             anywhere            
    ufw-track-forward  all  --  anywhere             anywhere            
    
    Chain OUTPUT (policy ACCEPT)
    target     prot opt source               destination         
    ufw-before-logging-output  all  --  anywhere             anywhere            
    ufw-before-output  all  --  anywhere             anywhere            
    ufw-after-output  all  --  anywhere             anywhere            
    ufw-after-logging-output  all  --  anywhere             anywhere            
    ufw-reject-output  all  --  anywhere             anywhere            
    ufw-track-output  all  --  anywhere             anywhere            
    
    Chain ufw-after-forward (1 references)
    target     prot opt source               destination         
    [..gekürzt..]
    

    Mit

    ufw reset
    

    löscht man alle Einstellungen.

    Hier noch die Ausgabe auf --help

    root@test-server:~# ufw --help
    
    Usage: ufw COMMAND
    
    Commands:
     enable                          enables the firewall
     disable                         disables the firewall
     default ARG                     set default policy
     logging LEVEL                   set logging to LEVEL
     allow ARGS                      add allow rule
     deny ARGS                       add deny rule
     reject ARGS                     add reject rule
     limit ARGS                      add limit rule
     delete RULE|NUM                 delete RULE
     insert NUM RULE                 insert RULE at NUM
     prepend RULE                    prepend RULE
     route RULE                      add route RULE
     route delete RULE|NUM           delete route RULE
     route insert NUM RULE           insert route RULE at NUM
     reload                          reload firewall
     reset                           reset firewall
     status                          show firewall status
     status numbered                 show firewall status as numbered list of RULES
     status verbose                  show verbose firewall status
     show ARG                        show firewall report
     version                         display version information
    
    Application profile commands:
     app list                        list application profiles
     app info PROFILE                show information on PROFILE
     app update PROFILE              update PROFILE
     app default ARG                 set default application policy
    
  • Um eine Rule zu löschen, macht man folgendes

    root@semaphore:/home/semaphore# ufw status numbered
    

    Status: active

    Um eine Rule zu löschen, macht man folgendes

    root@semaphore:/home/semaphore# ufw status numbered
    Status: active
    
         To                         Action      From
         --                         ------      ----
    [ 1] 22/tcp                     ALLOW IN    Anywhere                  
    [ 2] 3000/tcp                   ALLOW IN    Anywhere                  
    [ 3] 80                         ALLOW IN    Anywhere                  
    [ 4] 443                        ALLOW IN    Anywhere                  
    [ 5] 22/tcp (v6)                ALLOW IN    Anywhere (v6)             
    [ 6] 3000/tcp (v6)              ALLOW IN    Anywhere (v6)             
    [ 7] 80 (v6)                    ALLOW IN    Anywhere (v6)             
    [ 8] 443 (v6)                   ALLOW IN    Anywhere (v6)          
    

    Jetzt kann man mit der Nummer die Rule löschen.

     root@semaphore:/home/semaphore# ufw delete 2
     Deleting:
      allow 3000/tcp
     Proceed with operation (y|n)? y       
     Rule deleted
    
  • Beispiel um eingehend einen Port für eine IP-Adresse zu erlauben.

    ufw allow from 1.1.1.1 to any port 8000
    
  • 0 Stimmen
    2 Beiträge
    18 Aufrufe
    frankm@nrw.socialF
    @stevegio I love https://github.com/dani-garcia/vaultwarden"Unofficial Bitwarden compatible server written in Rust"
  • Did you know?

    Uncategorized free linux
    1
    0 Stimmen
    1 Beiträge
    22 Aufrufe
    Niemand hat geantwortet
  • Fedora 42

    Linux fedora linux btrfs
    2
    2
    0 Stimmen
    2 Beiträge
    428 Aufrufe
    FrankMF
    Ich habe mir gestern den Cosmic Desktop angesehen. Davon abgesehen, das er noch ein sehr frühes Stadium ist, hat er mir nicht wirklich gefallen. Also heute mal die Referenz von Fedora installiert, die Workstation mit Gnome Desktop. Wer hier lange mitliest, weiß das ich kein Fanboy vom Gnome Desktop bin. Aber ich wollte unbedingt mal den Anaconda Installer sehen. Der ist richtig gut geworden und das man jetzt das Tastaturlayout für die Verschlüsselung einstellen kann, wird hoffentlich in Zukunft verhindern, das ich mit einer amerikanischen Tastatur meine Passphrase eingeben muss Da war ja vorher bei meinen Test das Problem, das ich nach Standby nicht über die Tastatur aufwecken konnte. Das war eine Einstellung im BIOS, irgendwas mit Wakeup/BIOS/USB Jetzt funktioniert das auch einwandfrei. Und zu Gnome sag ich mal nichts, ich bin da vermutlich zu alt für Ich lasse es aber mal ein paar Tage auf der Platte, vielleicht erkenne ich ja noch seinen Nutzen. Zum Schluss, das schöne an FOSS ist, wir haben die Wahl welchen Desktop wir installieren dürfen. Fedora 42 sieht gut aus und läuft rund. Jetzt mal suchen, wo ich in Gnome diese beschissene Updateverhalten ausschalten kann, was aussieht wie ein Windows. Das braucht nun wirklich niemand.
  • Manjaro KDE Plasma 21.2.6

    Linux manjaro kde linux
    16
    2
    0 Stimmen
    16 Beiträge
    944 Aufrufe
    FrankMF
    @FrankM sagte in Manjaro KDE Plasma 21.2.6: Eines betrifft die Anordnung der Icons auf dem Desktop. Die Anordnung, die ich wähle, werden immer wieder geändert. Unschön, aber den Desktop nutze ich so gut wie gar nicht. Also kann ich auch auf den Fix warten. Kann noch was dauern https://pointieststick.com/2023/03/03/this-week-in-kde-plasma-6-begins/ Desktop icons on the active activity should no longer inappropriately re-arrange themselves when the set of connected screens changes. However during the process of investigation, we discovered that the code for storing desktop file position is inherently problematic and in need of a fundamental rewrite just like we did for multi-screen arrangement in Plasma 5.27. This will be done for Plasma 6.0, and hopefully make Plasma’s long history of being bad about remembering desktop icon positions just that–history (Marco Martin, Plasma 5.27.3. Link)
  • Nextcloud 23.0.3

    Nextcloud nextcloud linux
    1
    0 Stimmen
    1 Beiträge
    184 Aufrufe
    Niemand hat geantwortet
  • Mainline 5.11.x

    Images linux rockpro64
    1
    0 Stimmen
    1 Beiträge
    287 Aufrufe
    Niemand hat geantwortet
  • VS Code - entferntes Verzeichnis einbinden

    Linux vscode linux
    2
    0 Stimmen
    2 Beiträge
    463 Aufrufe
    FrankMF
    Mein kleines Projekt liegt auch noch auf gitlab.com. Man kann prima die beiden Dienste (VSCode & gitlab.com) verknüpfen. Eine Änderung, ein commit und dann git push origin master Und die Änderungen sind oben. Aber, ich stecke da noch ganz am Anfang der Lernkurve
  • pdo Abfrage funktioniert nicht

    Linux linux
    2
    0 Stimmen
    2 Beiträge
    592 Aufrufe
    FrankMF
    Wichtig ist natürlich auch, das folgendes php Paket installiert ist! sudo apt install php7.0-mysql Je nachdem welche PHP Version installiert ist, muss der Befehl angepasst werden. Mit php -v könnt ihr nachschauen welche Version installiert ist.