Transform CIDR IP ranges to route add rules

#!/bin/bash

# Input file containing IP ranges in CIDR notation
INPUT_FILE="ip_ranges.txt"
# Gateway to use in route commands
GATEWAY="192.168.0.1"

# Function to convert CIDR to range and generate route commands
generate_routes() {
local cidr=$1
local gateway=$2

# Extract the base IP and prefix from CIDR
local base_ip=$(echo "$cidr" | cut -d'/' -f1)
local prefix=$(echo "$cidr" | cut -d'/' -f2)

# Calculate the subnet mask
local mask=$(( 0xFFFFFFFF ^ ((1 << (32 - prefix)) - 1) ))
local netmask="$(( (mask >> 24) & 255 )).$(( (mask >> 16) & 255 )).$(( (mask >> 8) & 255 )).$(( mask & 255 ))"

echo "route add -net $base_ip netmask $netmask gw $gateway"
}

# Read input file and process each CIDR block
while read -r line; do
[[ -z "$line" || "$line" =~ ^# ]] && continue # Skip empty lines and comments
generate_routes "$line" "$GATEWAY"
done < "$INPUT_FILE"

Set up Zabbix Server using docker

docker network create --subnet 172.28.0.0/24 --ip-range 172.28.0.0/24 zabbix-net

docker run --name postgres-server -t -e POSTGRES_USER="zabbix" -e POSTGRES_PASSWORD="zabbix_pwd" -e POSTGRES_DB="zabbix" --network=zabbix-net --restart unless-stopped -d postgres:latest
docker run --name zabbix-snmptraps -t -v /zbx_instance/snmptraps:/var/lib/zabbix/snmptraps:rw -v /var/lib/zabbix/mibs:/usr/share/snmp/mibs:ro --network=zabbix-net -p 162:1162/udp --restart unless-stopped -d zabbix/zabbix-snmptraps:alpine-5.4-latest
docker run --name zabbix-server-pgsql -t -e DB_SERVER_HOST="postgres-server" -e POSTGRES_USER="zabbix" -e POSTGRES_PASSWORD="zabbix_pwd" -e POSTGRES_DB="zabbix" -e ZBX_ENABLE_SNMP_TRAPS="true" -e ZBX_CACHESIZE="3072M" -e ZBX_VALUECACHESIZE="1024M" --network=zabbix-net -p 10051:10051 --volumes-from zabbix-snmptraps --restart unless-stopped -d zabbix/zabbix-server-pgsql:alpine-5.4-latest
docker run --name zabbix-server-pgsql -t -e DB_SERVER_HOST="postgres-server" -e POSTGRES_USER="zabbix" -e POSTGRES_PASSWORD="zabbix_pwd" -e POSTGRES_DB="zabbix" -e ZBX_ENABLE_SNMP_TRAPS="true" -e ZBX_CACHESIZE="3072M" --network=zabbix-net -p 10051:10051 --volumes-from zabbix-snmptraps --restart unless-stopped -d zabbix/zabbix-server-pgsql:alpine-5.4-latest
docker run --name zabbix-web-nginx-pgsql -t -e ZBX_SERVER_HOST="zabbix-server-pgsql" -e DB_SERVER_HOST="postgres-server" -e POSTGRES_USER="zabbix" -e POSTGRES_PASSWORD="zabbix_pwd" -e POSTGRES_DB="zabbix" --network=zabbix-net -p 8443:8443 -p 80:8080 -v /etc/ssl/nginx:/etc/ssl/nginx:ro --restart unless-stopped -d zabbix/zabbix-web-nginx-pgsql:alpine-5.4-latest

Backup & Restore pg DB

Backup the database using the following command:
pg_dump -U zabbix -F c zabbix > zabbix.dump

Restore the database using the following command:
pg_restore -U zabbix -d <dbname> ctfdb.dmp