add new module sshd-dns which can process sshd conf files substituing IPs for hostnames

master
David Kebler 2024-08-03 14:51:11 -07:00
parent b2efa57439
commit 7f15b61f23
1 changed files with 30 additions and 0 deletions

30
modules/sshd-dns.mod Normal file
View File

@ -0,0 +1,30 @@
#!/bin/bash
sshd_dns () {
local dir
local dnsconf
local conf
dir=${1:-"/etc/ssh/sshd_config.d"}
pushd "$dir" 1>/dev/null || return;
for dnsconf in *.conf.dns; do
[[ -f "$dnsconf" ]] || break
conf=$(basename $dnsconf .dns)
echo "----- processing sshd file $dnsconf to $conf ----"
sudo cp $dnsconf $conf
cat $conf
echo -e "\n------------"
for host in $(sed -e 's/[ ,]/\n/g' $conf | sed -n 's/[Dd][Nn][Ss]://p'); do
echo found host $host, substituting $(dig +short $host)
sudo sed -i 's/[Dd][Nn][Ss]:'$host'/'$(dig +short $host)'/g' $conf
done
echo "----- created sshd conf file $conf ----"
cat $conf
echo -e "\n------------"
done
echo restart ssh service daemon to enable these changes
popd 1>/dev/null || return
}