FreeBSD is known to be very suitable for computer servers, from Netflix streaming to Whatsapp messaging as powerful examples. Some also use FreeBSD as a workstation OS. I am one of those using BSD on both camps, although I also use some GNU/Linux boxes for ‘trivial’ purposes. In modern times having an internet connection seems almost natural to westeners as if it were current water or electricity at the plug end. And as it happens with those sometimes the supply runs out for some reason.
Not having an internet connection at your workstation desk for one day is something you can easily overcome. One week is something you may be not thinking as a possibility but it can eventually happen if enough things go wrong. This happened to me but for a bit longer than a full month. A solution had to be found and obviously I’ve tried the traditional approach of connection to my machines on the internet somewhere else by moving my workstation to a place with connectivity. But that is not always an option nor a good solution. So what can one do to solve this simple «lack of internet»?
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.
Mobile devices, Android or iPhone, are capable of USB tethering. Another way to name it is Ethernet over USB. Among the protocols able to do this «magic» is RNDIS. And «Oh yes! Miracle!» FreeBSD makes use of it. So this means you can use your Android or Apple phone device to connect your FreeBSD box (provided it has USB 2.0 or 3.0) to the internet. Just imagine you are in a hotel connected to the wifi and it goes down and doesn’t come back again. You are at home doing your work and some works on the street cut the physical cable supplying the whole neighborhood. And you really need your connection, and you really use FreeBSD because even Linux is not an option for you because of jails, because of bhyve, because of you simply just use it. What to do?
If this is only going to be temporary follow what the handbook states and load the appropiate driver depending on your phone device. Then enable the tethering option on the phone so it starts «giving signal». After that grab your FreeBSD box and ask for an ip address through the new network interface. This whole thing means launching the next series of commands at the terminal.
This command loads the driver into the kernel. This will only last as long as the box is on. After rebooting it will no longer load this module. Launch them as root or make use of sudo or doas, whichever method you preffer.
# kldload if_urndis
Now let’s check it’s been loaded.
# kldstat | grep if_urndis
If output comes out in the form of if_urndis.ko, everything is fine and the kernel module is loaded so you will be able to make use of the driver. If it comes empty something has gone wrong.
Now after enabling the tethering over USB on your phone launch the following command to see a new network interface appears. For those new to the UNIX world and the terminal, you usually have one interface named em0 or similar and the loopback interface as well, called lo0. A third network interface should appear (unless your BSD box has several NICs so you will see something similar to em0, em1, emX and the loopback lo0). Something similar to this should appear after launching ‘ifconfig’.
# ifconfig
em0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
options=209b<RXCSUM,TXCSUM,VLAN_MTU,VLAN_HWTAGGING,VLAN_HWCSUM,WOL_MAGIC>
ether 50:65:f3:1f:7b:3c
hwaddr 50:65:f3:1f:7b:3c
inet 192.168.1.126 netmask 0xffffffff broadcast 192.168.1.126
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
media: Ethernet autoselect
status: no carrier
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> metric 0 mtu 16384
options=600003<RXCSUM,TXCSUM,RXCSUM_IPV6,TXCSUM_IPV6>
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x2
inet 127.0.0.1 netmask 0xff000000
nd6 options=21<PERFORMNUD,AUTO_LINKLOCAL>
groups: lo
ue0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether 02:0d:5b:0d:36:65
hwaddr 02:0d:5b:0d:36:65
inet 192.168.42.89 netmask 0xffffff00 broadcast 192.168.42.255
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
So as you see the new interface has appeared and its named ue0. In my case you already see an IP address, the inet 192.168.42.89 entry line. But you won’t see this in yours until you launch the following command.
# dhclient ue0
Now you should obtain an IP address from your phone device through the USB cable and the «miracle» of Ethernet through USB unveils before your eyes. To check this is really the case do the next two things.
One, do launch ‘ifconfig’ again and the ue0 interface should show an IP address.
# ifconfig ue0
ue0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> metric 0 mtu 1500
ether 02:0d:5b:0d:36:65
hwaddr 02:0d:5b:0d:36:65
inet 192.168.42.89 netmask 0xffffff00 broadcast 192.168.42.255
nd6 options=29<PERFORMNUD,IFDISABLED,AUTO_LINKLOCAL>
If you have an IP address, that means the inet line entry with some numbers, you’re on the good track. Now one last step before grabbing your browser or other terminal tab and ssh to any box out on the internet. Ping to any server, ip or website you know it’s online.
$ ping google.com
PING google.com (216.58.201.174): 56 data bytes
64 bytes from 216.58.201.174: icmp_seq=0 ttl=44 time=40.592 ms
64 bytes from 216.58.201.174: icmp_seq=1 ttl=44 time=40.851 ms
64 bytes from 216.58.201.174: icmp_seq=2 ttl=44 time=59.647 ms
^C
--- google.com ping statistics ---
3 packets transmitted, 3 packets received, 0.0% packet loss
round-trip min/avg/max/stddev = 40.592/47.030/59.647/8.922 ms
$
If you receive ICMP packets back and there is no packet loss you are now connected to the internet through your phone device.
Now the only thing to worry about is to have decent signal from your phone carrier. Obviously 3G or 4G is much better to have, specially if you need to browse. The demands for ssh or telnet connections on a terminal are much lower so with lower signal you will be ok. So this may save the day but… if you are offline I find difficult for you to read this article. So if you find it useful or may be in your tool box download it, copy it, make your own notes and keep it at hand just in case… you run out of internet connectivity.
Last but not least. If you want this kernel module to be permanent so it loads every time you boot and not having to setup the whole thing permanently just add the following entry on /boot/loader.conf file:
if_urndis_load="YES"
If you add this line the kernel module will load at every boot. You will still have to enable your tethering service on your phone, but for that you just need to slide your finger tips to the right setting. And you will have to manually call for an IP address with the ‘dhclient’ command.
PS: Sorry for the long tittle. But things turnet out this way. Now the world knows there is a how to connect a FreeBSD box to the internet through an Android device via an USB port.
If you find the articles in Adminbyaccident.com useful to you, please consider making a donation.
Use this link to get $200 credit at DigitalOcean and support Adminbyaccident.com costs.
Get $100 credit for free at Vultr using this link and support Adminbyaccident.com costs.
Mind Vultr supports FreeBSD on their VPS offer.