Skip to content

ufw - Die einfache Firewall

Linux
  • 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
    

  • Python - Interessante Packages

    Python3
    1
    0 Stimmen
    1 Beiträge
    70 Aufrufe
    Niemand hat geantwortet
  • Update 1.32.5 - Security Fixes!

    Vaultwarden
    1
    0 Stimmen
    1 Beiträge
    72 Aufrufe
    Niemand hat geantwortet
  • Restic v0.16.5 released

    Restic
    1
    0 Stimmen
    1 Beiträge
    117 Aufrufe
    Niemand hat geantwortet
  • MongoDB Compass

    Linux
    1
    0 Stimmen
    1 Beiträge
    208 Aufrufe
    Niemand hat geantwortet
  • NodeBB - v3.6.0

    NodeBB
    1
    0 Stimmen
    1 Beiträge
    78 Aufrufe
    Niemand hat geantwortet
  • Thunderbird - Schriftgröße der Mailansicht dauerhaft ändern

    Linux
    1
    0 Stimmen
    1 Beiträge
    183 Aufrufe
    Niemand hat geantwortet
  • NodeBB - spawn npm ENOENT

    NodeBB
    1
    0 Stimmen
    1 Beiträge
    413 Aufrufe
    Niemand hat geantwortet
  • Liste von Linuxbefehlen

    Angeheftet Linux
    3
    0 Stimmen
    3 Beiträge
    685 Aufrufe
    FrankMF
    systemd Anzeige der geladenen Dienste root@host:/etc/systemd/system# systemctl --type=service UNIT LOAD ACTIVE SUB DESCRIPTION atd.service loaded active running Deferred execution scheduler blk-availability.service loaded active exited Availability of block devices cloud-config.service loaded active exited Apply the settings specified in cloud-config cloud-final.service loaded active exited Execute cloud user/final scripts cloud-init-local.service loaded active exited Initial cloud-init job (pre-networking) cloud-init.service loaded active exited Initial cloud-init job (metadata service crawler) console-setup.service loaded active exited Set console font and keymap cron.service loaded active running Regular background program processing daemon crowdsec-firewall-bouncer.service loaded active running The firewall bouncer for CrowdSec crowdsec.service loaded active running Crowdsec agent dbus.service loaded active running D-Bus System Message Bus getty@tty1.service loaded active running Getty on tty1 ifupdown-pre.service loaded active exited Helper to synchronize boot up for ifupdown keyboard-setup.service loaded active exited Set the console keyboard layout kmod-static-nodes.service loaded active exited Create List of Static Device Nodes lvm2-monitor.service loaded active exited Monitoring of LVM2 mirrors, snapshots etc. using dmeventd or progress polling mariadb.service loaded active running MariaDB 10.11.3 database server networking.service loaded active exited Raise network interfaces nginx.service loaded active running A high performance web server and a reverse proxy server qemu-guest-agent.service loaded active running QEMU Guest Agent resolvconf.service loaded active exited Nameserver information manager semaphore.service loaded active running Ansible Semaphore serial-getty@ttyS0.service loaded active running Serial Getty on ttyS0 ssh.service loaded active running OpenBSD Secure Shell server systemd-binfmt.service loaded active exited Set Up Additional Binary Formats systemd-fsck@dev-disk-by\x2duuid-1E22\x2dDC00.service loaded active exited File System Check on /dev/disk/by-uuid/1E22-DC00 systemd-journal-flush.service loaded active exited Flush Journal to Persistent Storage systemd-journald.service loaded active running Journal Service systemd-logind.service loaded active running User Login Management systemd-modules-load.service loaded active exited Load Kernel Modules systemd-random-seed.service loaded active exited Load/Save Random Seed systemd-remount-fs.service loaded active exited Remount Root and Kernel File Systems systemd-sysctl.service loaded active exited Apply Kernel Variables systemd-sysusers.service loaded active exited Create System Users systemd-timesyncd.service loaded active running Network Time Synchronization systemd-tmpfiles-setup-dev.service loaded active exited Create Static Device Nodes in /dev systemd-tmpfiles-setup.service loaded active exited Create Volatile Files and Directories systemd-udev-trigger.service loaded active exited Coldplug All udev Devices systemd-udevd.service loaded active running Rule-based Manager for Device Events and Files systemd-update-utmp.service loaded active exited Record System Boot/Shutdown in UTMP systemd-user-sessions.service loaded active exited Permit User Sessions ufw.service loaded active exited Uncomplicated firewall user-runtime-dir@0.service loaded active exited User Runtime Directory /run/user/0 user@0.service loaded active running User Manager for UID 0 LOAD = Reflects whether the unit definition was properly loaded. ACTIVE = The high-level unit activation state, i.e. generalization of SUB. SUB = The low-level unit activation state, values depend on unit type. 44 loaded units listed. Pass --all to see loaded but inactive units, too. To show all installed unit files use 'systemctl list-unit-files'.