Glibc Tips

From trapsink.com
Jump to: navigation, search


IPv4 Preferred

Glibc provides the capability per RFC 3484 to allow the sysadmin to specify the sort order of returned calls to getaddrinfo() via the /etc/gai.conf file. This is a handy way to have IPv4 preferred over IPv6 returned addresses:

precedence  ::ffff:0:0/96  100

The presence of a single precedence line in the configuration file causes the default table to not be used. The /etc/gai.conf is typically either empty or missing; if configured in the file the default table would look like:

/etc/gai.conf (RFC defaults)
label       ::1/128        0
label       ::/0           1
label       2002::/16      2
label       ::/96          3
label       ::ffff:0:0/96  4
precedence  ::1/128        50
precedence  ::/0           40
precedence  2002::/16      30
precedence  ::/96          20
precedence  ::ffff:0:0/96  10

When adding the IPv4 precedence, change the last line to indicate 100 (larger number == higher precedence):

/etc/gai.conf (IPv4 preferred)
label       ::1/128        0
label       ::/0           1
label       2002::/16      2
label       ::/96          3
label       ::ffff:0:0/96  4
precedence  ::1/128        50
precedence  ::/0           40
precedence  2002::/16      30
precedence  ::/96          20
precedence  ::ffff:0:0/96  100