'hostname -A' can not get the alias, meanwhile 'hostname -a' is deprecated. So we should do it by ourselves.
The parsing is based on the format of /etc/hosts, i.e. IP_address canonical_hostname [aliases...]
Signed-off-by: Pingfan Liu piliu@redhat.com --- dracut-module-setup.sh | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 3fa696d..6745cff 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -689,12 +689,31 @@ kdump_check_iscsi_targets () { } }
+# hostname -a is deprecated, do it by ourself +get_alias() { + local ips + local entry + local alias_set + + ips=$(hostname -I) + for ip in $ips + do + entries=$(grep $ip /etc/hosts | awk '{ $1=$2=""; print $0 }') + if [ $? -eq 0 ]; then + alias_set="$alias_set $entries" + fi + done + + echo $alias_set +} + is_localhost() { local hostnames=$(hostname -A) local shortnames=$(hostname -A -s) + local aliasname=$(get_alias) local nodename=$1
- hostnames="$hostnames $shortnames" + hostnames="$hostnames $shortnames $aliasname"
for name in ${hostnames}; do if [ "$name" == "$nodename" ]; then