How To Choose a Specific IP Address From a DNS Result?

Photo by Jordan Harrison on Unsplash
74.6.231.20, 74.6.143.26, 74.6.143.25, 98.137.11.164, 98.137.11.163, 74.6.231.21
scopev4 ::ffff:98.137.11.0/120 3
scopev4 ::ffff:74.6.231.0/120 2
scopev4 ::ffff:74.6.143.0/120 1

Second column is the IP subnet, third column is the priority. The lower number has high priority.

getaddrinfo will decide which IP address/subnet is going to be used. It is going to be calculated through the 3rd column.

1) Call getaddrinfo
2) Get IP address of yahoo.com
3) Check if there is a rule for these IP addresses in the gai.conf file
4) Get the one that has high priority. If an IP address of yahoo.com is not listed in gai.conf and getaddrinfo would return that IP.
root@adil:~# systemd-resolve --flush-caches && ping yahoo.com -c1PING yahoo.com (74.6.143.25) 56(84) bytes of data.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store