For Darwin, the default configuration mechanism, and the officially recommended way, is to edit the files as described below.
In Darwin, network devices are referred to by a short name followed by a number. The number starts with zero and increases as more network interfaces of the same type are detected. Some short names used in Darwin are "en" (ethernet devices), "lo" (loopback interface), "ppp" (PPP and, post-darwin-1.3.1, PPPoE), and "pppoe" (PPPoE, pre-darwin-5.1).
There are 3 places network configuration information is stored.
The file /etc/iftab contains one line per "configuration", where each line contains a device "spec" and the remainder of the arguments that would be passed to ifconfig. This file is accessed only at boot time, and therefore, any device specified must be present for the configuration to take effect. Thus, PPP devices are generally not configured with this file.
Lines beginning with "#" are treated as comments. A device spec is a device name, with some shell-like wildcard capability (for example, '*' means any device; 'en*' means any "en" device). A device name from the list of existing devices is configured with the first line that matches. Each line consists of the name of a network device, followed by items that make up the arguments for an ifconfig command. For example, a configuration that includes the loopback interface and just the built-in network device might appear this way:
lo0 inet 127.0.0.1 netmask 255.0.0.0 up en0 -AUTOMATIC-
The first line assigns the indicated address/netmask to lo0, and brings the device up. The second line tells the Network StartupItem that it should appeal to BOOTP for further configuration information. The command ipconfig handles this (in the file /System/Library/StartupItems/Network/Network).
The "magic cookies" that can be used following the device names are as follows:
Cookie | Uses |
---|---|
-AUTOMATIC- | BOOTP |
-BOOTP- | BOOTP |
-BOOTP- | BOOTP |
-DHCP- | DHCP |
-INFORM- | DHCP Inform |
The default iftab file has a bunch of comments at the top of it explaining the fields in it, but here's a brief description. It looks something like this (with the comments removed):
lo0 inet 127.0.0.1 netmask 255.0.0.0 up * inet -AUTOMATIC-
With the wildcard capability, it may be convenient to leave the file in its default state, if you are using BOOTP on all interfaces (other than "lo0"). If DHCP is in use, you can replace AUTOMATIC with DHCP. Starting from the left, the first field is the interface you want to configure. Let's assume we're going to configure en0. The second field is the protocol to configure. This will almost always be inet (IPv4 configuration). From here on, the line can be different.
en0 inet {My IP} netmask {My netmask} up
This will set up "en0" with the IP address and netmask that you provide.
en0 inet -DHCP-
The special tag -DHCP- says that this interface should be configured through DHCP.
en0 inet -AUTOMATIC-
or
en0 inet -BOOTP-
The -AUTOMATIC- and -BOOTP- tags say that this interface should be configured using bootp.
In Darwin 5.2 and later, the agent for controlling most of the network configuration issues (ipconfigd) has been incorporated into configd, as a plugin (IPConfiguration). The information from iftab is incorporated into configd's dynamic store directly. This effects the treatment and the recording of aliases.
The /etc/hostconfig file is used for generic host configuration information, similar to rc.conf in FreeBSD. The file is included by /etc/rc.common which is read by various shell scripts during bootup. It sets sh variables that are used by the scripts to determine how the system is to be setup. Two parameters are of interest for the configuration of networking at startup: HOSTNAME and ROUTER.
The default hostconfig file ships with the following lines (among others):
HOSTNAME=-AUTOMATIC- ROUTER=-AUTOMATIC-
The ROUTER variable can be either -AUTOMATIC-, for the default router to be determined automatically, either through DHCP or Bootp depending on the configuration of /etc/iftab. The ROUTER variable can also be set to the IP address of your default router. Here are two examples:
# The default. Configured by DHCP or bootp ROUTER=-AUTOMATIC- # Set statically ROUTER=192.168.1.1
You do not want to put the hostname of your router in this file because name resolution is usually not available at the time the default router is set.
HOSTNAME can be either a literal name; or the word -AUTOMATIC-. In the latter case, the system will determine the hostname from information gleaned while booting, from either BOOTP or DHCP. Note that the host name specified here is not related to the DNS hostname. It is the value that is stored and retrieved from the system using the hostname(1) command.
NetInfo can be used to provide the resolver configuration information, such as your domain name and your nameserver(s). It is not set up to do so by default, but you can set it up this way.
NetInfo can be manipulated through the utility niutil. Configuration information stored in NetInfo stays the same across reboots, until someone chages it. This description is for the first time configuration only:
This tells NetInfo to create a place for the resolver configuration. The 'resolver' directory is not present by default, so you need to create it if you need it.
This creates a "domain" entry in the NetInfo resolver configuration, and sets the value to mydomain.com. Of course, you'll want to change mydomain.com to your domain.
This creates a "nameserver" entry in the NetInfo resolver configuration, and sets the value to 192.168.1.1. You'll want to change 192.168.1.1 to the IP address of your nameserver. Don't use the hostname of your nameserver. You can set up multiple "nameserver" entries by repeating this command with different values of the nameserver address.
Now, if you reboot, your machine should be configured on the network when it comes back up. However, you don't have to reboot if you don't want to. Here are the steps to get your configuration to stick without rebooting:
route add default {your gw IP}
Both netinfod and lookupd record their PIDs in files in /var/run (netinfo_local.pid and lookupd.pid), so you can issue
kill -HUP `cat /var/run/FILE`
without having to resort to other commands to find the process IDs. HUPping netinfod tells it that information has changed in its database (you configure the DNS information there), and HUPping lookupd tells it the resolver information has changed. Theoretically, you shouldn't have to send HUP's to these daemons, but in practice, you do.