Configuring the local network
Point-to-point interfaces
With a point-to-point interface, the software currently requires you to specify the IP address of the other end of the link as well. As we shall see in "Configuring PPP" , there is no good reason to do this, but ifconfig insists on it. In addition, we need the network mask for a non-broadcast medium. The value is obvious1 Well, you’d think it was obvious. We’ll see on page 346 that some people think it should be something else : 1 you can reach exactly one address at the other end, so it must be 255.255.255.255. With this information, we could configure the PPP interface on gw:
# ifconfig tun0 139.130.136.133 139.130.136.129 net mask 255.255.255.255
In fact, this is almost never necessary; in "Configuring PPP" we’ll see that the PPP software usually sets the configuration automatically.
The loopback interface
The IP protocols require you to use an address to communicate with every system—even your own system. Theoretically, you could communicate with your system via the an Ethernet interface, but this is relatively slow: the data would have to go through the network stack. Instead, there is a special interface for communicating with other processes in the same system, the loopback interface. Its name is lo0, and it has the address 127.0.0.1. It’s straightforward enough to configure:
# ifconfig lo0 127.0.0.1
In fact, though, you don’t even need to do this much work: the system automatically sets it up at boot time.
Checking the interface configuration
ifconfig doesn’t just set the configuration: you can also use it to check the configuration. It’s a good idea to do this after you change something:
$ ifconfig dc0: flags=8843< UP, BROADCAST, RUNNING, SIMPLEX, MULTICAST > mtu 1500 inet 223.147.37.5 net mask 0xffffff00 broadcast 223.147.37.255 inet6 fe80::280:c6ff:fef9:d3fa%dc0 prefixlen 64 scopeid 0x1 ether 00:80:c6:f9:d3:fa media: Ethernet autoselect (100baseTX < full-duplex >) status: active lp0: flags=8810<POINTOPOINT,SIMPLEX,MULTICAST> mtu 1500 lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384 inet6 ::1 prefixlen 128 inet6 fe80::1%lo0 prefixlen 64 scopeid 0x3 inet 127.0.0.1 net mask 0xff000000 tun0: flags=8051<UP, POINTOPOINT, RUNNING, MULTICAST > mtu 1500 inet 139.130.136.133 -- > 139.130.136.129 net mask 0xffffffff
There are a number of things to note here:
- The dc0 interface has both an IPv4 address (inet) and a corresponding IPv6 address (inet6). It also specifies the Ethernet address (ether 00:80:c6:f9:d3:fa). It is capable of negotiating 10 Mb/s, 100 Mb/s half duplex and 100 Mb/s full duplex. It’s connected to a switch, so it’s currently running 100 Mb/s full duplex.
- The interface lp0 is the the PLIP interface for connections via the parallel port. It is not configured (in other words, it has not been set up for operation).
- We’ve already seen the loopback interface lo0.
- There is also a tun0 interface for PPP.
The configuration files
The system startup scripts summarize this configuration information in a number of configuration variables .See "Starting and stopping the system" for more details. At the moment, the following variables are of interest to us:
-
hostname is the name of the host. You should have set it when you installed the system (see page 87). You can also set it manually with the hostname command:
# hostname -s gw.example.org
- For each interface, a variable of the form ifconfig_interface contains the parameters to be passed to ifconfig to configure that interface.
Previously, FreeBSD also required you to set a variable network_interfaces, a list of the names of the interfaces to be configured. This variable now defaults to the value auto to specify that all interfaces should be configured. You only need to change it if you specifically want to exclude an interface from configuration.
For gw, we put the following information in /etc/rc.conf:
hostname=‘gw.example.org’ ifconfig_dc0=‘inet 223.147.37.5’
We don’t configure the tunO interface here; as we’ll see in "Configuring PPP" , the PPP setup works differently.
Automatic configuration with DHCP
Maintaining the network configurations for a number of machines can be a pain, especially if they're laptops that come and go. There's analternative for larger networks: use DHCP, the Dynamic Host Configuration Protocol. DHCP enables a machine to get configuration information automatically from the network. The concept is expandable, but typically you get an IP address and net mask and the names of the default name servers and routers. In terms of the configuration we've seen so far, this replaces running the ifconfig and route programs, and also the file /etc/resolv.conf, which describes the locations of name servers. We'll look at it on page 366.
There are two parts to DHCP: the client and the server.
DHCP client
To get a configuration, you run dhclient. In previous releases of FreeBSD, dhclient printed out information about the addresses it received. In Release 5, it does not print anything. Simply start it with the name of the interface:
# dhclient dc0
To assign an address automatically at boot time, put the special value DHCP in the ifconfig_dc0 variable:
ifconfig_dc0=DHCP
DHCP server
DHCP requires a server. The server is not included as part of the base system; instead, install the net/isc-dhcp3 port:
# cd /usr/ports/net/isc-dhcp3 # make install
To configure dhcpd, edit the configuration file /usr/local/etc/isc-dhcpd.conf. Here's an example:
ddns-update-style ad-hoc; # 100 Mb/s Ethernet subnet 223.147.37.0 net mask 255.255.255.0 { range 223.147.37.90 223.147.37.110; option domain-name-servers freebie.example.com, presto.example.com; option domain-name " example.com "; option routers gw.example.com; option subnet-mask 255.255.255.0; option broadcast-address 223.147.37.255; default-lease-time 86400; max-lease-time 259200; use-host-decl-names on; use the specified name as host name host andante { hardware ethernet 0:50:da:cf:7:35; } }
This configuration file tells dhcpd:
- To dynamically allocate IP addresses in the range 223.147.37.90 to 223.147.37.110 (range keyword).
- That the domain name servers are freebie.example.com and andante.example.com. We’ll look at domain name servers in "The Domain Name Service" .
- The net mask and the broadcast address.
The variables default-lease-time and max-lease-time, which are specified in seconds, determine how long it will be before a system checks its configuration. The values here represent one day and three days respectively.
use-host-decl-names tells dhcpd to use the name on the host line as the host name of the system. Otherwise you would need an additional option host-name specification for every system. For one machine it doesn’t makemuch difference, but if you have twenty such machines, you'll notice the difference.
One of the problems with dhcpd is that by default it doesn’t allocate a static IP address. Theoretically you could attach a laptop to the same DHCP server and get a different address every time, but in fact dhcpd does its best to keep the same address, and sometimes you may find it impossible to change its mind. In this configuration file, though, we have explicitly told dhcpd about andante, which is recognized by its Ethernet address. This works relatively well for fixed machines, but there’s problem with laptops and PC Card: dhcpd recognizes the network interface, not the machine, and if you swap the interface card, the IP address moves tothe new machine.