Hostname issue

I have a weird issue that has me stumped trying to resolve a hostname of an instance. My app is running in 3 regions AMS, LAX, and SIN. When running: > hostname -i inside each instance I get following results:

  • ams: 1.81.126.12
  • lax: fdaa:x:xxxx:xxx:xxx:x:xxxx:x
  • sin: fdaa:x:xxxx:xxx:xxx:x:xxxx:x

I would expect ams to return fdaa:x:xxxx:xxx:xxx:x:xxxx:x

Any ideas why this is not the case?

1 Like

This is a good bug.

In short, it’s obscure hostname behavior. The instance ID for that VM is 22117900, which is what we set as the hostname. Since that’s all digits, the hostname -i command assumes that’s an exact IP address, and simply converts it to an IP instead of doing the normal lookup. If you plug 22117900 into this tool, you’ll see what it’s doing: Decimal to IP Converter - Convert Integer to IP - Online - Browserling Web Developer Tools

This is a more reliable way to get the private IP, assuming that’s what you’re after.

/# grep fly-local-6pn /etc/hosts | cut -f 1
fdaa:x:xxxx:xxx:xxx:x:xxxx:x

Weirdly, hostname -I behaves as you’d expect:

/# hostname -I
172.19.0.90 172.19.0.91 fdaa:x:xxxx:xxx:xxx:x:xxxx:x
4 Likes

Thanks Kurt! That solves it.