My Terminal Prompt is showing number rather than the System name

I am not very new to Mac and earlier my terminal used to show <username>@Mackbook-Pro. But now it is showing <username>@<some number>. I am using a Macbook Pro 16 (Intel) and using zsh shell. This is not something which is breaking anything but I would love to know what exactly changed.

MacBook Pro 16″, macOS 12.5

Posted on Jul 22, 2022 8:36 AM

Reply
Question marked as Top-ranking reply

Posted on Jul 22, 2022 9:44 AM

You are likely using a VPN connection whose remote DNS server assigns a dynamic host name to you, in this case something numeric. Although I don't use VPN very often, I used the following in my ~/.zshrc startup file to always show my local hostname.


MyHost="$(networksetup -getcomputername)"
PS1="%n@${MyHost} %% "
viking@odin %


There are other Zsh prompt expansion options too.

4 replies
Question marked as Top-ranking reply

Jul 22, 2022 9:44 AM in response to codesteller

You are likely using a VPN connection whose remote DNS server assigns a dynamic host name to you, in this case something numeric. Although I don't use VPN very often, I used the following in my ~/.zshrc startup file to always show my local hostname.


MyHost="$(networksetup -getcomputername)"
PS1="%n@${MyHost} %% "
viking@odin %


There are other Zsh prompt expansion options too.

Jul 23, 2022 8:24 AM in response to codesteller

please give us your PS1 prompt string


echo "$PS1" | cat -vte


This will tell us what your Mac thinks it. From that we will know what to look at


For example, with zsh as the shell, here is what my prompt string looks like

echo "$PS1" | cat -vte
%n@%m %1~ %# $


The trailing $ is from cat -vte indicating where the end of the line is located at. The $ is not part of the prompt.

%n is suppose to be your username, which should be the same as $USERNAME

%m is suppose to be the hostname up to the first period.

%1~ is suppose to show the name of your current working directory (just the name and not the full path).

%# will translate to % if you are a normal user, and # if you are running as root.


Knowing what your PS1 value says will go a long way to figuring out what is happening.


NOTE: Often the hostname is obtained by doing a reverse DNS lookup starting with your IP address and asking the DNS server what the hostname is. Often times the DNS server (typically your home router, acting as a local DNS server and a cache for the ISP's DNS server) will not have a translation from IP address to name, so macOS DNS lookup will return the System Preferences -> Sharing -> Computer Name. But if the DNS server does return a value, then that value is displayed.


I've seen this happen when a Windows computer registers its host name with the home router for DNS lookups. Because most home IP addresses are assigned by DHCP, when DHCP lease period expires the IP address to the Windows system maybe given to another computer, in this case your Mac, and when your shell does a reverse DNS lookup it gets the information stored by the Window system.


Typically this happens when systems are disconnected from the home system so that they are not still using the IP address (laptops come and leave the house).


Also it is not just Windows that can register a DNS name. Other devices can do this. I was just using Windows as a common example.

Jul 22, 2022 9:53 PM in response to VikingOSX

Thanks @VikingOSX.

I am not on any VPN. I also reset my Mac and reinstalled the OS. It still remains the same.

But you are correct, it has to do with something with the network. When I change from one network to another, this number keep on changing.

I changed my zshrc file as you suggested and it helped, but I still dont understand how to fix it at the source.

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.

My Terminal Prompt is showing number rather than the System name

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