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 <mhuang@redhat.com>
Acked-by: Dave Young <dyoung@redhat.com>
This commit is contained in:
Minfei Huang 2015-07-23 18:29:25 +08:00 committed by Dave Young
parent c994a80698
commit 2ba32c6ccf
1 changed files with 8 additions and 2 deletions

View File

@ -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