summaryrefslogtreecommitdiff
path: root/content/bsd/switching-wifi-eth.md
diff options
context:
space:
mode:
Diffstat (limited to 'content/bsd/switching-wifi-eth.md')
-rw-r--r--content/bsd/switching-wifi-eth.md91
1 files changed, 91 insertions, 0 deletions
diff --git a/content/bsd/switching-wifi-eth.md b/content/bsd/switching-wifi-eth.md
new file mode 100644
index 0000000..4282d1a
--- /dev/null
+++ b/content/bsd/switching-wifi-eth.md
@@ -0,0 +1,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).