Networking on a FreeBSD Laptop

Last edited on 2025-05-28 Tagged under  #freebsd   #bsd   #network 

Part of the "Exploring FreeBSD on a Laptop" series.

Tested on FreeBSD 14.2

During installation on my laptop (Thinkpad T480s), there was an opportunity to select and configure a network adapter identified by the FreeBSD installer. I chose to use the ethernet adapter and it was configured successfully.

After the first boot into the system, I manually configure the wireless adapter for an additional networking option. Finally, I combine the ethernet and wireless interfaces into a virtual interface to provide failover network capability should one of the interfaces become unavailable.



Ethernet Adapter

Identify the system's network adapters:

$ pciconf -lv | grep -A1 -B3 network
em0@pci0:0:31:6:        class=0x020000 rev=0x21 hdr=0x00 vendor=0x8086 device=0x15d7 subvendor=0x17aa subdevice=0x2258
    vendor     = 'Intel Corporation'
    device     = 'Ethernet Connection (4) I219-LM'
    class      = network
    subclass   = ethernet
iwm0@pci0:61:0:0:       class=0x028000 rev=0x78 hdr=0x00 vendor=0x8086 device=0x24fd subvendor=0x8086 subdevice=0x0010
    vendor     = 'Intel Corporation'
    device     = 'Wireless 8265 / 8275'
    class      = network

The text before the @ symbol minus the integer is the name of the driver controlling the device(s). In this case there is an ethernet adapter using em(4) and a wireless adapter using iwm(4).

As mentioned, ethernet was configured during installation. Use the ifconfig(8) command to get its current status:

$ ifconfig em0
em0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
	options=800020<JUMBO_MTU,HWSTATS>
  ...
	status: active
	nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

The adapter is currently UP and active. FreeBSD uses dhclient(8) as its DHCP client, which automatically retrieves and sets the IP address, netmask, and default router for the interface.

Wireless Adapter

After identifying my wireless adapter as iwm0, I assign the device to an interface:

# ifconfig wlan0 create wlandev iwm0

Output details of the newly created (inactive) interface:

$ ifconfig wlan0
wlan0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=0
        ether 98:3b:8f:31:d8:50
        groups: wlan
        ssid "" channel 1 (2412 MHz 11b)
        regdomain FCC country US authmode OPEN privacy OFF txpower 30
        bmiss 10 scanvalid 60 wme bintval 0
        parent interface: iwm0
        media: IEEE 802.11 Wireless Ethernet autoselect (autoselect)
        status: no carrier
        nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

Enable this interface to persist across reboots by using sysrc(8) to add to rc.conf:

# sysrc wlans_iwm0="wlan0"

Wireless Networks

Bring UP the currently inactive wireless interface:

# ifconfig wlan0 up

List available networks:

$ ifconfig wlan0 list scan

Once a network has been selected from the list, the connection and authentication is managed by wpa_supplicant(8). Connection details are stored in the wpa_supplicant.conf(5) file.

NOTE
Most wireless networks perform authentication with a password stored in the router.

Create/open the file for editing:

# vi /etc/wpa_supplicant.conf

Add the wireless network details. Example entry:

network={
        scan_ssid=1
        ssid="HomeWifi"
        psk="12345678"
}

Details:

  • scan_ssid is only needed if the network is hidden
  • ssid is the network name
  • psk is the network password

Save changes and exit.

To use a dynamic IP address with this interface, add to rc.conf:

# sysrc ifconfig_wlan0="WPA DHCP"

Restart the networking service:

# service netif restart

Run the ifconfig command and it should now display both network interfaces are UP and have been assigned IP addresses.

Subsequent wireless networks can be added to wpa_supplicant.conf either by editing the file directly or using wpa_passphrase(8) (or a network manager utility).

Virtual Interface

With the two network interfaces on the laptop confirmed working, its possible to combine them together in a failover configuration. This type of configuration uses the most preferred and available connection from a group of network interfaces, and the system switches automatically when the link state changes.

FreeBSD uses the lagg(4) interface to provide failover:

This mode sends and receives traffic only through the master port. If the master port becomes unavailable, the next active port is used. The first interface added to the virtual interface is the master port and all subsequently added interfaces are used as failover devices. If failover to a non-master port occurs, the original port becomes master once it becomes available again.

Example failover configuration

Using my laptop as an example, the ethernet interface em0 will serve as the master port and the wireless interface wlan0 will be the failover device. I combine the two interfaces into a virtual interface by overriding the ethernet interface MAC address with the MAC address of the wireless interface.

Determine the MAC address of the wireless interface:

$ ifconfig wlan0 | grep ether
        ether 98:3b:8f:31:d8:50

Now, change the MAC address of the Ethernet interface to match:

# ifconfig em0 ether 98:3b:8f:31:d8:50

Create the lagg interface and configure it to use em0 and wlan0:

# ifconfig lagg0 create
# ifconfig lagg0 up laggproto failover laggport em0 laggport wlan0

Display the virtual interface:

$ ifconfig lagg0

Start the DHCP client to obtain an IP address:

# dhclient lagg0

To preserve this configuration across reboots, open rc.conf for editing:

# vi /etc/rc.conf

Deactivate the current ifconfig_[interface] settings by commenting out the entries:

#ifconfig_em0="DHCP"
#ifconfig_wlan0="WPA DHCP"

Add the new settings (with the appropriate wireless MAC address):

ifconfig_em0="ether 98:3b:8f:31:d8:50"
ifconfig_wlan0="WPA"

NOTE
Available region definitions can be found in /etc/regdomain.xml.

Set the region for the correct parameters and channels for your wireless adapter:

create_args_wlan0="country US"

Configure the virtual interface:

cloned_interfaces="lagg0"
ifconfig_lagg0="up laggproto failover laggport em0 laggport wlan0 DHCP"

This is what it looks like all together:

wlans_iwm0="wlan0"
#ifconfig_em0="DHCP"
#ifconfig_wlan0="WPA DHCP"
ifconfig_em0="ether 98:3b:8f:31:d8:50"
ifconfig_wlan0="WPA"
create_args_wlan0="country US"
cloned_interfaces="lagg0"
ifconfig_lagg0="up laggproto failover laggport em0 laggport wlan0 DHCP"

Save changes and exit.

Reboot:

$ shutdown -r now

Run ifconfig and note that a single IP address is assigned to the lagg0 interface.

Test by disconnecting the ethernet cable (network access is maintained by wireless) and bring down a network interface and confirm failover to the other remaining one.

Good stuff!

Resources

You can like, share, or comment on this post on the Fediverse 💬

Thanks for reading! Read other posts?

» Next: X Window System on FreeBSD

« Previous: Brightness and Sound on FreeBSD