How to make terminal to follow local hostname from settings?

I do not know what happened, but before I had I kind of sync between macOS settings for local hostname and the host name I see in the terminal app. For instance if I change host name in settings it automatically updates terminal. At some point it stopped to work and I do not know how to bring this feature back.


MacBook Air 15″

Posted on Mar 1, 2024 10:08 AM

Reply
Question marked as Top-ranking reply

Posted on Mar 3, 2024 5:47 AM

One thing I do in my Zsh startup file (~/.zshrc) is ensure that my prompt is always my local hostname, and not a supplanted reverse DNS host name provided by a VPN. My free University VPN service for alumni was recently elimninated as an Alumni service, so I am not now using VPN.


# don't want VPN DNS changing my hostname
MyHost="$(networksetup -getcomputername)"
PS1="${MyHost}: %~ %# "


and my Zsh shell prompt becomes:

odin: ~ %



This would work in the Bash shell's ~/.bash_profile or ~/.bashrc as well with adjustments for Bash PS1 syntax.

MyHost="$(networksetup -getcomputername)"
export PS1="$MyHost: \w $ "



19 replies
Question marked as Top-ranking reply

Mar 3, 2024 5:47 AM in response to Evgenii.Sergeev

One thing I do in my Zsh startup file (~/.zshrc) is ensure that my prompt is always my local hostname, and not a supplanted reverse DNS host name provided by a VPN. My free University VPN service for alumni was recently elimninated as an Alumni service, so I am not now using VPN.


# don't want VPN DNS changing my hostname
MyHost="$(networksetup -getcomputername)"
PS1="${MyHost}: %~ %# "


and my Zsh shell prompt becomes:

odin: ~ %



This would work in the Bash shell's ~/.bash_profile or ~/.bashrc as well with adjustments for Bash PS1 syntax.

MyHost="$(networksetup -getcomputername)"
export PS1="$MyHost: \w $ "



Apr 23, 2024 7:39 AM in response to Evgenii.Sergeev

This can be a difficult problem. There are so many different things that can cause a problem accessing a local device as a server. So if what I'm an out to say doesn't work, then please start your own thread for your own problem. Otherwise, these kinds of things get extremely confusing.


One possible cause is a new feature/bug in macOS Ventura and later. In System Settings, there are two different places to set your computer name. The system will allow you to set two different name, which I strongly discourage. Unfortunately, the comparable "Sharing" setting that people would have used in the past is not the setting that people should use in Ventura+.


In Ventura, go to Settings > General > About. Under the picture of your computer and the model name, there is a field for the computer name. You can double-click on this name to change it. This is the setting to change.


Then, you go to Settings > General > Sharing. At the bottom of the list you should see "Local hostname" which should be the same name you specified above with ".local" appended to the end. This is the old setting that you shouldn't use anymore.



Mar 1, 2024 10:49 AM in response to Evgenii.Sergeev

Evgenii.Sergeev wrote:

I do not know what happened, but before I had I kind of sync between macOS settings for local hostname and the host name I see in the terminal app. For instance if I change host name in settings it automatically updates terminal. At some point it stopped to work and I do not know how to bring this feature back.


https://discussions.apple.com/content/attachment/5cb7ae3f-9322-4364-981f-992691c7ea3b


You can change the way your mac is seen on your Network >System Settings>Sharing>Edit






Restart and see if your Terminal is what you want...



You can further customize the Terminal prompt if necessary...


many references on-line:


https://scriptingosx.com/2019/07/moving-to-zsh-06-customizing-the-zsh-prompt/


https://www.makeuseof.com/customize-zsh-prompt-macos-terminal/






Apr 23, 2024 7:50 AM in response to OogieM

OogieM wrote:

I have the same problem, did a migrate from an old system to a new one, have verified proper host name in the sharing section and restarted terminal and I can't get it to work either. No antivirus or system optimization stuff here either


What network testing have you done?


dig, hostname, dns-sd, and scutil would be the typical commands used for researching host name translations. These commands are your tools for researching these cases.


For instance, these are the three common host names:

scutil —-get ComputerName # the ”friendly” name
scutil —-get LocalHostName # the Bonjour / mDNS / ZeroConf host name
scutil —-get HostName # should be the same as what hostname command returns


(I’d use scutil in preference to the networksetup command as described above, but that’s local preference.)


There are quite possibly multiple host names and multiple IP addresses in use for any particular host, too.

Mar 3, 2024 4:15 AM in response to Evgenii.Sergeev

Not to say this isn't a bug, but I've not seen anyone else report this problem so it 'seems' like it might not be a system wide bug. You could submit this as either a bug report or feature request here:


Feedback - macOS - Apple


Lastly, are you running any 3rd party system optimizing software or anti-virus? Often times those will cause random system problems.

Apr 23, 2024 8:48 AM in response to OogieM

OogieM wrote:

On both the new Ventura Settings General About I have the correct name. And the correct name is showing in Settings General Sharing but it's STILL not showing up properly in the terminal app.

You didn't even give me 10 minutes. Not even 10 minutes.


As I said, there are many, many different issues that could cause this problem. If you are complaining about something not showing up properly in the Terminal app, that's an entirely different category of problems altogether.


But I'm feeling generous this morning. Even though you didn't even give me 10 minutes - just seven minutes - I'll still tell you the cause of the problem. Terminal you say? There's probably a 90% chance that your Terminal problem is caused by Homebrew. Any time someone complains about some really, really basic Terminal operation not working properly, the cause is always Homebrew. So use your remaining 3 minutes to contact the good people running Homebrew technical support.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to make terminal to follow local hostname from settings?

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.