# Need help tethering Raspberry Pi to FreeBSD



## canute4444 (Nov 8, 2021)

Hi,

I am trying to share network connection from my machine (FreeBSD 12.2-RELEASE-p10 amd64) to a Raspberry Pi that I have connected via USB (using Ethernet over USB)

I have the Raspberry Pi setup in OTG mode (using this) 
I followed instructions on how to tether (using this)

FreeBSD seems to recognize the RPi as an Ethernet Gadget and creates a network interface ue0

```
# dmesg
ugen0.3: <Linux 5.10.17+ with 20980000.usb RNDIS/Ethernet Gadget> at usbus0
cdce0 on uhub0
cdce0: <RNDIS Communications Control> on usbus0
cdce0: No valid alternate setting found
device_attach: cdce0 attach returned 6
cdce0 on uhub0
cdce0: <RNDIS Ethernet Data> on usbus0
cdce0: faking MAC address
ue0: <USB Ethernet> on cdce0
ue0: Ethernet address: 2a:c6:d4:1c:84:00
```

My FreeBSD machine has network connectivity through another existing interface re0. I'm trying to share this connection with the RPi. I created a Bridge bridge0 and added re0 and ue0 as members.

```
# ifconfig
re0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
        options=8209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC,LINKSTATE>
        ether b4:2e:99:a2:1e:7a
        media: Ethernet autoselect (1000baseT <full-duplex>)
        status: active
        nd6 options=9<PERFORMNUD,IFDISABLED>
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
        options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
        inet6 ::1 prefixlen 128
        inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
        inet 127.0.0.1 netmask 0xff000000
        groups: lo
        nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
pflog0: flags=0<> metric 0 mtu 33160
        groups: pflog
bridge0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 02:ce:c9:e6:51:00
        inet 192.168.1.51 netmask 0xffffff00 broadcast 192.168.1.255
        id 00:00:00:00:00:00 priority 32768 hellotime 2 fwddelay 15
        maxage 20 holdcnt 6 proto stp-rstp maxaddr 2000 timeout 1200
        root id 00:00:00:00:00:00 priority 32768 ifcost 0 port 0
        member: re0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
                ifmaxaddr 0 port 1 priority 128 path cost 55
        member: ue0 flags=143<LEARNING,DISCOVER,AUTOEDGE,AUTOPTP>
                ifmaxaddr 0 port 1 priority 128 path cost 200000
        groups: bridge
        nd6 options=9<PERFORMNUD,IFDISABLED>
ue0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> metric 0 mtu 1500
        ether 2a:67:bf:dd:85:00
        nd6 options=1<PERFORMNUD>
```

Unfortunately, the RPi doesn't see a working network connection and isn't able to access the FreeBSD machine.
On RPi, I see only this on usb0 interface

```
# ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 19  bytes 4328 (4.2 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 19  bytes 4328 (4.2 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 169.254.132.134  netmask 255.255.0.0  broadcast 169.254.255.255
        inet6 fe80::17ef:ce2c:caec:a21f  prefixlen 64  scopeid 0x20<link>
        ether ba:66:f8:a9:a6:27  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
```

Any pointers on what steps I am missing?


----------



## astyle (Nov 9, 2021)

canute4444 said:


> usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 169.254.132.134


The *169.254.x.x address* is one issue I'm spotting on the Pi. This address won't get you anywhere. So, on the Pi, you'll need to make sure that your usb0 connection has a *valid address like 192.168.1.x*. I think that can be achieved by telling the Pi to send a DHCP request to the FreeBSD machine: `# dhclient usb0`. Hope this helps


----------



## canute4444 (Nov 10, 2021)

astyle said:


> The *169.254.x.x address* is one issue I'm spotting on the Pi. This address won't get you anywhere. So, on the Pi, you'll need to make sure that your usb0 connection has a *valid address like 192.168.1.x*. I think that can be achieved by telling the Pi to send a DHCP request to the FreeBSD machine: `# dhclient usb0`. Hope this helps


Unfortunately, `# dhclient usb0` on the Pi doesn't seem to do anything. It actually hangs and nothing seems to change. The *169.254.x.x address* still doesn't change to *192.168.1.x* either.


----------



## SirDice (Nov 10, 2021)

The 169.254.0.0/16 address is a so-called link-local address. Some DHCP client implementations on Linux (and Windows) will default to a link-local address if it doesn't get a response to a DHCP request. This is part of the "zero-configuration networking" idea, you can just connect two hosts with a network and they'll magically figure out how to communicate with each other. On FreeBSD the DHCP client is just going to fail (timeout) and not set an IP address at all. Because you don't have a DHCP service set up you're going to need to use static addresses, or set up a DHCP service for this connection. 





__





						Link-local address - Wikipedia
					






					en.wikipedia.org
				




The 169.254.0.0/16 address range is just a normal IP range like every other IP range, including the RFC1918 addresses. Similar to the RFC1918 addresses they're not routed on the internet as they're supposed to be used locally only (hence the name link-local).


----------



## astyle (Nov 10, 2021)

canute4444 said:


> Unfortunately, `# dhclient usb0` on the Pi doesn't seem to do anything. It actually hangs and nothing seems to change. The *169.254.x.x address* still doesn't change to *192.168.1.x* either.


Well, in that case, just manually assign a static address to usb0, say 192.168.1.15. Then, on FreeBSD, ping that IP.


----------



## canute4444 (Nov 10, 2021)

SirDice said:


> The 169.254.0.0/16 address is a so-called link-local address. Some DHCP client implementations on Linux (and Windows) will default to a link-local address if it doesn't get a response to a DHCP request. This is part of the "zero-configuration networking" idea, you can just connect two hosts with a network and they'll magically figure out how to communicate with each other. On FreeBSD the DHCP client is just going to fail (timeout) and not set an IP address at all. Because you don't have a DHCP service set up you're going to need to use static addresses, or set up a DHCP service for this connection.
> 
> 
> 
> ...


I do have a DHCP server running at my Gateway (192.168.1.1) which is handing out IP addresses.
On my FreeBSD machine, re0 is directly connected to my Gateway

[*Gateway, DHCP Server*]  <->  re0  [*FreeBSD*]  ue0  <->  usb0 [*Pi*]

I thought *bridge0* having re0 and ue0 interface means that any machine connected to ue0 should be able to receive an IP address directly from Gateway.

In any case, even if I set a static IP address (192.168.1.15) on the Pi using /etc/dhcpcd.conf, I am not able to reach 192.168.1.15 from my FreeBSD machine

```
# ping 192.168.1.15
PING 192.168.1.15 (192.168.1.15): 56 data bytes
ping: sendto: Host is down
ping: sendto: Host is down
ping: sendto: Host is down
ping: sendto: Host is down
```

Static IP is getting set on Pi.

```
# ifconfig
lo: flags=73<UP,LOOPBACK,RUNNING>  mtu 65536
        inet 127.0.0.1  netmask 255.0.0.0
        inet6 ::1  prefixlen 128  scopeid 0x10<host>
        loop  txqueuelen 1000  (Local Loopback)
        RX packets 40  bytes 3744 (3.6 KiB)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 40  bytes 3744 (3.6 KiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.1.15  netmask 255.255.255.0  broadcast 192.168.1.255
        inet6 fe80::833b:1e3b:1fbf:5e21  prefixlen 64  scopeid 0x20<link>
        ether 7a:a5:5b:50:98:27  txqueuelen 1000  (Ethernet)
        RX packets 0  bytes 0 (0.0 B)
        RX errors 0  dropped 0  overruns 0  frame 0
        TX packets 0  bytes 0 (0.0 B)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0
```
 
Any idea how I can diagnose further?


----------

