-
All replies
-
Helpful answers
-
Dec 8, 2013 5:28 AM in response to Pinstrypsoldierby BobHarris,sarah's iphone:~ Dan$
Is not your home directory. It is
Hostnane : Current-directory Short-username
~ is a standard Unix abbreviation for your home directory.
"sarah's iphone" is what the bash shell (the program issuing the prompt) thinks your hostname is.
And bash thinks this because it took your IP address, did a reverse DNS lookup, and the DNS server returned "sarah's iphone", so that is what bash put in your prompt.
Chances are your home router is acting as your local DNS server, and cached your girl friend's iPhone name from a previous time when the router's DHCP serve assigned her the IP address that the DHCP server has now given you.
You could try resetting/power cycling you router to get its DNS server to forget the name "sarah's iphone".
Or you could give your Mac a DHCP ID via system preferences -> Network -> Advanced -> TCP/IP -> DHCP ID, and then configure your home router to always give you the same IP address so that Sarah's iPhone will not get it and store her iPhone hostname in the local DNS server.
Or you could explicitly set your prompt via the bash PS1 variable in the bash shell initialization file.
-
Dec 8, 2013 8:55 AM in response to Pinstrypsoldierby MrHoffman,Some more details on what BobHarris has referenced here; commands and examples and related.
-
Aug 31, 2016 1:23 AM in response to BobHarrisby eli128,thanks for this. glad that (most likely?) I have not been hacked. But I can't seem to make these strange hostnames go away. I reset my router, and it stayed the same. I added a DHCP ID to my IP address, and THEN a NEW strange hostname appeared in terminal. First time it was someone's iphone, now it's someone's android. We had some guests recently so I suppose they could be the phones they were using here. Can't seem to purge them.
-
Aug 31, 2016 6:02 AM in response to eli128by BobHarris,Take the easy solution, just set your own prompt.
Add the following to your .bash_profile
PS1='$(networksetup -getcomputername):\W \u\$ '
Which will stop asking your DNS server for your name based on your IP address and will always use the name you put in System Preferences -> Sharing -> Computer Name
The bash shell running in a Terminal session will accept 1 of 3 different initialization scripts
.bash_profile
.bash_login
.profile
It will use the 1 one found in the above order and then stop looking. If you already have one of the other named files, then put the PS1 prompt setting in that one.
NOTE: I change my PS1 prompt all the time, because at work the corporate DNS reverse lookup name is really ugly and something like "company_region-ip.n.n.address-building-floor" all spelled out so it is very long and my prompt takes up most of the screen. So if for no other reason I change it for that. But I also get very creative with my PS1 prompt as I will include colors for different machines I'm on, if I'm working in a development view (aka a project), time stamp, a custom directory path, and it includes an escape sequence that changes my Terminal title bar.
All I'm suggesting is to customize your PS1 to include your preferred computer name
If you do NOT want to change your PS1 prompt, then you need to resolve your DNS lookups. This can be your local DNS cache. Find the DNS cache flush commands for your version of OS X. Unfortunately Apple keeps changing the commands to do this depending on the version of OS X, and I have not kept up with it. You might find something on Mr. Hoffman's web site <http://labs.hoffmanlabs.com/node/1828> if you use the search box for "flush", or Google "your OS X version DNS cache flush"
Your router is also a place that can have a name associated with a DNS address. You have to hope that your ISP's DNS servers are not associating name with your local network IP addresses, or there is no way to reset/flush those (as in my case where it is the corporate DNS servers that give me my ugly names).
Another approach is to see if your home router will allow you to ALWAYS assocate your Mac with a specific IP address. Then your router will reserve that IP address and never give it to a guest in your home, and thus it will obtain a name pushed to it from a Windows or Android device. Some routers associate the nn:nn:nn:nn:nn:nn MAC (Media Access Control) address with the IP address. Other's such as Apple Airport Extreme can associate the IP address with a DHCP ID. I do this for other reason, but it should make sure you always get the same IP address and it is not loaned out to someone else in your home.