-
Notifications
You must be signed in to change notification settings - Fork 0
/
set_hostname_batch.sh
36 lines (29 loc) · 968 Bytes
/
set_hostname_batch.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
#Douglas Oliveira
# Lista de DNS para verificar
TOTAL_DNS_LIST=14
DNS_LIST=()
for i in $(seq 1 $TOTAL_DNS_LIST); do
DNS_LIST+=("dominio-a$i.com.br")
DNS_LIST+=("doninio-b$i.srv.br")
DNS_LIST+=("dominio-c$i.com")
done
# Obtém o endereço IP externo do servidor atual
external_ip=$(curl -s ifconfig.me)
# Função para obter o IP de um DNS
get_ip_from_dns() {
nslookup $1 | grep 'Address:' | tail -n1 | awk '{print $2}'
}
# Loop através da lista de DNS
for dns in "${DNS_LIST[@]}"; do
dns_ip=$(get_ip_from_dns "$dns")
# Compara o IP do DNS com o IP externo do servidor
if [ "$dns_ip" == "$external_ip" ]; then
# Configura o hostname removendo a parte '.ip.tv'
new_hostname=${dns%.ip.tv}
# Configura o hostname do servidor (requer privilégios de superusuário)
sudo hostnamectl set-hostname "$new_hostname"
echo "Hostname configurado para: $new_hostname"
break
fi
done