Re: USB tethering between FreeBSD and mobile phone (Debian OS)

From: Matthias Apitz <guru_at_unixarea.de>
Date: Wed, 15 Nov 2023 11:55:44 UTC
El día miércoles, noviembre 15, 2023 a las 02:19:23p. m. +0300, Odhiambo Washington escribió:

> On Wed, Nov 15, 2023 at 8:44 AM Matthias Apitz <guru@unixarea.de> wrote:
> 
> >
> > Just to end this thread:
> >
> >
> > How to tether the mobile phone Purism Librem 5 with FreeBSD
> > guru@unixarea.de, November 2023
> >
> > The Purism Librem 5 (L5) runs PureOS, a Debian variant, but no DHCP server.
> > When an USB-C cable connection between the laptop and the L5 is made, the
> > NetworkManager in the L5 sees the carrier in the network interface 'usb0'
> > and launches a DHCP client on the interface. All we have to do, or what
> > can be done, is launching a DHCP server on the interface 'ue0'. Here is
> > it's configuration.
> >
> > Build and install the port net/isc-dhcp44-server.
> >
> > We just use one of the existing example configuration from
> > /usr/local/etc/dhcpd.conf:
> >
> > ...
> > # A slightly different configuration for an internal subnet.
> > subnet 10.5.5.0 netmask 255.255.255.224 {
> >   range 10.5.5.26 10.5.5.30;
> >   option domain-name-servers ns1.internal.example.org;
> >   option domain-name "internal.example.org";
> >   option routers 10.5.5.1;
> >
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Whose IP is 10.5.5.1 ?? The phone or the FreeBSD box?
> If the phone is getting an IP address from the DHCP server running on the
> FreeBSD, that IP address is bound to change unless assigned statically by a
> DHCP reservation!

As I said: this config is just one of the examples in the file
dhcp.conf. I picked this up to get an addr pair in the range 
10.5.5.26 10.5.5.30. With this the FreeBSD gets assigned (static)
10.5.5.26 and the phone 10.5.5.27:

FreeBSD:

$ ifconfig ue0
ue0: flags=1008843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST,LOWER_UP> metric 0 mtu 1500
	options=80000<LINKSTATE>
	ether 3e:07:40:6d:13:91
	inet 10.5.5.26 netmask 0xffffffe0 broadcast 10.5.5.31
	inet6 fe80::3c07:40ff:fe6d:1391%ue0 prefixlen 64 scopeid 0x3
	media: Ethernet autoselect
	status: active
	nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>

$ netstat -rn
Routing tables

Internet:
Destination        Gateway            Flags     Netif Expire
default            10.49.211.1        UGS       wlan0
10.5.5.0/27        link#3             U           ue0
10.5.5.26          link#1             UHS         lo0
10.49.211.0/24     link#2             U         wlan0
10.49.211.252      link#1             UHS         lo0
127.0.0.1          link#1             UH          lo0


the value for ue0 comes from the devd script:

/usr/local/etc/devd/l5.sh

#!/bin/sh
#
ifconfig ue0 inet 10.5.5.26 netmask 255.255.255.224 
/usr/local/etc/rc.d/isc-dhcpd restart

phone:

purism@pureos:~$ ifconfig usb0
usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 10.5.5.27  netmask 255.255.255.224  broadcast 10.5.5.31
        inet6 fe80::4d93:bdb7:ac4b:698  prefixlen 64  scopeid 0x20<link>
        ether 96:06:ad:58:63:9d  txqueuelen 1000  (Ethernet)
        RX packets 1810569  bytes 112088858 (106.8 MiB)
        RX errors 72  dropped 0  overruns 0  frame 0
        TX packets 556250  bytes 7353668068 (6.8 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

purism@pureos:~$ netstat -rn
Kernel IP routing table
Destination     Gateway         Genmask         Flags   MSS Window  irtt Iface
0.0.0.0         10.5.5.1        0.0.0.0         UG        0 0          0 usb0
0.0.0.0         10.49.211.1     0.0.0.0         UG        0 0          0 wlan0
0.0.0.0         10.158.237.201  0.0.0.0         UG        0 0          0 wwan0
10.5.5.0        0.0.0.0         255.255.255.224 U         0 0          0 usb0
10.49.211.0     0.0.0.0         255.255.255.0   U         0 0          0 wlan0
10.158.237.192  0.0.0.0         255.255.255.240 U         0 0          0 wwan0


> This config is so in reverse that I fail to understand it.
> Is this intended for the FreeBSD box to access the Internet??

No, the FreeBSD has access to Internet via wlan0. This config is just to
allow SSH between the phone and FreeBSD. And the phone has access to
Internet through its wwan0 (data mobile).

	matthias

-- 
Matthias Apitz, ✉ guru@unixarea.de, http://www.unixarea.de/ +49-176-38902045
Public GnuPG key: http://www.unixarea.de/key.pub

I am not at war with Russia.
Я не воюю с Россией.
Ich bin nicht im Krieg mit Russland.