Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

vigu360

macrumors member
Original poster
Oct 21, 2009
90
0
Canada
When I ssh or do something with the Mac I need to enter <MacName>.local . Is there a way I can change it to just <MacName> (eg server.local --> server)? In unix we need to change /etc/hosts/ file what's the equivalent in Mac OS X?
 

jtara

macrumors 68020
Mar 23, 2009
2,008
536
However, a better way to do this is on your router, if it supports a hosts table. I use OpenWRT, which does.
 

Darth.Titan

macrumors 68030
Oct 31, 2007
2,906
753
Austin, TX
Yes OS X does have an /etc/hosts file, but it won't solve the OP's problem.

OP, in Terminal, try:
Code:
sudo scutil --set HostName your_new_hostname
 
  • Like
Reactions: Enjay314

jtara

macrumors 68020
Mar 23, 2009
2,008
536
Yes OS X does have an /etc/hosts file, but it won't solve the OP's problem.

Actually, upon re-reading, it's not clear exactly WHAT the OPs problem actually is. Can you be more specific?

FROM what computer TO what computer? And what is the OS on each computer?

.local isn't a part of your host name. It's the TLD used by ZeroConf. ZeroConf is a "distributed DNS" scheme that allows each machine in a local network to provide it's OWN "DNS". This is quite apart from the standard DNS system.

So, changing the host name on the destination computer isn't going to get rid of the .local, because .local ISN'T part of that host name.

Any local machine that has ZeroConf enabled and is set-up to advertise services can be accessed in the .local domain.

If you want to have a non-zeroconf local domain, you can do so, you just can't call it .local. For example, I use .lan. You either need a DNS server on your network or you can set this up in local /etc/hosts (or equivalent) files on each machine.

You can also have hosts that don't have a TLD, which I THINK is what the OP is asking for. Again, this requires that you have either a local DNS server (I have one on my router) or that you make entries in /etc/hosts on each computer.
 

Darth.Titan

macrumors 68030
Oct 31, 2007
2,906
753
Austin, TX
.local isn't a part of your host name.

I beg to differ. Typing "hostname" into the Terminal gets me Mac-Pro.local
It is indeed part of the host name.

However the rest of your post is spot on. The OP removing the .local from his hostname is not going to magically make his computer visible on the network by typing just the name. A DNS on the network would be the only thing to do aside from editing all the other /hosts files on the network.
 

Alrescha

macrumors 68020
Jan 1, 2008
2,156
317
If the OP doesn't want to have to type the 'local' part of the hostname, then I suggest that the solution is to add 'local' to the search domain in /etc/resolv.conf.

A.
 

jtara

macrumors 68020
Mar 23, 2009
2,008
536
I beg to differ. Typing "hostname" into the Terminal gets me Mac-Pro.local

That's because the "hostname" command tags-on the domain. But the domain is NOT part of the hostname.

To display the real hostname, use "hostname -s".

You can also see it in System Preferences, Sharing. It's at the top, "Computer Name".

If you hit edit, you will see the "local hostname", and can edit it. Here you will see the .local TLD, but note that you CANNOT remove .local - it's greyed out. This is because ".local" is NOT part of the computer name! They are just being helpful and showing you how to address the computer on your local subnet. i.e. you need to tag .local onto it.

Setting the host name without "local" using scutil as shown above will set the host name to....


... another drumroll....

exactly what it is currently!

It is indeed part of the host name.

No, it isn't. See above.

There does seem to be a lot of confusion about this. Lots of posts on the net asking for the opposite of this. That is, wanting to ADD .local to their hostname. Guess what happens if you try to add .local to your hostname? It gets removed. Otherwise it would be myhost.local.local

I'm assuming these people (wanting to ADD .local) are trying to access their computer from another computer that doesn't have a Bonjour/Zeroconf resolver installed, so doesn't know about the .local TLD. It's never correct to set a hostname with a .local suffix or to have a .local TLD in DNS. .local is reserved for Bonjour/Zeroconf.

---------- Post added at 03:32 PM ---------- Previous post was at 03:30 PM ----------

If the OP doesn't want to have to type the 'local' part of the hostname, then I suggest that the solution is to add 'local' to the search domain in /etc/resolv.conf.

A.

Yes, that's another way to do it.

To clarify, this would need to be done on every OTHER computer in the network. It's telling it "when I use a hostname without a suffix, automatically appened add ".local".
 

throttlemeister

macrumors 6502a
Mar 31, 2009
550
63
Netherlands
Let's try to clear up some of the semantic confusion.

A hostname is a name for a host, consisting of an alphanumeric string without dots.

A domain name is a name for a domain, consisting of an alphanumeric string that can contain dots. If it contains dots, it indicates one or more subdomains.

A hostname can be appended by a domain name, with the both of them separated by a dot to create a FQDN (fully qualified domain name).

If you see something like aaaa.bbbb.cccc.dddd.eeee, the hostname is only the aaaa part. The rest of it is the domain, with bbbb being a subdomain of cccc being a subdomain of 'real' domain dddd which is actually a subdomain of TLD eeee. The left most part before the first dot is ALWAYS the hostname, while the right most part after the last dot is ALWAYS the TLD.
 

throttlemeister

macrumors 6502a
Mar 31, 2009
550
63
Netherlands
This is simply not true. See: http://en.wikipedia.org/wiki/Hostname

or

http://www.ietf.org/rfc/rfc2396.txt

It *might* be true for some very specific cases (e.g. non-TCP/IP based networks), but it is not universally the case.

A.
No offense, but you are wrong in that you completely misunderstood what I said. On the internet a hostname may be defined by its FQDN (wikipedia) or its URL/URI/URN (rfc2369) in order to be unique, but on systems (aka physical machines, what we are discussing here) the hostname is the string before the first dot. There is a difference between systems and networks. While a host may be known as a.b.c on the internet, it is generally known as a.b on the local net, but on the system itself it is known as simply a. Knowing this helps to understand why the system behaves as it does, whereas using internet topology to describe a system does not.

We may think in internet terms all the time these days, but this way of drilling down from top level to a specific machine is exactly how TCP/IP networks are designed (just think how DNS works). UNIX systems in particular act and behave this way due to their origins.
 

throttlemeister

macrumors 6502a
Mar 31, 2009
550
63
Netherlands
Since there is apparently a lot more networking knowledge here than unix, let's get back to the original question that will hopefully clarify my point.

Open Terminal and type hostname.

On my system, this will say something like machine.domain.com (but with my real name and domain of course).

You might be thinking right now "see, that is what I said" but you are wrong. What you are seeing is actually Apple incorrectly setting the hostname. But the system is pretty smart, so when it calls for its hostname, it will strip everything behind the first dot. It is for all intends and purposes, irrelevant.

Now go back to Terminal and type domainname

It will come back empty.

Hmm.

While the system is pretty smart in stripping down the hostname entry to its true system hostname, it has no knowledge about the domain name because it isn't set. When it calls for the domain name of the system, it just gets back an empty string. And it will never ever figure out what additional information is set in the hostname, because it will never ever call the hostname to find the domain name. And when the system gets an empty domain name, it will add .local itself, simply because with a TCP/IP network you have to have a hostname + domain.

If we would go back into my example of machine.domain.com and you would go into Terminal and type hostname machine followed by domainname example.com the machine would correctly identify itself as host 'machine' within the domain 'example.com' with a FQDN machine.domain.com and never show itself as machine.local
 
Last edited:

Alrescha

macrumors 68020
Jan 1, 2008
2,156
317
Now go back to Terminal and type domainname

I'm sorry, you're just off in the weeds. The 'domainname' command has nothing whatsoever to do with DNS names. It's an old YellowPages/NIS throwback and isn't used for anything any more.*

The 'hostname' command is a call to gethostname() which is all about the DNS names, e.g. xxxx.xxxx.xxxx. A clue is that the documentation for gethostname() tells you that the maximum length is 255 characters, which also happens to be the maximum size of the DNS 'fqdn' as you like to call it.

You are right that in old Unix times before the Internet, hostnames were just the name of the host. But that was back in the days of UUCP (and before) and not relevant now.

The hostname command on modern Unix systems returns the full hostname. It has an option to remove the domain part of the hostname if you like.

Apple isn't setting anything 'incorrectly'.

A.

* Apologies to anyone still using yp/nis
 
Last edited:

Alrescha

macrumors 68020
Jan 1, 2008
2,156
317
To get back to the original question:

When I ssh or do something with the Mac I need to enter <MacName>.local . Is there a way I can change it to just <MacName> (eg server.local --> server)? In unix we need to change /etc/hosts/ file what's the equivalent in Mac OS X?

1) You can add all the hosts you want to talk to in your /etc/host file(s) on all your machines. Then you can type 'ssh host' and it will work the way you want.

2) You can add Host with Hostname definitions to your .ssh/config files(s), e.g.

Host macname
Hostname xx.xx.xx.xx (can be name or IP address)

Then you can say 'ssh host' (but this will only work for ssh).

3) You can have your DHCP server hand out a default search domain of 'local' (depending on your DHCP server). Normally you would have it hand out yourdomain.tld, but you don't appear to be using an internal DNS server.

If 'local' is your default search domain, then you can type 'ssh host' and it will work the way you want. You can also manually put 'search local' into your /etc/resolv.conf, but if you are using DHCP this probably gets re-written by OS X.

A.
 

canhaz

macrumors 6502
Jan 17, 2012
310
145
If the OP doesn't want to have to type the 'local' part of the hostname, then I suggest that the solution is to add 'local' to the search domain in /etc/resolv.conf.

To get back to the original question:
If 'local' is your default search domain, then you can type 'ssh host' and it will work the way you want. You can also manually put 'search local' into your /etc/resolv.conf, but if you are using DHCP this probably gets re-written by OS X.

This seemed like the nicest way. So I've added "search local" to resolv.conf manually. I've also done it via Network Preferences for my active ethernet connection under the DNS tab. After doing so I noticed my comcast assigned search domain went away and only "search local" remained in my /etc/resolv.conf

However I can't get it to work using "ssh machinename"

"ssh machinename.local" works fine though.

Any ideas? (Im on Yosemite)
 

jettca11

macrumors newbie
Mar 30, 2015
1
0
I've also done it via Network Preferences for my active ethernet connection under the DNS tab.

This worked for me, but only by adding ".local". "local" (without a prepending dot) didn't work. I'm no sys-admin, but I believe ".local" is parsed by Mac OS X as a TLD, much like ".com" or ".org" (other posters alluded to this above).

Adding it to DNS Search Domains in the Network System Preferences makes the system attempt to resolve hostnames by adding ".local" to the end of them. This seems to me to be what the OP is looking to accomplish.
 

canhaz

macrumors 6502
Jan 17, 2012
310
145
This worked for me, but only by adding ".local". "local" (without a prepending dot) didn't work. I'm no sys-admin, but I believe ".local" is parsed by Mac OS X as a TLD, much like ".com" or ".org" (other posters alluded to this above).

Adding it to DNS Search Domains in the Network System Preferences makes the system attempt to resolve hostnames by adding ".local" to the end of them. This seems to me to be what the OP is looking to accomplish.

Thank's wanted to point out, that this is not working for me in Yosemite.

However, visitors to this thread, may find this relevant to the discussion:

http://apple.stackexchange.com/ques...alternative-to-replace-mdnsresponder-argument
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.