Setting Your Machine s Hostname

Setting Your Machine's Hostname

When dealing with networks, you will often encounter the term hostname . This term can cause some confusion because of the difference between its technical meaning and its common usage. The term hostname is frequently used where the correct term would be fully qualified domain name ( FQDN ).

Hostname technically refers to a name given to a specific machine (or host) without any mention of a domain name. So a machine's hostname could be "mailserver1," "frodo," or "amelia." The hostname is typically (but not always) a single word rather than multiple words separated by dots. On the other hand, an FQDN always includes a domain name, and thus always has one or more dots in it. For example, is an FQDN.

In Chapter 11, "Introduction to System Administration," we explained that people tend to refer to Internet hosts by their FQDNs, (such as, while machines on the Internet identify each other using IP addresses. FQDNs ultimately point to IP addresses, not to hostnames.

What can be very confusing is that the actual hostnames of machines on the Internet are often not used in their FQDNs. For example, the machine that is reachable with the FQDN might have a hostname of server23. And here's the really confusing part: The term hostname is widely used to refer to what are actually FQDNs, so it is very common to read something that says, "Enter a hostname, such as," and, for better or worse , we stick to the popular usage in this book.

Throughout this chapter we talk about setting up server software on your computer so that other machines can connect to it using various network protocols (for example, to send e-mail to your computer or to use a Web browser or FTP client to connect to your computer). If you want people to be able to connect to your server using an FQDN instead of an IP address, then you need to arrange for an FQDN to "point" to your machine's IP address. This is done using something called the domain name system (DNS.)

FQDNs refer to specific machines and are created by whoever controls the domain involved. For example, the FQDN

refers to the machine that has the IP address That FQDN is created by whoever controls the

domain (that would be me, the author).

The controller of a domain may create as many sub-domains and FQDNs as he or she wishes within the domain. Basically, you can add as many different elements as you like to the left side of domain names you control.

If you are running your Mac in a large office environment, you should probably contact your office's network administrator to find out what the FQDN is for your machine, or have the administrator create one for you.

If you are a home- or small-office user , then your Internet service provider (ISP) has probably established FQDNs for the IP address(es) that it assigned to you. Unfortunately, the FQDN for your machine's IP address is probably something like "user135-walla-walla."

You may also have reserved a new domain name through one of the many domain-name registries. You will need to contact that registry and ask it to set up the FQDN for you, giving it the FQDN you want and the IP address for your machine. It will often take several days or even weeks to get through the bureaucratic process.

So in order for your machine to have the FQDN that you want, you must arrange for the following:

  • Your machine must have a static IP address. This is one that does not change each time you reboot the machine. Look in the Network pane of System Preferences, on the TCP/IP tab. Select the port you want to use, such as Built-in Ethernet, from the Show pop-up menu. The Configure method should be set to Manually ( Figure 14.1 ). For an exception to this rule, see the sidebar "Dynamic DNS."

    Figure 14.1. The TCP/IP tab of the Network pane of System Preferences, where you set the Configure method to Manually for a static IP address.

  • The owner of an Internet domain name must create a configuration entry that associates your IP address with a domain name (making it an FQDN).

Mac OS X tries to figure out the FQDN for your machine when it boots up, but if you want the operating system to set its hostname to an FQDN other than the one it finds automatically, you need to change a system-configuration file.

To see the hostname your Mac is using:

  • hostname

    This will show the FQDN that your Mac is currently using.

    Technically, the hostname is only the left-most part of the FQDN, and you can see that part alone by adding the -s option:

    hostname -s


  • Sometimes in a script you want to get the hostname part of the FQDN so that you can use it in the name of a log file or something similar. In a Bourne shell script you would use

    hostpart=`hostname -s`

    and in a tcsh ( csh ) script you would use

    set hostpart=`hostname -s`

    That sets $hostpart to contain only the host part of the FQDN.

The system of translating domain names to IP addresses (and vice versa) is handled by the DNS worldwide database of domain names and IP addresses. This distributed database is made up of tens of thousands of servers, called domain name servers , each of which is responsible for a small portion of the overall database. Each domain name is controlled by one server (the primary DNS server for that domain), with one or more backup servers (secondary DNS servers) that copy information from the primary one.

Only the operator of a primary DNS server can create a new FQDN. Even if you set the hostname of your Mac, the rest of the world will not be able to use that hostname to reach your Mac unless a DNS record associates that hostname with your Mac's IP address.

To see the DNS records for a hostname:

  • dig name

    The dig command will show you information about the name which you usually enter as an FQDNfor example,


    Figure 14.2 shows an annotated example of a dig query and response.

    Figure 14.2. Annotated example of output from the dig command.

    The ANSWER SECTION is where the IP address will be shown. In some cases an FQDN may map to multiple IP addresses; for example, try


    See man dig for more details on the dig command.


  • A very important item in Figure 14.2 is the ANSWER SECTION , which shows us that an A record exists associating the IP address with the FQDN

  • E-mail servers use their FQDN to identify themselves when they send e-mail to another machine. In most cases, the receiving server will reject the connection unless the DNS "A record" for the sending machine's IP address matches the FQDN with which the sending e-mail server identifies itself. In other words, the machine you are sending to wants to be able to look at the IP address of your machine. The receiving server automatically gets the IP address when your machine connects to it. Then the receiving server wants to translate that IP address into an FQDN that matches your e-mail server. This is largely an anti-spam measure.

  • Another way to see the IP address(es) for an FQDN is the host commandfor example:




To see the fully qualified domain name for an IP address:

  • dig -x ipaddress

    For example:

    dig -x

    If there is an FQDN for the IP address, it will be shown in the ANSWER SECTION of the output from dig .

If the FQDN you intend to use for your machine is different from the one returned by the hostname command, then you must change a system-configuration file to tell your Mac to use the FQDN you want. The exact method of doing this varies among different versions of Unix, but here's the Darwin approach.

Dynamic DNS

Most home users of the Internet do not have static IP addresses. Instead, their Internet service providers assign a different address (from a pool of addresses) each time a customer connects.

There is a way that you can have an FQDN that points to a machine whose IP address changes each time it boots up. You arrange with a service that provides dynamic DNS . With this service, your computer contacts the dynamic DNS provider each time it gets a new IP address, and the dynamic DNS provider updates its database so that your FQDN points to your current IP address.

See Dynamic DNS Providers List (

Note: For several tasks in this chapter, you'll have to become root, make a backup of your /etc/hostconfig file, and then edit it. We've listed the three steps of the task here, but later in the chapter we combine them, with a reference back here.

To change the /etc/hostconfig system-configuration file:

Become root:

sudo -s

Make a backup copy of /etc/hostconfig :

 cp /etc/hostconfig/etc/  hostconfig.  YYYYMMDD  

Use today's date for YYYYMMDD . The /etc/hostconfig file can be changed only by root.

YYYYMMDD is the current year, month, and day from today's date. If you were doing this on July 23, 2003, the command line would read

 cp /etc/hostconfig /etc/  hostconfig.20030723 

Edit the file /etc/hostconfig using your favorite command-line editorfor example, vi :

vi /etc/hostconfig

Review Chapter 6, "Editing and Printing Files," for more on editing files.

Make whatever changes are need to the hostconfig file.

You will use the steps from this task in several tasks in this chapter.

Whenever you change a system-configuration file, you should always make a copy of it first. That way, you can easily revert to whatever state the file was in before you messed it up . . . um, before you changed it.

To set the machine's hostname temporarily:

  • sudo hostname newhostname

    This will set the machine's hostname to newhostname for example:

    sudo hostname

    The change will last only until the next reboot. See the next task for how to set the hostname on each startup.

This next task requires a reboot, so only proceed with it when you are ready to reboot the machine.

To set the machine's hostname on every startup:

Per the task above, become root, back up /etc/hostconfig , and edit the file using vi .

Change the line that says


to have your FQDN, instead of -AUTOMATIC- . So if your FQDN is, you would use

Save your changes and quit the editor.

(In vi , you press and then type :wq .)

Restart the machine.

In Mac OS X 10.2 (only), you can restart just the networking functions with

SystemStarter restart Network

In other versions of Mac OS X, you must restart the machine for the change to take effect. However, see the previous task for how to set the hostname temporarily, without a reboot.

Test it:


should show the FQDN you entered.

Running Your Own DNS Server

Mac OS X comes with the software necessary to run your own DNS server. To effectively run your own DNS server for a particular domain, such as, your Mac needs to be on all the time and have a static IP address. Also, you must notify the domain's registrar that you want your Mac to be the primary DNS server for the domain.

Unix for Mac OS X 10. 4 Tiger. Visual QuickPro Guide
Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
ISBN: 0321246683
EAN: 2147483647
Year: 2004
Pages: 161
Authors: Matisse Enzer

Similar book on Amazon © 2008-2017.
If you may any questions please contact us: