Monday, May 18, 2009

FreeBSD Network interfaces

FreeBSD Network interfaces
Nick Rogness nick@rogness.net

Introduction

So what is a network interface? In plain old english, it is a logical reference to underlying network hardware. They comprise the lowest layer of the networking subsystem, interacting with the actual transport hardware.

Network Interface Concepts

It is important to understand network interfaces as they are the key to talking to your network hardware (like Ethernet, token-ring,ATM,etc). Different network interfaces may support one or more different protocol families, such as TCP/IP, IPX, etc.
Ifconfig The main utility for inspecting and configuring a network interface is ifconfig. First lets look at viewing all interfaces:

# ifconfig -a
xl0: flags=8843 mtu 1500
options=3
inet 205.238.129.221 netmask 0xfffffffc broadcast 205.238.129.223
inet6 fe80::250:daff:fe77:cc77%xl0 prefixlen 64 scopeid 0x1
ether 00:50:da:77:cc:77
media: Ethernet autoselect (100baseTX )
status: active
lp0: flags=8810 mtu 1500
ppp0: flags=8010 mtu 1500
sl0: flags=c010 mtu 552
faith0: flags=8002 mtu 1500
lo0: flags=8049 mtu 16384
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x6
inet 127.0.0.1 netmask 0xff000000


Ah, it appears I have several interfaces: xl0,lp0,ppp0,sl0,faith0,and lo0. What do they all mean? First lets talk about the loopback interface, lo0. This is a special interface for communicating with itself. It always has the IP address 127.0.0.1. All of the other interfaces (except xl0) will be ignored for now but I will give a brief description:

lp0 -> printer interface
ppp0 -> PPP interface
sl0 -> slip interface
faith0 -> IPv6 interface


Now, xl0. I chose to look at xl0 because it is the logical reference to my ethernet network card I have installed in my machine. This is not to say that every network card in FreeBSD will be referenced by xl0. Unlike Linux, each corresponding Ethernet chipset driver is referenced differently in FreeBSD. A full list is located in the kernel LINT file. I happen to be using a 3com network card, for which the xl driver has been written. therefore, my network card is referenced by xl0, meaning the first 3com network card in the machine. If I added another 3com network card to my box, it would show up as xl1, add another and get xl2, etc, etc. I can get more information from the kernel dmesg.boot file like so:

# grep xl0 /var/run/dmesg.boot
xl0: <3Com 3c905C-TX Fast Etherlink XL> port 0x9000-0x907f mem 0xf6800000-0xf680007f irq 9 at device 10.0 on pci1
xl0: Ethernet address: 00:50:da:77:cc:77
miibus0: on xl0


This is what the kernel probe found at boot time.

Lets look again at just the xl0 ifconfig output:

# ifconfig xl0
xl0: flags=8843 mtu 1500
inet 205.238.129.221 netmask 0xfffffffc broadcast 205.238.129.223
inet6 fe80::250:daff:fe77:cc77%xl0 prefixlen 64 scopeid 0x1
ether 00:50:da:77:cc:77
media: Ethernet autoselect (100baseTX )
status: active


This tells us some interesting things. The first line show the interface flags . The flags basically say that this interfaces is UP. It is a BROADCAST type interface. It's running in SIMPLEX mode and MULTICAST is enabled. The mtu, or Maximum Transmission Unit, is set to 1500 bytes (standard for ethernet). The next line says inet 205.238.129.221 ... This is the IP address configuration line. inet (meaning IPv4 family) followed by the IP address, netmask and broadcast address configured on this ethernet interface. The next line inet6 deals with IPv6 (which I'm not covering). The next line ether 00:50:da:77:cc:77 tells you the ethernet MAC address. The next line media: ... refers to the media type and option of the network card. It appears my card is running at 100baseTX . This was picked up by the autoselect. You can, however, manually set your media type and different options associated with media (like duplex). To see what all media types are supported by your network card:

# ifconfig -m xl0
xl0: flags=8843 mtu 1500
options=3
capability list:
=3
inet 205.238.129.221 netmask 0xfffffffc broadcast 205.238.129.223
inet6 fe80::250:daff:fe77:cc77%xl0 prefixlen 64 scopeid 0x1
ether 00:50:da:77:cc:77
media: Ethernet autoselect (100baseTX )
status: active
supported media:
media autoselect
media 100baseTX mediaopt full-duplex
media 100baseTX
media 10baseT/UTP mediaopt full-duplex
media 10baseT/UTP
media 100baseTX mediaopt hw-loopback


Take special note of the media lines down at the bottom. To manually set them:

To set to 100BaseTX :

# ifconfig xl0 media 100baseTX

Or to set to 100BaseTX and run in full-duplex:

# ifconfig xl0 media 100baseTX mediaopt full-duplex

No comments: