Alle Beiträge von neutrinus

Beat Caveng, Developer bei A-Enterprise GmbH. Blog Author zu den Themen, Python und Open Source. Tutorials zu Python Problemlösungen und Shell Scripts.

Block IP by ufw or iptables and firewalld

A large number of suspicious requests is going on, protection is provided by ufw, iptables or firewalld. This tutorial show how to use the commands to reject an IP address on popular Linux software Firewalls.

Block IP by ufw or iptables and firewalld

Using ufw or iptables and firewalld

Fire up a terminal and log on to the server by using SSH and then complete the steps for firewalld in the first chapter. The second chapter shows the commands for UFW, and the third shows using iptables.

firewalld tool

firewalld is on RHEL 7, CentOS 7 and later, Fedora 18 and later.

To ensure that firewalld is running on your server, run the following command. If firewalld is not running, go to the iptables chapter.

$ sudo systemctl status firewalld

Run the following command to block the IP address and to add the rule to the permanent set:

$ sudo firewall-cmd --permanent --add-rich-rule="rule family='ipv4' source address='xxx.xxx.xxx.xxx' reject"

Run the following command to reload the firewalld rules:

$ sudo firewall-cmd --reload

Run the following command to list and verify the new rule:

$ sudo firewall-cmd --list-all

Run the following command to remove a blocked IP address.

$ sudo firewall-cmd --remove-rich-rule="rule family='ipv4' source address='xxx.xxx.xxx.xxx' reject"

Run the following command to verify the firewalld is running.

$ firewall-cmd --state

Uncomplicated Firewall (UFW)

ufw is available on Debian 6 and later, Ubuntu 8.04 LTS and later.

To ensure that ufw is running on your server, run the following command. If ufw is not running, go to the iptables chapter.

$ sudo systemctl status ufw

Run the following command to block the IP address:

$ sudo ufw deny from xxx.xxx.xxx.xxx to any

Run the following command to list and verify the new rule:

$ sudo ufw status

Run the following command to remove a blocked IP address.

$ sudo ufw delete 7

Run the following command to show numbered list of firewall rules.

$ ufw status numbered

iptables tool

iptables is commonly pre-installed on all Linux distributions.

Run the following command to block the IP address:

$ sudo iptables -I INPUT -s xxx.xxx.xxx.xxx -j DROP

Run the following command to save the settings. The settings persist after the server reboots.

$ sudo service iptables save

Run the following command to list and verify the new rule:

$ sudo iptables -vnL

Run the following command to delete a iptables chain.

$ sudo iptables -D INPUT 7

Run the following command to show numbered list of iptables chains.

$ sudo iptables -L --line-numbers

about ufw or iptables and firewalld

The firewall commands ufw, iptables and firewalld shown here for the corresponding kernel firewalls apply to the most common Linux operating systems.

SSH aus KeePass mit Windows Terminal starten

Dieses Tutorial beschreibt das starten einer SSH-Terminal Sitzung unter Windows, geöffnet wird die Verbindung aus dem KeePass Manager, dem bekannten Passwort Safe, und unter Verwendung von OpenSSH und dem Windows Terminal. Voraussetzung ist, das OpenSSH auf dem Windows Rechner installiert ist, aus Apps & Features – Optionale Features. Das Windows Terminal ist im Microsoft Store zu finden.

Das neue Windows Terminal hat sich entwickelt und erreicht die Parität sich mit modernen Terminals anderer Betriebssysteme wie dem GNOME Terminal messen zu lassen. Es ist nicht nur kostenlos, es kann sich auch mit den bekannten Terminal Tools unter Windows sehen lassen, wie beispielsweise PuTTY und KiTTY.

Windows Terminal ist für die Batchverarbeitung mit Pfad ausführbar.

%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe

Hier aus KeePass über das Feld URL mit dem „cmd://“ Argument.

Für den Eintrag in KeePass in das Feld URL folgende Zeile hinzufügen.

cmd://"%LOCALAPPDATA%\Microsoft\WindowsApps\wt.exe" ssh -v {USERNAME}@{TITLE}

  Aus dem Feld „Title“ wird der Hostname in {TITLE} übergeben, und aus „User name“ die Benutzer-ID in {USERNAME}. Wird ein abweichender Port für SSH verwendet muss der Port angegeben werden, zB. -p 60622

Mit OK den Eintrag schliessen und speichern. Ein Doppel-Klick auf den Eintrag in der Spalte URL öffnet das Windows Terminal.

Der Host Eintrag wird in der Windows Terminal Einstellungen (Ctrl+,) hinzugefügt, mit Neues Profil hinzufügen.

  Tipp! Mit ssh-keyen generierte Schlüssel lassen sich SSH Sitzungen ohne Passwort Eingabe und dazu noch sicherer nutzen.

SSH aus KeePass mit Windows Terminal starten

Dazu legt man unter dem Homepfad %USERPROFILE% den Ordner .ssh an, in diesem Privat und Public Keys abgelet werden, mit anlegen der Datei config kann der Host konfiguriert werden, mit der zuweisung von Hostname und dem passenden Privat Key.

Host vm126
    HostName 10.10.0.11
    User james
    IdentityFile ~/.ssh/id_rsa
    ServerAliveInterval 60

Der Public Key (id_rsa.pub) wird auf dem Remote Host unter ~/.ssh/authorized_keys gespeichert.