Menu

#26 hostname -i on IPv4/IPv6 dual stack systems

BETA-1.65-UPSTREAM
accepted
nobody
5
2021-01-06
2015-04-15
Terra
No

Greetings,

/bin/hostname -i on an IPv4/IPv6 dual stack host will return IPv6 by default if configured...

However there are scripts we have that use the following:
server_ip4=$(/bin/hostname -i)
exec tcpserver .... ${server_ip4} ....

When we turned up our IPv6 allocation, those scripts broke as they are for IPv4 services and the return was an IPv6 address...

I would like to propose the attached patch for the addition of '-4' and '-6' switch options to control which address family to return when using the '-i' option...
e.g. -i[46]

FWIW, the server is based on Gentoo...
sys-apps/net-tools-1.60_p20130513023548

Thank you for your consideration!

--
FutureQuest, Inc.
Terra Nova
http://www.FutureQuest.net

1 Attachments

Discussion

  • Terra

    Terra - 2015-04-15

    I am also including a 2nd patch, which is the one we use internally as it defaults to an IPv4 result for backwards compatibility with existing scripts using '/bin/hostname -i'... We did not want to edit a ton of scripts to explicitly state '-4' on the dual stack servers... Anyone reading this with the same dilemma now has a choice of which patch to use for their needs...

    The first patch was more or less to follow hostname's existing behavior as-is, where IPv6 result was the default... In most people's cases though, IPv4 came first and existing scripts were written with that assumption with IPv6 being bolted on later...

    --
    Terra

     
  • Mike Frysinger

    Mike Frysinger - 2021-01-04

    i agree we need -4/-6 options. i think the default should be left to the system though.

    we can't support that with the current gethostbyname/gethostbyname2 APIs. we need to switch to getaddrinfo so we can provide hints.

     
  • Mike Frysinger

    Mike Frysinger - 2021-01-06
    • status: open --> accepted
     

Log in to post a comment.