From c0cf64a5c0d16957ccf006e974ca38da4032c209 Mon Sep 17 00:00:00 2001 From: Richard Lau Date: Wed, 6 Nov 2024 16:04:17 +0000 Subject: [PATCH] ansible: add getaddrinfo config to prefer IPv4 On some hosts, IPv6 connectivity is limited and may result in DNS lookups returning IPv6 addresses that the host is unable to reach. Add a config file for glibc's getaddrinfo function that configures IPv4 addresses to have higher precedence for such hosts. --- ansible/roles/bootstrap/files/gai.conf | 12 ++++++++++++ .../roles/bootstrap/tasks/partials/rhel8-s390x.yml | 8 ++++++++ 2 files changed, 20 insertions(+) create mode 100644 ansible/roles/bootstrap/files/gai.conf diff --git a/ansible/roles/bootstrap/files/gai.conf b/ansible/roles/bootstrap/files/gai.conf new file mode 100644 index 000000000..fac6ddeff --- /dev/null +++ b/ansible/roles/bootstrap/files/gai.conf @@ -0,0 +1,12 @@ +# getaddrinfo(3) configuration file +# Settings to prefer IPv4 addresses for hosts with limited IPv6 connectivity. + +# Below settings are documented defaults but need to be duplicated since +# setting any precedence line means the default table is not used. +precedence ::1/128 50 +precedence ::/0 40 +precedence 2002::/16 30 +precedence ::/96 20 + +# This line is changed from the default to give IPv4 higher precedence. +precedence ::ffff:0:0/96 100 diff --git a/ansible/roles/bootstrap/tasks/partials/rhel8-s390x.yml b/ansible/roles/bootstrap/tasks/partials/rhel8-s390x.yml index e856de8d3..ae11fc212 100644 --- a/ansible/roles/bootstrap/tasks/partials/rhel8-s390x.yml +++ b/ansible/roles/bootstrap/tasks/partials/rhel8-s390x.yml @@ -48,3 +48,11 @@ insertafter: ":OUTPUT ACCEPT.*]" line: "-A INPUT -s 127.0.0.2/32 -d 127.0.0.1/32 -j ACCEPT" notify: restart iptables + +- name: Configure getaddrinfo to prefer IPv4 addresses + ansible.builtin.copy: + dest: /etc/gai.conf + group: root + mode: 0644 + owner: root + src: "gai.conf"