mirror of
https://github.com/buildplan/du_setup.git
synced 2025-12-17 17:55:35 +00:00
set new hostname in /etc/hosts
This commit is contained in:
parent
5a917cb9e9
commit
b40b1793e4
18
du_setup.sh
18
du_setup.sh
@ -3172,15 +3172,23 @@ configure_system() {
|
|||||||
if [[ $(hostnamectl --static) != "$SERVER_NAME" ]]; then
|
if [[ $(hostnamectl --static) != "$SERVER_NAME" ]]; then
|
||||||
hostnamectl set-hostname "$SERVER_NAME"
|
hostnamectl set-hostname "$SERVER_NAME"
|
||||||
hostnamectl set-hostname "$PRETTY_NAME" --pretty
|
hostnamectl set-hostname "$PRETTY_NAME" --pretty
|
||||||
if grep -q "^127.0.1.1" /etc/hosts; then
|
|
||||||
sed -i "s/^127.0.1.1.*/127.0.1.1\t$SERVER_NAME/" /etc/hosts
|
|
||||||
else
|
|
||||||
echo "127.0.1.1 $SERVER_NAME" >> /etc/hosts
|
|
||||||
fi
|
|
||||||
print_success "Hostname configured: $SERVER_NAME"
|
print_success "Hostname configured: $SERVER_NAME"
|
||||||
else
|
else
|
||||||
print_info "Hostname already set to $SERVER_NAME."
|
print_info "Hostname already set to $SERVER_NAME."
|
||||||
fi
|
fi
|
||||||
|
if grep -q "^127.0.1.1" /etc/hosts; then
|
||||||
|
# Check if the line matches the chosen server name; if not, update it
|
||||||
|
if ! grep -q "^127.0.1.1.*$SERVER_NAME" /etc/hosts; then
|
||||||
|
sed -i "s/^127.0.1.1.*/127.0.1.1\t$SERVER_NAME/" /etc/hosts
|
||||||
|
print_info "Updated /etc/hosts to resolve $SERVER_NAME."
|
||||||
|
else
|
||||||
|
print_info "/etc/hosts already resolves $SERVER_NAME correctly."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "127.0.1.1 $SERVER_NAME" >> /etc/hosts
|
||||||
|
print_info "Added entry to /etc/hosts for $SERVER_NAME."
|
||||||
|
fi
|
||||||
|
|
||||||
log "System configuration completed."
|
log "System configuration completed."
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user