Klaus Zimmermann's Corner

How to force wired connection in FreeBSD 13 on a laptop

Quick note-to-self sort of post: I decided to plug my FreeBSD machine into the wired LAN cable. The WiFi connection is still going great, but I'd rather use the full Gigabit connection when I can. To my surprise, the moment after I connected and switched off the WiFi, however, all connectivity from the laptop died - couldn't even ping addresses out of my local network.

This is a little unexpected, since usually what happens is that the WiFi doesn't work while the cabled connection is a walk in the park (lack of drivers, not knowing how to configure wpa_supplicant and so). Never had the cabled connection let me down before when I was on Linux!

After wrestling a little with the problem, I eventually honed in on the problem: for some reason, FreeBSD wasn't setting up a route for the wired network em0, even if an IP address was assigned to it via DHCP! And so, I derived the fix:

# set down wifi to make sure only the cabled connection works:
ifconfig wlan0 down

# if no IP address yet, get one for your cabled interface:
dhclient em0

# now that we have an address, add a default route via the gateway:
# change this to your router's IP address:
route add default <192.168.X.X>

Now check the status of your routing table via the command netstat -r. It should be something like this:

Routing tables

Internet:
Destination        Gateway            Flags     Netif Expire
default            192.168.0.1        UGS         em0
localhost          link#2             UH          lo0
...

And there you have it! Everything should be working normally. Note that I wrote the steps to fix the issue in more or less a script form. This is on purpose: you could make a script of sorts out of this to "activate" wired connection mode, and its reverse (swapping the wlan0 and em0 interfaces) for the wireless one. Happy fast browsing!