I'm writing some bash on a linux server, and there's one concept I'm trying to get my head around.
Given a domain name, can I tell if it's pointing to the current server? Bearing in mind that the server may have multiple ip addresses.
My current plan is to loop all ip addresses from the 'ip addr' command, and see if the 'host example.com' returns one of them.
Any better ideas?
You don't need to loop through the ip addresses you can just use
ip addr
which lists all the configured addresses for the system and grep for the address thathost example.com
returns, sowould return 0 in $? if the ip address returned by host is matched. You also need to check for IPv6 addresses so as above
will return 0 to $? if the IPv6 address for example.com is matched.