An unexpected hostname and how I checked before I panicked

A post from the future!

You may have noticed this post is dated in the future. I do this to keep myself on a regular writing schedule and to mask the flurries of activity I'm prone to.

Please feel free to read and share as you normally would.

The other day I opened my terminal and noticed I was mike@Clearpeak. Considering this was my work computer (and Liquid Light is nothing like Clearpeak) alarm bells started ringing.

Before I engaged code-red protocol and suspected a hack, I thought I would check as to where it was coming from.

Finding the source

My first port-of-call was to ask Claude how I can check where it was coming from. It gave me 4 commands to verify the identity

scutil --get HostName
scutil --get LocalHostName
scutil --get ComputerName
hostname

Note: scutil is a native mac command line tool

Mine came back with:

  • scutil --get HostName: HostName: not set
  • scutil --get LocalHostName: Mikes-MacBook-Pro
  • scutil --get ComputerName: Mike's MacBook Pro
  • hostname: Clearpeak.localdomain

With the local scutil --get HostName coming back not set, macOS goes off to the network to try and get a name from the router. If the router has seen a phone, printer or something else on that IP address, it may well remember the name when it's reassigned.

The fix

To resolve it, you can leave it or set the local hostname yourself. This will stop the computer asking the network for a name.

sudo scutil --set HostName Mikes-MacBook-Pro

Open a new terminal and your prompt will stay put, whatever network you're on.

CLI

View this post on Github

You might also enjoy…

Mike Street

Written by Mike Street

Mike is a CTO and Lead Developer from Brighton, UK. He spends his time writing, cycling and coding. You can find Mike on Mastodon.