101

I have a local network at home. This network contains 5 laptops. One of the laptops is a Mac with macOS 10.8 on it. The other has a Linux installed, all others run Windows.

When trying to open my router and check "Connected devices", under the IP address of this Mac I see following:

Host Name - some IPV6 address

What I'd rather prefer to see is some meaningful name so that I can use that in the /etc/hosts file in Linux laptop. And also I'd like to check the computer name so that the /etc/hosts line was proper.

5 Answers 5

190

Setting the Mac hostname or computer name from the terminal

  1. Open a terminal.
  2. Type the following command to change the primary hostname of your Mac:
    This is your fully qualified hostname, for example myMac.domain.com

    sudo scutil --set HostName <new host name>
    
  3. Type the following command to change the Bonjour hostname of your Mac:
    This is the name usable on the local network, for example myMac.local.

    sudo scutil --set LocalHostName <new host name>
    
  4. If you also want to change the computer name, type the following command:
    This is the user-friendly computer name you see in Finder, for example myMac.

    sudo scutil --set ComputerName <new name>
    
  5. Flush the DNS cache by typing:

    dscacheutil -flushcache
    
  6. Restart your Mac.

6
  • after doing this I still see the IPv6 address in the router. Any idea? And what would be the line in the /etc/hosts file on Linux if I set the hostnames to MyMac?
    – Igor
    Jun 24, 2017 at 16:37
  • 2
    Always attribute quoted content with an appropriate source link and use quote formatting for quoted content. I've added a potential source link but please edit if this is incorrect.
    – grg
    Jun 24, 2017 at 22:10
  • 4
    scutil --get HostName shows the current value of HostName. Jan 26, 2021 at 21:56
  • Should we done all steps?
    – alper
    Jun 28, 2021 at 9:49
  • 2
    sudo hostname <new-host-name> also sets hostname that can be used from terminal. It would be nice to see what is the difference and relations between these internal hostnames in MacOS and standard *nix hostnames (as @scrpy asked). Additionally, System Preferences -> Sharing is another place to change some hostname, so again, what is the diff to previous hostname settings? Jun 30, 2022 at 12:16
22

You can set the computer name in System Preferences → Sharing.

4
  • @ggarside, I still see an IPv6 as a computer name inside the router. It is a Comcast modem/router one. Any idea?
    – Igor
    Jun 25, 2017 at 1:25
  • 7
    this doesn't seem to change the hostname returned by the hostname command in terminal
    – Woodstock
    Dec 12, 2020 at 13:53
  • 1
    @Woodstock it does seem to be linked somehow, but does not get updated immediately
    – Magnus
    Jan 6, 2021 at 1:25
  • @grg Do you know what this difference is between this and the NetBIOS Name in the Network -> Advanced section of Preferences? Jul 9, 2021 at 15:12
5

You need to set the hostname in two places

  1. System Settings -> General -> About -> Name
  2. In a terminal, sudo scutil --set HostName <new host name>

You can verify the hostname is correctly updated by doing:

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

Then, dscacheutil -flushcache and restart your mac.

1
  • 1
    Thanks, works for me on Sonoma 14.0.
    – gsl
    Oct 26, 2023 at 15:21
1

On macOS 13, computer name can be changed from:

System Settings -> General -> About -> Name

This changes the computer name displayed in Terminal, Sharing, Finder, etc. No system restart required.

4
  • Unfortunately does not work. Used to work in the past, now I see "mac.local" and does not propagate the change.¨
    – lzap
    May 19, 2023 at 13:40
  • @lzap For the benefit of future readers of this question, in which macOS version did this not work? It worked fine for me on macOS 13. May 22, 2023 at 2:20
  • I am on 13.4. The path via Settings did not work for me, "scutil" utility did. For the record, I am interested in changing the UNIX hostname variable, not the thing that is displayed somewhere in Apple UI.
    – lzap
    May 28, 2023 at 12:52
  • This approach works, but you may need a system restart to see the effect.
    – sherb
    Jun 17, 2023 at 16:04
-1

On your Mac, choose Apple menu > System Settings, click General in the sidebar, then click Sharing on the right. ... Click Edit in the “Local hostname” section at the bottom of the window, then enter a new local hostname. If needed, turn on the “Use dynamic global hostname” option.

1
  • Was it ChatGPT or Bing Chat that got your this answer which was sourced from here?This answer also doesn't offer anything new that hasn't already been posted by others.
    – Allan
    Jun 28, 2023 at 3:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .