From 2ba32c6ccf6ad5e705a28def925d9de6699fdec1 Mon Sep 17 00:00:00 2001 From: Minfei Huang Date: Thu, 23 Jul 2015 18:29:25 +0800 Subject: [PATCH] dracut-module-setup: Prefer ipv4 address as the hostname address Kdump will parse the hostname to get the ip address, if hostname is specfied in /etc/kdump.conf. We will get the ip address(ipv4 or ipv6, according to the DNS server) by using "getent hosts". For now, it is more reasonable that we shall get all of the ip address(including ipv4 and ipv6 address) which point to the hostname by using "getent ahosts". And we will prefer to use the ipv4 address, if both ipv4 and ipv6 address work. The reason why we choose the ipv4 as preferred address is to solve the issue kdump will fail to connect the hostname machine(parsed as ipv6 address), due to the DNS server is ipv4 address in 2nd kernel. Signed-off-by: Minfei Huang Acked-by: Dave Young --- dracut-module-setup.sh | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/dracut-module-setup.sh b/dracut-module-setup.sh index b792a2d..55261a1 100755 --- a/dracut-module-setup.sh +++ b/dracut-module-setup.sh @@ -306,12 +306,18 @@ get_ip_route_field() #$1: config values of net line in kdump.conf #$2: srcaddr of network device kdump_install_net() { - local _server _netdev _srcaddr _route + local _server _netdev _srcaddr _route _serv_tmp local config_val="$1" _server=$(get_remote_host $config_val) - is_hostname $_server && _server=`getent hosts $_server | head -n 1 | cut -d' ' -f1` + if is_hostname $_server; then + _serv_tmp=`getent ahosts $_server | grep -v : | head -n 1` + if [ -z "$_serv_tmp" ]; then + _serv_tmp=`getent ahosts $_server | head -n 1` + fi + _server=`echo $_serv_tmp | cut -d' ' -f1` + fi _route=`/sbin/ip -o route get to $_server 2>&1` [ $? != 0 ] && echo "Bad kdump location: $config_val" && exit 1