This page looks best with JavaScript enabled

Mobile USB tethering on FreeBSD

 ·  🎃 kr0m

Sooner or later all ISPs end up having problems and interrupting service to customers, it is in these moments when we need to have a plan B. In this article I will explain how to use the USB tethering of our phone to access the Internet through the mobile connection.

The first step will be to enable tethering on the phone:



We check through dmesg that our operating system has detected the new network interface:

dmesg

ugen0.10: <Xiaomi SDM660-MTP SN:4420871C> at usbus0
ugen0.10: <Xiaomi SDM660-MTP SN:4420871C> at usbus0 (disconnected)
ugen0.10: <Xiaomi SDM660-MTP SN:4420871C> at usbus0
urndis0 on uhub0
urndis0: <RNDIS Communications Control> on usbus0
ue0: <USB Ethernet> on urndis0
ue0: Ethernet address: XX:XX:XX:XX:XX:XX

We can also check it through ifconfig:

ifconfig ue0

ue0: flags=8802<BROADCAST,SIMPLEX,MULTICAST> metric 0 mtu 1500
	ether XX:XX:XX:XX:XX:XX
	nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

We request an IP address via DHCP:

dhclient ue0

DHCPDISCOVER on ue0 to 255.255.255.255 port 67 interval 4
DHCPOFFER from 192.168.42.129
DHCPREQUEST on ue0 to 255.255.255.255 port 67
DHCPACK from 192.168.42.129
bound to 192.168.42.35 -- renewal in 1799 seconds.

We check the status of the interface again to make sure we have been assigned an IP address:

ifconfig ue0

ue0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
	ether XX:XX:XX:XX:XX:XX
	inet 192.168.42.35 netmask 0xffffff00 broadcast 192.168.42.255
	nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>

We modify the default gateway by removing the existing one and assigning the DHCP server IP, which can be seen when we run the dhclient command.

route del default 192.168.69.200
route add default 192.168.42.129

We check that the default gateway is correct:

netstat -rn|grep default

default            192.168.42.129     UGS         ue0

Now we have access to the Internet through the mobile connection, an easy and quick way to check it is through fetch:


To return to the original state before enabling tethering, simply execute the following commands:

service netif restart
service routing restart

If you liked the article, you can treat me to a RedBull here