However, you do need to be aware of the default subnet masks so you can use the correct subnet mask for your IP address. The default subnet masks are different for each class:
Default Subnet Mask
In my test network, I have three computers. I've decided to use the private Class A network range, the default subnet mask, and to use host addressess of 1, 2, and 3. This translates into the following addresses:
On the computer named alpha, I used the
ifconfig utility to "bind" an IP address to its NIC. In order to do this, I first had to determine the device name of the NIC using the following command:
dmesg | grep Ethernetrl0: Ethernet address: 00:00:b4:94:9d:3f
which shows that the device name of alpha's NIC is rl0. To see if there is an IP address bound to your NIC, use the following command if you're
running FreeBSD 4.0 and above (but substitute your NIC's device name for
ifconfig rl0 inetrl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 ifconfig: rl0 has no inet interface address!
If you're running FreeBSD version 3.x or below, you do not use the
inet argument as these versions only support IPv4 addresses.
This NIC does not have an IPv4 address; I'll use the
ifconfig command like so to assign one:
DNS and Bind, 4th Edition
ifconfig rl0 10.0.0.1 netmask 255.0.0.0ifconfig: ioctl (SIOCAIFADDR): permission denied
Note that regular users have sufficient permission to view, but not to change, the IP address assigned to a NIC. Let's become the superuser and try again:
ifconfig rl0 10.0.0.1 netmask 255.0.0.0 exit
ifconfig rl0 inetrl0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500 inet 10.0.0.1 netmask 0xff000000 broadcast 10.255.255.255
Once you've bound an IP address to a NIC, you'll want to use the ping utility to ensure that the NIC can send and receive TCP/IP packets.
is called pinging your loopback address. This will check that TCP/IP has been initialized on your system. If this test does not work, you can't use TCP/IP.
will check that your IP address is valid. If this test does not work, check that you have a valid IP address and subnet mask and that no other host is using the same IP address.
If you have another host on your network, ping its IP address. If this last test works, you're in business. If not, double-check your network cabling and ensure that the other computer is turned on and that you are pinging the correct address.
TCP/IP uses IP addresses, but humans like to use hostnames. Quick, what's
the IP address of www.yahoo.com? Don't feel bad if you don't know, as you
don't need to in order to access Yahoo's webpage. Hostname resolution was
designed to map hostnames to the IP addresses that TCP/IP understands. If
you have a small network, you can use the
/etc/hosts file to provide hostname resolution. DNS databases provide the same function in larger
networks and on the Internet. DNS is far beyond the scope of this
article; if you need to setup a DNS server, I highly recommend that you first
read DNS and BIND by Cricket Liu and Paul Albitz. The DNS Resources Directory site also contains many useful documents on DNS.
However, editing the
/etc/hosts file is an easy matter. First, you need to know, and possibly set, your hostname using the hostname utility. Anyone
can view the computer's hostname by typing
hostname. Only root can change the computer's hostname. One way to change a computer's hostname is like so:
This will set the computer's hostname to alpha.
Once the computers in your network have hostnames, you should edit the
/etc/hosts file so you can access resources by hostname instead of IP address. Again, only root can modify this file. Each of the computers in
my network has an
/etc/hosts file that looks like this:
more /etc/hosts127.0.0.1 localhost 10.0.0.1 alpha 10.0.0.2 beta 10.0.0.3 gamma
After you edit the
/etc/hosts file, always try pinging the hostnames that you've added. For example:
ping alpha ping beta ping gamma
If any of the pings fail, you either have a typo in your
etc/hosts file or the hostname has not been set on that computer.
Well, that's probably enough about TCP/IP for one day. We'll be revisiting TCP/IP in future articles and will add more details to these basic concepts as we go along. Next week, we'll explore the world of e-mail and how your FreeBSD system uses two TCP/IP ports to allow you to exchange e-mail messages with the world.
Dru Lavigne is a network and systems administrator, IT instructor, author and international speaker. She has over a decade of experience administering and teaching Netware, Microsoft, Cisco, Checkpoint, SCO, Solaris, Linux, and BSD systems. A prolific author, she pens the popular FreeBSD Basics column for O'Reilly and is author of BSD Hacks and The Best of FreeBSD Basics.
Read more FreeBSD Basics columns.
Discuss this article in the Operating Systems Forum.
Return to the BSD DevCenter.