USB tethering: FreeBSD laptop with L5

When I connect my L5 to my beloved FreeBSD laptop with an USB-C cable, on both ends exists (L5: usb0) or come up (FreeBSD: ue0) a network interface:

ifconfig usb0
usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        ether 96:06:ad:58:63:9d  txqueuelen 1000  (Ethernet)
        RX packets 448488  bytes 31739673 (30.2 MiB)
        RX errors 6  dropped 0  overruns 0  frame 0
        TX packets 306592  bytes 3677180864 (3.4 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0


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
	inet6 fe80::3c07:40ff:fe6d:1391%ue0 prefixlen 64 scopeid 0x3
	media: Ethernet autoselect
	status: active
	nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>

but nothing else happens in the sense of DHCP; a dhcpclient is started on FreeBSD for this interface ue0.

I can use ifconfig ue0 10.0.1.1 on FreeBSD and on the L5 ifconfig 10.0.1.2 and can run fine ssh purism@10.0.1.2 from FreeBSD to the L5.

What could I do that the L5 gives an IP addr to usb0 and respends to the dhclient listening in FreeBSD on ue0?

UPDATE:

When I do the same USB-C connection using my MacBook Pro, IP addresses get assigned automatically as:

purism@pureos:~$ ifconfig usb0
usb0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST>  mtu 1500
        inet 192.168.33.2  netmask 255.255.255.0  broadcast 192.168.33.255
        inet6 fe80::4d93:bdb7:ac4b:698  prefixlen 64  scopeid 0x20<link>
        ether 96:06:ad:58:63:9d  txqueuelen 1000  (Ethernet)
        RX packets 1799784  bytes 111111162 (105.9 MiB)
        RX errors 18  dropped 0  overruns 0  frame 0
        TX packets 548389  bytes 7352130824 (6.8 GiB)
        TX errors 0  dropped 0 overruns 0  carrier 0  collisions 0

~ apitzm$ ifconfig en7
en7: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
	options=404<VLAN_MTU,CHANNEL_IO>
	ether 3e:07:40:6d:13:91
	inet6 fe80::18de:caef:aa2d:3bd6%en7 prefixlen 64 secured scopeid 0x13
	inet 192.168.33.1 netmask 0xffffff00 broadcast 192.168.33.255
	nd6 options=201<PERFORMNUD,DAD>
	media: autoselect (100baseTX <full-duplex>)
	status: active

This is because in the MacOS some DHCP services is started with

   #!/bin/sh
   #
   # start the DHCP server in MacOS
   # see also:
   # https://www.swissns.ch/site/2014/05/running-mac-os-xs-built-in-dhcp-server/
   # config file: /etc/bootpd.plist
   #
   # guru@unixarea.de, March 2023

   # start:
   #
   sudo /bin/launchctl load -w /System/Library/LaunchDaemons/bootps.plist

UPDATE 2:

In the past I did the same with an Ubuntu mobile phone (BQ E4.5), see my booklet here:

The phone have had the IP add 10.42.0.1 which means that DHCP was provided from the phone to the FreeBSD laptop.


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;
  option broadcast-address 10.5.5.31;
  default-lease-time 600;
  max-lease-time 7200;
}
...

Lines for /etc/rc.conf:

ifconfig_ue0="inet 10.5.5.26 netmask 255.255.255.224"
dhcpd_enable="YES"
dhcpd_ifaces="ue0"

And at the end we let devd(8) do its job when the USB-C connection is made
with this configuration:

/usr/local/etc/devd/l5.conf:

notify 1 {
	match "system"          "IFNET";
	match "subsystem"       "ue0";
	match "type"            "ATTACH";
	action "/usr/local/etc/devd/l5.sh";
};

/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



Now you can run from the laptop 

ssh purism@10.5.5.27

and from there back:

ssh guru@10.5.5.26

Hello @guido.gunther and @dos, to be able to SSH from my FreeBSD laptop over an USB-C connection between the Librem 5 and my laptop, I’ve had to setup a DHCP server on my laptop. I documented the exact procedure here in the posting USB tethering: FreeBSD laptop with L5 - #2 by guru

There are comments from members of the FreeBSD community who are questioning the setup and argument that the DHCP server should run in the L5 itself with only declaring in FreeBSD that the network interface in FreeBSD should get its IP addr from the L5 by DHCP. I’m attaching the mail below. Can someone with more Debian/L5 knowhow please comment on this. Thanks in advance.

Date: Wed, 15 Nov 2023 07:14:53 +0100 (GMT+01:00)
To: questions@freebsd.org
Cc: Matthias Apitz <guru@unixarea.de>
Subject: Re: USB tethering between FreeBSD and mobile phone (Debian OS)

Hi Matthias (and anyone who comes across this later),

The DHCP server should be run on the device capable of acting as an internet
gateway (in this case, the phone) or else the setup is backwards from every
setup I've come across in 25 years in IT. (In fact, your phone probably already
had dhcpd installed for exactly that reason.)

As an added benefit, nothing needs to be built or installed on the FreeBSD side,
and one line needs to be added to /etc/rc.conf, as previously explained.

Why swim against the current and make things more complex than they need to be?


1 Like

I don’t understand the question. You can easily set the phone up to be either a DHCP client or DHCP server, depending on what you want to achieve. Tethering cellular connection is not the only use case of USB networking, I’m often sharing the laptop’s connection with the phone. Nothing is “backwards”; if your configuration doesn’t match the use case you want to achieve, just reconfigure it. Switching between DHCP client and server on usb0 interface is just a matter of changing the state of a single dropdown in NetworkManager’s profile, and FreeBSD is completely irrelevant here as everything should be able to establish a connection via DHCP automatically with no additional configuration.

1 Like

Thanks for your feedback. Where do I do this switch exactly and how this will work without having the DHCP server installed?

1 Like

The default connection method in NetworkManager’s profile is “Automatic (DHCP)”, making it a DHCP client. Switching to “Shared to other computers” will make the phone act as a DHCP server instead. This is just a regular GNU/Linux machine, it works exactly the same as between two regular PCs.

1 Like

But in which app or config file I can do this switch. Sorry, but I’m not a Debian PC expert :slight_smile:

1 Like

Doesn’t matter, you have plenty of config frontends to choose from: gnome-control-center, nmtui, nmcli, nm-connection-editor to name a few… I also trust that you’ll have no trouble with finding information on how to use NetworkManager on the Internet :wink:

2 Likes

I used in the L5 the app nm-connection-editor and went through the configuration of the Ethernet connection which I just renamed from “Wired connection 1” to the name “usb0”. I can assign in the tab for IPv4 manually an addr, what I did as 10.0.1.1 netmask 255.255.255.0, which is visible afterwards with ip addr in that interface when USB-C connects the laptop.

I found no way to set with the app an option DHCP server. I can only configure that the IP for usb0 should fetched by DHCP (which I did not), an consequently the interface ue0 in the laptop remains without any IP addr on:

# dhclient ue0
DHCPDISCOVER on ue0 to 255.255.255.255 port 67 interval 5
DHCPDISCOVER on ue0 to 255.255.255.255 port 67 interval 7
DHCPDISCOVER on ue0 to 255.255.255.255 port 67 interval 7
...

@dos, please advice how to set DHCP server, best with a screenshot. Thanks.

I think his previous answer is: it’s a standard Linux computer. The internet tells you how to configure Linux (specifically Linux networking). Whether that answer is sufficient I don’t know.

He also suggests using NetworkManager. I can confirm that on my desktop computer, using Settings / Network / (connection)Settings / IPv4 … the option “shared to other computers” does exist. What that option does I can’t say but surely your starting point would be to follow that advice and use that option?

1 Like

I’ve found a good article here which explains the details based on nmcli which I would prefer because of its man page and because on the L5 small screen where the GUI tools a difficult to manage: Internet connection sharing with NetworkManager - Fedora Magazine

1 Like

I removed with the nm-connection-editor what I configured with the name “usb0” and did on cmd line from the terminal app:

purism@pureos:~$ nmcli connection add type ethernet ifname usb0 ipv4.method shared con-name local

purism@pureos:~$ nmcli device
DEVICE         TYPE      STATE         CONNECTION 
usb0           ethernet  connected     local      
wlan0          wifi      connected     tarara     
p2p-dev-wlan0  wifi-p2p  disconnected  --         
lo             loopback  unmanaged     --         
purism@pureos:~$ ip -o addr show usb0
2: usb0    inet 10.42.0.1/24 brd 10.42.0.255 scope global noprefixroute usb0\       valid_lft forever preferred_lft forever
2: usb0    inet6 fe80::f33f:f4d6:688f:9f8d/64 scope link noprefixroute \       valid_lft forever preferred_lft forever

On the laptop I used the devd to start on plugin of the cable dhclient ue0 and this gets an IP addr from the L5:

# dhclient ue0
DHCPREQUEST on ue0 to 255.255.255.255 port 67
DHCPACK from 10.42.0.1
bound to 10.42.0.28 -- renewal in 1800 seconds.

and SSH to purism@10.42.0.1 is fine too.

Thanks for the hints, @dos

1 Like

It sets DHCP server up and configures routing so it acts as a gateway.

2 Likes

probably including NAT too.

Check if DHCP is habilitado en ambos nĂşcleos para la comunicaciĂłn por cable.

Yes, NAT too:


I disconnected my laptop from any red and only used the USB-C
tethering to connect to Internet:

before tethering:

# ifconfig wlan0
wlan0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=0
	ether 90:48:9a:92:9e:43
	groups: wlan
	ssid "" channel 1 (2412 MHz 11b)
	regdomain 108 indoor ecm authmode OPEN privacy OFF txpower 20 bmiss 7
	scanvalid 60 wme burst bintval 0
	parent interface: ath0
	media: IEEE 802.11 Wireless Ethernet autoselect (autoselect)
	status: no carrier
	nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>

after tethering (IP addr to ue0 comes down via dhclient ue0):

# ifconfig -a
lo0: flags=1008049<UP,LOOPBACK,RUNNING,MULTICAST,LOWER_UP> metric 0 mtu 16384
	options=680003<RXCSUM,TXCSUM,LINKSTATE,RXCSUM_IPV6,TXCSUM_IPV6>
	inet 127.0.0.1 netmask 0xff000000
	inet6 ::1 prefixlen 128
	inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
	groups: lo
	nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
wlan0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
	options=0
	ether 90:48:9a:92:9e:43
	groups: wlan
	ssid "" channel 1 (2412 MHz 11b)
	regdomain 108 indoor ecm authmode OPEN privacy OFF txpower 20 bmiss 7
	scanvalid 60 wme burst bintval 0
	parent interface: ath0
	media: IEEE 802.11 Wireless Ethernet autoselect (autoselect)
	status: no carrier
	nd6 options=23<PERFORMNUD,ACCEPT_RTADV,AUTO_LINKLOCAL>
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.42.0.18 netmask 0xffffff00 broadcast 10.42.0.255
	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 in the laptop, default is the tethering link
to the L5:

Internet:
Destination        Gateway            Flags     Netif Expire
default            10.42.0.1          UGS         ue0
10.42.0.0/24       link#3             U           ue0
10.42.0.18         link#1             UHS         lo0
127.0.0.1          link#1             UH          lo0


SSH from the laptop to the L5 works fine:

$ ssh purism@10.41.0.1
Linux pureos 6.4.0-1-librem5 #1 SMP PREEMPT Fri Oct  6 00:42:44 UTC 2023 aarch64

You have mail.
Last login: Mon Nov 20 07:42:11 2023 from 10.42.0.18
inhibiting suspend ...
...
logout

DNS in the laptop:

$ cat /etc/resolv.conf

# Generated by resolvconf
nameserver 10.42.0.1

PING in the laptop to some Internet site:

$ ping www.muc.de
PING www.muc.de (193.149.48.8): 56 data bytes
64 bytes from 193.149.48.8: icmp_seq=0 ttl=56 time=29.705 ms
64 bytes from 193.149.48.8: icmp_seq=1 ttl=56 time=27.737 ms
64 bytes from 193.149.48.8: icmp_seq=2 ttl=56 time=31.455 ms
64 bytes from 193.149.48.8: icmp_seq=3 ttl=56 time=28.204 ms
...

running in the L5 a tcpdump for the above PING from the laptop
shows the NAT for the packages behind the wwan0 addr: 

tcpdump -n -i wwan0

17:53:39.269033 IP 10.137.136.208 > 193.149.48.8: ICMP echo request, id 13573, seq 78, length 64
17:53:39.361920 IP 193.149.48.8 > 10.137.136.208: ICMP echo reply, id 13573, seq 78, length 64
1 Like