IP addresses, especially IPv6 addresses (see the sidebar "IPv6 Addresses,” earlier in this chapter), aren’t something that you ever really want to deal with directly; hostnames are much more convenient to use. However, every operation that involves a hostname has to involve looking up an IP address for that hostname. For example, when you point Safari or Firefox to http://www.oreilly.com, the system translates that hostname into an IP address using the Domain Name System (DNS), a distributed naming system that resolves hostnames to an IP addresses.
For the most part, DNS is transparent. All you need to have is a DNS server defined in your network configuration, and you can use hostnames in your applications. Without DNS, all you’ll be able to do is surf the Net by IP address, which is possible but not a very fun experience.
If your computer obtained its IP address through DHCP, it should also be configured with the correct DNS server. However, if you have to configure your IP address manually, you’ll need to provide valid values for a DNS server. If you have to configure your own DNS servers, make sure you use a DNS server that is close to you on the network. After all, every connection to a host on the Internet requires the resolution of hostname to IP address. The closer you are to the server, the better.
The DNS servers that your machine is currently using are shown in the Network preference panel. You can also find them in the /etc/resolv.conf
file, as shown in Example 11-3.
Example 11-3. Examining the contents of the resolv.conf file
$ cat /etc/resolv.conf
domain example.com
nameserver 192.168.79.5
nameserver 192.168.79.7
On other Unix systems, you can directly edit the resolv.conf
file to change your nameserver configuration. However, this file is automatically updated by the networking system in Mac OS X, so any changes you make to it will be lost the next time you change networks.
To look up an IP address for a hostname yourself, or to find the hostname associated with an IP address, you can use the Lookup tab of Network Utility, as shown in Figure 11-5. Simply enter the host or IP address that you want to look up and click the Lookup button. Other options are available to you through the information pop-up menu. However, for most purposes, the default information setting should give you all the information you need.
On the command line, you can use the host
command to determine the IP address for a host or vice versa, as shown in Example 11-4.
Even without a configured DNS server, there is another component of Bonjour known as multicast DNS (mDNS). mDNS lets computers on a local network know each others’ names so that you can access a computer using a human-readable name instead of an IP address. For example, for a machine named Hobbes, you should be able to browse a web server running on it from another machine on the local network by entering into Safari Hobbes.local
.
By default, when you install Mac OS X, the name of your machine will be based on the full name given when setting up the first account. For example, the default name of my machine after installing Tiger was “Jason Deraleau’s Computer.” You should change this to be something a bit shorter and more personalized (throughout this book you’ll see Ronin and Hobbes, the names of two of my machines) in the Sharing preference panel.
The combination of mDNS and self-assigned IP addresses provides the foundation for Bonjour to work its magic. With mDNS, Bonjour-enabled computers not only let each other know their names, but they can also advertise the services they offer. When you enable iTunes music sharing or iChat, a description of that service is broadcast via mDNS, allowing any other Bonjour machine to see it.
The various services provided by a host, such as HTTP for serving web pages or SMTP for handling email, are each exposed to other computers on a separate port: a network connection endpoint in the IP stack identified by a number. For example, HTTP is defined to run on port 80. This means whenever you browse to a page on the server, your web client is opening a connection to port 80 of the server to make its request.
Most services use ports
numbered less than 1024; these are known as the well-known ports
. Table 11-1 lists the various services and ports built into Mac OS X’s firewall. Table 11-2 lists some more common services and their ports. You can also find an extensive listing of well-known services in the /etc/services
file.
Table 11-1. Well-known ports found in Mac OS X’s firewall
Service |
Ports |
---|---|
Personal File Sharing |
548/tcp, 427/tcp |
Windows Sharing |
139/tcp, 137/udp, 138/udp |
Personal Web Sharing |
80/tcp, 427/tcp, 443/tcp |
Remote Login |
22/tcp |
FTP Access |
21/tcp |
Apple Remote Desktop |
3283/tcp, 5900/tcp, 3283/udp, 5900/udp |
Remote Apple Events |
3031/tcp |
Printer Sharing |
631/tcp, 515/tcp |
iChat Bonjour |
5297/tcp, 5298/tcp |
iTunes Music Sharing |
3689/tcp |
iPhoto Bonjour Sharing |
8770/tcp |
Network Time |
123/udp |