From 3be5f74df08483a95d0844b728031ddc1bdf81f1 Mon Sep 17 00:00:00 2001 From: Pingfan Liu Date: Fri, 13 Mar 2020 11:05:49 +0800 Subject: [PATCH] dracut-module-setup.sh: improve get_alias() In /etc/hosts, the alias name can come at the 2nd column, regardless of the recommendation. E.g. the following format is valid although not recommended cat /etc/hosts 127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 ::1 localhost localhost.localdomain localhost6 localhost6.localdomain6 192.168.22.21 fastvm-rhel-7-6-21 fastvm-rhel-7-6-21.localdomain 192.168.22.22 fastvm-rhel-7-6-22 fastvm-rhel-7-6-22.localdomain 192.168.22.21 node1_hb 192.168.22.22 node2_hb So filtering out both 2nd and 3rd column for matching. Signed-off-by: Pingfan Liu Acked-by: Kairui Song --- dracut-module-setup.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index 7a2c7b4..2c8d714 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -683,7 +683,8 @@ get_alias() { ips=$(hostname -I) for ip in $ips do - entries=$(grep $ip /etc/hosts | awk '{ $1=$2=""; print $0 }') + # in /etc/hosts, alias can come at the 2nd column + entries=$(grep $ip /etc/hosts | awk '{ $1=""; print $0 }') if [ $? -eq 0 ]; then alias_set="$alias_set $entries" fi