Both getent hosts and getent ahosts can potentially print both IPv4 and
IPv6 addresses, but they decide which address(es) to print differently.
hosts calls gethostbyname2 (the IPv6-supporting variant of
gethostbyname). The behavior is hard-coded: look up an IPv6 address, and
if none exists, look up an IPv4 address.
ahosts calls getaddrinfo. This function enumerates all protocols for a
given name, so it can return both IPv4 and IPv6 addresses in the same
call. What it returns is determined by the settings in /etc/gai.conf.
Because many applications are still struggling to cope with IPv6, most
distributions prefer IPv4 by default and only use IPv6 by explicit
request.
Signed-off-by: Minfei Huang <mhuang(a)redhat.com>
---
dracut-module-setup.sh | 3 +--
kdump-lib.sh | 13 +++++++++++++
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh
index 898229e..ca871fd 100755
--- a/dracut-module-setup.sh
+++ b/dracut-module-setup.sh
@@ -299,8 +299,7 @@ kdump_install_net() {
_server=`echo $config_val | sed 's/.*@//' | cut -d':' -f1`
- _need_dns=`echo $_server|grep "[a-zA-Z]"`
- [ -n "$_need_dns" ] && _server=`getent hosts $_server|cut -d'
' -f1`
+ is_hostname $_server && _server=`getent ahosts $_server | head -1 | cut
-d' ' -f1`
_netdev=`/sbin/ip route get to $_server 2>&1`
[ $? != 0 ] && echo "Bad kdump location: $config_val" &&
exit 1
diff --git a/kdump-lib.sh b/kdump-lib.sh
index 1b98a6f..d12b7c9 100755
--- a/kdump-lib.sh
+++ b/kdump-lib.sh
@@ -206,3 +206,16 @@ is_ipv6_address()
{
echo $1 | grep -q ":"
}
+
+# if the passed parameter is hostname/domain, it will be satisfied with
+# condition which it is without colon ":", and contains the [a-zA-Z]
+# $1: hostname/ip address
+is_hostname()
+{
+ local _hostname=`echo $1 | grep ":"`
+
+ if [ -n "$_hostname" ]; then
+ return 1
+ fi
+ echo $1 | grep -q "[a-zA-Z]"
+}
--
2.1.0