summaryrefslogtreecommitdiff
path: root/content/bsd/switching-wifi-eth.md
blob: 4282d1a3748a175ae51da26f7f2113ae809cf19a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
+++
title = "Switching between WiFi and Ethernet on FreeBSD"
author = ["Michał Sapka"]
date = 2024-10-26T20:11:00+02:00
categories = ["bsd"]
draft = false
weight = 4001
primary_menu = "bsd"
image_dir = "bsd"
image_max_width = 600
abstract = "How to handle multiple network interfaces?"
[menu]
  [menu.bsd]
    weight = 4001
    identifier = "switching-between-wifi-and-ethernet-on-freebsd"
    parent = "freebsd-personal"
    name = "Switching between WiFI and Ethernet"
+++

**The problem**:
I have a laptop with built-in WiFi.
Say what you will about WiFi, it's always better to use the good, old cable connection.
I have bought myself a cheap, USB Ethernet adapter (Reltek) which is perfectly detected by FreeBSD, as per `ifconfig(8)`:

```shell
ue0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
      options=68009b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
      ether c8:4d:44:20:6a:1b
      inet 10.0.7.197 netmask 0xfffff800 broadcast 10.0.7.255
      media: Ethernet autoselect (1000baseT <full-duplex>)
      status: active
      nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
```

However, I don't want to remove the WiFi card, but FreeBSD insists on using it for all outgoing connections.


## Pre-requisites {#pre-requisites}

What we need to know:

-   names of devices (from `ifconfig(8)`). In my case, WiFi is `wlan0` while the Eth dongle is `ue0`
-   default route (from `netstat(1)`):
    ```shell
    netstat -rn | grep default
    ```

Write down the IP shown, in my case it's `10.0.1.1`.


## Netif {#netif}

Netif is FreeBSD's way to manage network devices. We will can disable WiFi:

```shell
service netif stop wlan0
```

And ensure the dongle (ue0) is enabled:

```shell
service netif restart ue0
```

At this point your WiFi is no longer enabled, and all traffic should go through Ethernet.
If everything works fine - you're done.


## Default route {#default-route}

Disabling a network interface removes its routes.
If you can't reach any location (try `ping(8)`) it may be that you are lacking default route.
We can check it via:

```shell
netstat -rn | grep default
```

If nothing is returned, your computer does't know to reach other machines.
Luckily, we can re-add it. Remember the address from earlier?

```shell
route add default 10.0.1.1
```

Now everything should work fine!


## Alternatives {#alternatives}

As per FreeBSD Guide, you can also try [link aggregation](https://docs.freebsd.org/en/books/handbook/advanced-networking/#network-aggregation).