2024-08-03 14:51:11 -07:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
sshd_dns () {
|
2024-08-21 18:48:51 -07:00
|
|
|
|
|
|
|
local ip
|
2024-08-03 14:51:11 -07:00
|
|
|
local dir
|
|
|
|
local dnsconf
|
|
|
|
local conf
|
2024-08-21 18:48:51 -07:00
|
|
|
|
|
|
|
_getip () {
|
|
|
|
[[ ! $1 ]] && return 1
|
2024-08-22 10:50:09 -07:00
|
|
|
if ip=$(getent ahostsv4 $1); then
|
2024-08-22 11:23:09 -07:00
|
|
|
echo $ip | grep STREAM | awk '{ print $1 ; exit }'
|
2024-08-21 18:48:51 -07:00
|
|
|
else
|
|
|
|
return 2
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-08-03 14:51:11 -07:00
|
|
|
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
|
2024-08-21 18:48:51 -07:00
|
|
|
echo host to lookup $host,
|
|
|
|
if ip=$(_getip $host); then
|
|
|
|
echo substituting $(dig +short $host)
|
|
|
|
sudo sed -i 's/[Dd][Nn][Ss]:'$host'/'$ip'/g' $conf
|
|
|
|
else
|
|
|
|
echo unable to find ip address for $host
|
|
|
|
echo fatal: removing $conf, exiting,
|
|
|
|
sudo rm -f $conf
|
|
|
|
popd 1>/dev/null || return 2
|
|
|
|
return 2
|
|
|
|
fi
|
2024-08-03 14:51:11 -07:00
|
|
|
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
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|