AddThis Social Bookmark Button


FreeBSD Basics FreeBSD Networking Basics

by Dru Lavigne

Beginners to Unix-like operating systems such as FreeBSD are often stymied by their network settings. Sure, the install process may have set up your NIC for you, but where do you go to view these settings, and how do you proceed if your NIC stops working? Since networking is such an integral part of computing, this article will demonstrate how to verify, configure, and optimize your network settings.

Verifying Your Interface Configuration

If you've come from a Microsoft background, you've probably used either winipcfg or ipconfig /all to verify your network settings at the command line. Unix comes with a similar utility, named ifconfig (for "interface config"). By entering this command, you'll see all of the system's interfaces and their settings. Some versions require you to include the -a, or all, switch.

% ifconfig
rl0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
    ether 00:05:5d:d2:19:b7
    media: Ethernet autoselect (10baseT/UTP)
    status: no carrier
rl1: flags=8802<BROADCAST,SIMPLEX,MULTICAST> mtu 1500
    ether 00:05:5d:d1:ff:9d
    media: Ethernet autoselect (10baseT/UTP)
    status: no carrier
    inet netmask 0xffffff00 broadcast
    ether 00:50:ba:de:36:33
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
    inet netmask 0xff000000 

Your output will vary from this, but will contain similarities. This particular system isn't running the default kernel. I've removed the default IPv6, gif, and faith devices from this kernel, so they don't show in the output.

This system does have three physical interfaces (rl0, rl1, and ed0) and the loopback virtual interface (lo0). Different versions of Unix differ in their interface naming convention. For example, Linux uses eth for Ethernet NICs, so would show their names as eth0, eth1, and eth2. BSD uses the driver name for each NIC, allowing you to differentiate between different chipsets and the features available for each driver. To see the documentation for your NIC's driver, read section 4 of its driver manual. Note that you don't include the number of the interface, so look up rl instead of rl0:

% man 4 rl
rl -- RealTek 8129/8139 Fast Ethernet device driver

% man 4 ed
ed -- ethernet device driver

While this system has three NICs, only ed0 is up and running. The two RealTek NICs don't have cables attached, as indicated by the status: no carrier lines. Accordingly, only ed0 has an IP address (, a subnet mask (0xffffff00), and a broadcast address (

That subnet mask is written in hex, as indicated by the beginning 0x. This particular mask isn't too hard to translate into decimal, if you remember that each pair of f characters (ff) is equivalent to 255. Thus, the subnet mask here is If you find a pair of hex numbers that aren't ff (255) or 00 (0), use bc or the built-in calculator to translate that hex pair into decimal for you. For example, if your mask is 0xffffe000:

% bc
bc 1.06
Copyright 1991-1994, 1997, 1998, 2000 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
<Ctrl d>

Here, I asked bc to translate a base 16, or hex, number as input (ibase=16). Remember to convert any letters to uppercase, or you won't get the correct answer. Since e0 is decimal 224, this example mask is

Verifying Your Default Gateway

Note that ifconfig gives the applicable status, MTU, IP address, subnet mask, broadcast address, and Ethernet (or MAC) address of each interface. However, it doesn't give the address of the default gateway or the DNS servers.

To see your default gateway address, use the netstat, or network status, command. Include the -r (routing) switch. Including the -n switch speeds up the results by skipping name resolution:

% netstat -rn
Routing tables

Destination      Gateway          Flags    Refs    Use   Netif  Expire
default      UGS     0    72664    ed0          UH      1       46    lo0
192.168.2        link#3             UC      0        0    ed0          UGHS    0        0    lo0    00:48:54:1e:2c:76  UHLW    1        0    ed0   1172

Note: Linux users can also use the route command to receive similar results. The BSD route command works differently; see man route for details. However, netstat -rn works on all operating systems, including Linux and Microsoft operating systems.

In your output, look for the line that begins with the word default. The associated IP address is that of your default gateway. Also look at the flags for that entry. Hopefully they indicate U for up and G for gateway. This indicates that you can communicate with your gateway. If the number in the Use field isn't 0, you've actually sent your gateway that number of packets.

Finally, the last line of this output shows the MAC address of the default gateway.

Verifying Your DNS Settings

The resolver configuration file should contain your DNS settings. You can view that file with:

% more resolv.conf

This particular system contains the IP addresses of three DNS servers. It's a good idea to have the addresses of at least two servers, in case your primary DNS server becomes unavailable.

While you have Internet access, you should know how to query your ISP's DNS servers and to record the results in a book containing your network settings. This will be invaluable if you ever need to recreate these settings manually. If you don't keep such a notebook, you can gather those settings from a system that does have working Internet access.

To find out the IP addresses of your DNS servers, use dig, the domain information groper. Here, I'll ask for the ns, or name server, entries for my ISP:

% dig ns

; <<>> DiG 8.3 <<>> ns 
;; res options: init recurs defnam dnsrch
;; got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 44589
;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 4
;;, type = NS, class = IN

;; ANSWER SECTION:         6h12m33s IN NS         6h12m33s IN NS         6h12m33s IN NS         6h12m33s IN NS

;; ADDITIONAL SECTION:   9m36s IN A   9m37s IN A    14m7s IN A    3m56s IN A

;; Total query time: 46 msec
;; WHEN: Sun Apr 11 14:30:14 2004
;; MSG SIZE  sent: 30  rcvd: 182

Your output will be divided into several SECTIONs. For now, concentrate on the ANSWER SECTION, which contains the answer to your dig query. My ISP uses four DNS name servers, as seen in my answer. Each name server uses an IN (IPv4) record and a NS (name server) record. However, the answer shows the names of the name servers. You don't want to use names for name resolution; you want the IP addresses of your name servers.

You'll find those names mapped to IP addresses in the ADDITIONAL SECTION.

dig is also handy if you ever forget the name or IP address of your ISP's SMTP or mail server. This time, query for the mx, or mail exchange record. Here, I've shown only the ANSWER SECTION for brevity:

% dig mx
;; ANSWER SECTION:         20m34s IN MX    5         20m34s IN MX    5         20m34s IN MX    5

My ISP has three SMTP servers. See that number between the MX and the name of the mail server? That's the priority number. My ISP's mail servers all have the same priority; however, some ISPs use different priorities. If yours does, choose the mail server with the lowest priority number, as it has the highest priority.

Pages: 1, 2

Next Pagearrow