Skip to content

Instantly share code, notes, and snippets.

@krotesk
Created August 19, 2025 05:25
Show Gist options
  • Select an option

  • Save krotesk/fafbb9e2362323c6558a438fa97fbdad to your computer and use it in GitHub Desktop.

Select an option

Save krotesk/fafbb9e2362323c6558a438fa97fbdad to your computer and use it in GitHub Desktop.
Add addresses as dictionary
#!/bin/bash
readonly connections=(
'192.168.1.4/24|tcp|22'
'192.168.1.5/24|tcp|53'
'192.168.1.6/24|tcp|80'
'192.168.1.7/24|tcp|139'
'192.168.1.8/24|tcp|443'
'192.168.1.9/24|tcp|445'
'192.168.1.10/24|tcp|631'
'192.168.1.11/24|tcp|5901'
'192.168.1.12/24|tcp|6566'
)
function set_connections(){
local range proto port
for fields in ${connections[@]}
do
IFS=$'|' read -r range proto port <<< "$fields"
echo "ufw allow from ${range} proto ${proto} to any port ${port}"
done
}
set_connections
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment