Block IP address using Linux Firewall

DDoS and suspicious attacks from source IP addresses can exhaust services and system resources. This tutorial show the commands to block IP address on common Linux Kernel Firewalls

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.

Block IP address using Linux firewall

firewalld is on RHEL 7 and later, CentOS 7, 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 using Linux Firewall 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

Block IP addresses using Linux iptables chains

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

The next related post might also be helpful, see in Block suspicious IP with Linux firewall daemon.

Visual Basic Script Windows Logon with Message-Box

Visual Basic Script Message-Box Pop-up Window

Visual Basic Script Message-Box, MsgBox Logon Message

Server administrators have the ability to send message to users to inform them when they log on to the workplace.

VBScript Message-Box (MsgBox) Logon

The Visual Basic Script Message-Box (MsgBox) function is excellent for this purpose. Insert the following 3 lines into an editor (Notepad) and save them as i.e. “logon.bat”.

echo msgbox("Good morning staff. we serve coffee or tea in the lounge bar. Thank you and a nice day!"),vbInformation ,"Message"> %temp%\msg.vbs
%temp%\msg.vbs
erase %temp%\msg.vbs

This VB-Script creates a pop-up window with information through the MsgBox function. The msg.vbs file is saved under %temp% and erase them after execution.

The user can close the opened window by clicking OK.

User Logon script (dsa.msc)

In the AD user administration (dsa.msc) for the corresponding users, enter the file name in the Profile tab at Logon script (logon.bat).

For Windows domain, save the file to \\server\netlogon.

  The netlogon share is located on the server at %systemroot%\SYSVOL\sysvol\[domain]\scripts. If a logon script is already in use, the code lines can be inserted into this script.

Microsoft Visual Basic Scripting Edition

VBScript (“Microsoft Visual Basic Scripting Edition”) is an Active Scripting language developed by Microsoft that is modeled on Visual Basic. It allows Microsoft Windows system administrators to generate powerful tools for managing computers without error handling and with subroutines and other advanced programming constructs. It can give the user complete control over many aspects of their computing environment.

VBScript uses the Component Object Model to access elements of the environment within which it is running. For example, the FileSystemObject (FSO) is used to create, read, update and delete files. VBScript has been installed by default in every desktop release of Microsoft Windows since Windows 98. In Windows Server since Windows NT 4.0 Option Pack; and optionally with Windows CE (depending on the device it is installed on).

A VBScript script must be executed within a host environment, of which there are several provided with Microsoft Windows, including: Windows Script Host (WSH), Internet Explorer (IE), and Internet Information Services (IIS). Additionally, the VBScript hosting environment is embeddable in other programs, through technologies such as the Microsoft Script Control (msscript.ocx).

Exit mobile version