Shore Up
Geometric shapes approaching a gate and dividing into two streams, one admitted and one turned back
CentOSLinuxWindowsZimbra Server

Whitelist or Blacklist per IP on Zimbra Server – Batch File

Ketan Aagja7 min read
No ratings yet

Whitelist or Blacklist per IP on Zimbra Server – Batch File, are you getting many spam requests from IP addresses? Do you want to block or allow IPs instantly? It’s been one hectic task for Email Administrators when they need to manage IP based whitelist and blacklist. Well here is the hassle free solution…!!!

Check out my other Zimbra Batch files:

Zimbra User Management

Zimbra Group / Distribution Lists Management

You will have to apply and modify some of the changes to get this work for you on your Zimbra Open Source Collaboration Server. Here is the guide that you need to follow first before going further below. Click HERE

I believe you have changed your required files and successfully setup RBL Override and Postfix Blacklist setup.

This is my guaranty, this batch file neither will affect any of your server operation nor it will modify any core configurations. It will only do the things that you are asking it to do!

Here are the basic requirements that you need when you use this batch file:

  • Install PUTTY on your windows PC where you will be using this batch file. (Get PUTTY – Free SSH and telnet Client for Windows – HERE)
  • Only use installer / setup of Putty, not the standalone Putty EXE
  • After installing Putty, just connect your Zimbra mail server first time using Putty from your Windows PC with ROOT User ID so that Putty can negotiate and accept ECDSA key fingerprint. Once done exit Putty.

My Zimbra Version - Release 8.7.3_GA_1750 (Centos 7 x64 - FOSS Edition)

Copy / Paste below batch file in notepad or any text editor.

Save as .bat file, modify below stated two lines and start using it confidently…!!!
Here is the batch file that can fulfill your whitelist and blacklist setup instantly, yes just about giving it 10 seconds. That’s hell faster yea..!!!

You only have to change following in batch file nothing else:

Line No: 9 — srv=Your Server’s IP

Line No: 11 — pws=Your Server’s ROOT User Password

@echo off
SETLOCAL EnableDelayedExpansion
color 1f
mode con: cols=90 lines=35
title Zimbra Server Management Script - By: Ketan Aagja
set zmp=/opt/zimbra/bin/zmprov
 
::Change your zimbra server IP below
set srv=MY ZIMBRA SERVER IP
:: Change your zimbra server password below
set pws=ROOT PASSWORD
SET STR=">> /opt/zimbra/conf/postfix_blacklist"
FOR /F "usebackq tokens=*" %%A IN (`ECHO %STR%`) DO set wht=%%~A
SET STR1=">> /opt/zimbra/conf/postfix_rbl_override"
FOR /F "usebackq tokens=*" %%A IN (`ECHO %STR1%`) DO set wht1=%%~A
cls
echo 			    Designed by : KETAN AAGJA
echo.
echo.
echo 		   ****** PLEASE SELECT APPROPRIATE OPERATION ******
echo. 	
echo.
echo.
echo.
echo.
echo.
echo.
echo				  PRESS 1 - WHITELIST IP ON ZIMBRA SERVER
echo. 
echo.
echo.
echo. 
echo.
echo. 	
echo.
echo.
echo				  PRESS 2 - BLACKLIST IP ON ZIMBRA SERVER
echo.
echo.
echo.
echo.  	
echo.
echo.
echo.
echo.


set /p vid=SELECT AN OPTION :        
echo.
echo.
echo.

cls

IF %vid%==1 GOTO white
IF %vid%==2 GOTO black
IF NOT DEFINED %vid% GOTO away


:white
cls
echo.
echo.
echo 			    *** PLEASE ENTER IP ADDRESS ***
echo. 	
echo.
echo.
echo. 
echo.
echo.
echo.
echo. 	
echo.
echo.
echo.
echo. 	
echo.
echo.
echo.
set /p vid1= IP ADDRESS :        
echo.
echo.
cls
echo.
echo.
echo.
echo.
IF EXIST %TMP%\white.log del /F %TMP%\white.log
echo echo "!vid1! OK" !wht1! >> %TMP%\white.log
echo /opt/zimbra/common/sbin/postmap /opt/zimbra/conf/postfix_rbl_override >> %TMP%\white.log
"C:\Program Files (x86)\PuTTY\putty.exe" -ssh root@%srv% -pw %pws% -m %TMP%\white.log
CLS
color 2f
echo. 	
echo.
echo.
echo 	             *** !vid1! HAS BEEN WHITELISTED ***
echo. 	
echo.
echo.
echo. 
echo.
echo.
echo.
echo. 	
echo.
echo.
echo.
echo. 	
echo.
echo.
echo.
echo 			  *** PRESS ANY KEY TO EXIT ***
pause >nul
exit


:black
cls
echo.
echo.
echo 		      *** PLEASE ENTER IP ADDRESS ***
echo. 	
echo.
echo.
echo. 
echo.
echo.
echo.
echo. 	
echo.
echo.
echo.
echo. 	
echo.
echo.
echo.
set /p vid1= IP ADDRESS :     
echo.
echo.
IF EXIST %TMP%\black.log del /F %TMP%\black.log
echo echo "!vid1! REJECT" !wht! >> %TMP%\black.log
echo /opt/zimbra/common/sbin/postmap /opt/zimbra/conf/postfix_blacklist >> %TMP%\black.log
"C:\Program Files (x86)\PuTTY\putty.exe" -ssh root@%srv% -pw %pws% -m %TMP%\black.log
CLS
color 2f
echo.
echo.
echo.
echo 	     *** %VID1% HAS BEEN BLACKLISTED ***
echo. 	
echo.
echo.
echo. 
echo.
echo.
echo.
echo. 	
echo.
echo.
echo.
echo. 	
echo.
echo.
echo.
echo 			   *** PRESS ANY KEY TO EXIT ***
pause >nul
exit


:away
color 1f
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo.
echo             			*** GO AWAY BAD GUY ***
echo. 	
echo.
echo.
echo. 
echo.
echo.

ping -n 4 127.0.0.1 >nul

Do write me or share your views/suggestions on how simply this is saving your time and helping you manage Zimbra users.

Written by
Ketan Aagja

Runs enterprise networks and security for a living, and writes Shore Up to turn two decades of hands-on Linux, Windows and mail-server work into guides you can actually use.

More about the author →

Was this article helpful?

Tap a star — no sign-in needed.

Be the first to rate this article.

Zimbra User Management – Batch File

Everybody loves Zimbra. The best in class Zimbra Collaboration Open Source Email server with contacts, tasks and calendar management on your finger tips. I indeed love it and recommend it to small and medium businesses when they ask me how can we achieve best in-house Email server. Even many big data enterprises are also using this feature rich daemon. Find our more information about Zimbra here – Zimbra Collaboration Open Source Edition System / email administrators manages users from Zimbra Admin Panel where they can create / modify and delete users and do many things. However I find it quite lazy myself when administering users using Zimbra Admin Panel. Believe me, login on to Zimbra Admin panel, issuing…

12 min read

Zimbra Group Management – Batch File

My another batch file to manage Groups or Distribution lists on Zimbra server from your Windows PC. Check out my Zimbra User Management – Batch File : HERE Find our more information about Zimbra here – Zimbra Collaboration Open Source Edition It is very simple batch file, just to achieve three simple activities from Zimbra Group Management – Batch File using SSH from any windows PC: Create Distribution List Add Member to Group List Remove member from Group Here are the basic requirements that you need when you use this batch file: Install PUTTY on your windows PC where you will be using this batch file. (Get PUTTY –…

9 min read

OpenLDAP Master Slave Replication In A Minute

Often I have seen that OpenLDAP Master Slave Replication seems heavy job for server administrators. Many articles are available to achieve this scenario but majority of the articles are so detailed that mostly administrators gets confused about their replication. Many time they applies replication configuration on server but loses data on either server or sometime whole database. Or gets locked out from database where they are not able to recover data. Many time, I also have made mistakes in learning OpenLDAP Master Slave Replication on my test servers, but just to understand and learn the whole process. Here is how you can achieve OpenLDAP Master Slave Replication in just a minute. Applied on CentOS Linux…

3 min read

Two way Dovecot Server Replication / Mirroring

Here is step-by-step guide to achieve two way Dovecot server replication / mirroring. I had been searching a lot to achieve two way dovecot server replication / mirroring and had been trying out many things. None methods were giving me sure shot and performance intensive results. Well you all do is, play with it more to understand it more and achieve more. This is what I did and achieved what I needed. Sharing with you all that what configuration I made with my both live production servers which are now replicating each and every emails with each other. I have not received any single email replication related issue since last 2 years. And still it is…

12 min read