14

(I'm using a Mac. It triple boots OS X.8, Gentoo, and Windows 7. I've only noticed the problem in OS X, but that's what I use most of the time so it might be occurring in other OSes.)

I've used System Preferences to set my host name to what I want it to be. Yet, when I connect to particular networks (parent's house, dorms, school, etc), as far as Darwin is concerned, my hostname becomes something else. I say Darwin because Terminal and the sharing panels in System Preferences ('Other users can [some sharing action] your computer [some address involving the altered hostname]'). Sometimes the altered hostname is a lower case version of what it should be, sometimes its host1234.some.provider.com, or just host1234.

This frustrates me. I want my hostname to be what I set it to, always, across all systems. Especially in Mac. What can I do to prevent this alteration? I have (root) access to a server with BIND on it, so should I set up dynamic global hostname? Are there any guides to setting up BIND for that (RFC 3007)? I (mostly) understand DNS as applied to websites, etc, but I've only ever altered the bindings in CPanel.

UPDATE: I'm not complaining about clients showing fully qualified host names. My local machine is showing a different host name. Lets say my computer's hostname is set to be Firelizzards-Computer in OS X's equivalent of /etc/hostname. Right now, connected to my dorm's WiFi, running hostname returns host-173-230-36-89.mycampusname.clients.myprovider.com (my LAN address is 173.230.36.89). Why is hostname not returning Firelizzards-Computer.mycampusname.clients.myprovider.com?

NOTE: The phrase 'dynamic global hostname' refers to a setting in OS X that involves RFC 3007.

SOLUTION: sudo scutil --set HostName <desired host name>. I found this, this, and this, the last one being my exact problem.

So now my question is, by what mechanism is connecting to a LAN changing what hostname was returning?

3 Answers3

8

The answer from Daniel J. is not a valid answer. It's just "stating a fact". Can it be done or not? And how is it done?

The answer is yes. Here is how:

  • Go in your OSX Network preferences and select the network card you are connected with.
  • Click on "Advanced..." near the bottom right corner of the dialog box (above "Assist me.." "Revert" and "Apply")
  • In the new window that comes up, click on the WINS tab and change the NetBIOS Name and Workgroup to your liking.
  • Save the changes ... et voilà
asiby
  • 188
1

SOLUTION: sudo scutil --set HostName <desired host name>. I found this, this, and this, the last one being my exact problem.

That's the correct solution. If you look at the man page for scutil, you'll see ComputerName, LocalHostName, and HostName all documented.

by what mechanism is connecting to a LAN changing what hostname was returning?

I cannot find official documentation for this, so I will have to report observed behavior.

Before any networks are connected, the hostname will be set by default to the computer name, which is set in General → About in System Settings. The local hostname will override this preference, which is set in Sharing → Local hostname. I think these correspond to ComputerName and LocalHostName respectively, and there's no GUI that I'm aware of for setting HostName.

When you connect to a network, something (not sure what!) issues a reverse-DNS request on the address acquired on that network, and sets the system hostname temporarily to that value, assuming it isn't set persistently with scutil. This will often happen to line up with your ComputerName because the macOS DHCP client will, by default, send the ComputerName or LocalHostName as the DHCP client ID to the DHCP server. To the extent that residential or small-office routing hardware supports DNS at all, it generally allows clients to pick their own names, then sets a PTR record in its local DNS server corresponding to that DHCP lease.

If your router supports configuring its DNS server, you can set up some records for your computer, and thereby affect what your hostname is on that network as well. If your router doesn't bother to support local DNS records, then your computer will just maintain its own hostname based on the config you've put into system settings. So in both cases it looks like you set it and it shows up as you'd expect.

However, when you connect to a larger network where you're not the administrator, those reverse DNS records can be anything. As you've noticed by your reference to "school" and "dorms", these larger networks often have their own DNS configuration regime, and whatever name it doles out is the one you'll see your system adopt.

Glyph
  • 570
  • 1
  • 5
  • 17
1

It looks like your computer is getting its hostname from a DHCP server. If you are in a campus context it is normal that network administrators try to keep control on any aspect that they can.

Daniel J.
  • 298