DEV Community

Alexander Sack
Alexander Sack

Posted on

Let's change the Avahi Hostname of a Pantavisor system

The Pantavisor Runtime system come with a container "pv-avahi" preinstalled.

pv-avahi is a simple container that Pantahub team ships for developer convenience. It publishes info that helps to link your Pantavisor powered device with your Pantahub Account on first boot and information about the device ID with URLs to the device details dashboard.

By default pv-avahi does not try to be smart about the hostname it puts into the avahi daemon for the host, so you would see something along the lines of this:

$ avahi-browse -arl
+ wlp2s0 IPv6 one                                           SFTP File Transfer   local
+ wlp2s0 IPv6 one                                           SSH Remote Terminal  local
= wlp2s0 IPv6 one                                           SFTP File Transfer   local
   hostname = [linux-1.local]
   address = [fe80::b66:3713:16db:4772]
   port = [22]
   txt = []
= wlp2s0 IPv6 one                                           SSH Remote Terminal  local
   hostname = [linux-1.local]
   address = [fe80::b66:3713:16db:4772]
   port = [22]
   txt = ["device-id=5f03098a7351ad000a736657" "pantahub=https://api.pantahub.com:443"]
+ wlp2s0 IPv4 one                                           SFTP File Transfer   local
+ wlp2s0 IPv4 one                                           SSH Remote Terminal  local
= wlp2s0 IPv4 one                                           SFTP File Transfer   local
   hostname = [linux-1.local]
   address = [10.50.0.1]
   port = [22]
   txt = []
= wlp2s0 IPv4 one                                           SSH Remote Terminal  local
   hostname = [linux-1.local]
   address = [10.50.0.1]
   port = [22]
   txt = ["device-id=5f03098a7351ad000a736657" "pantahub=https://api.pantahub.com:443"]

Of course, "linux-1.local" is very generic, so lets take a look how we can change that using Pantahubs config mechanism.

Step 1: Find your device and Open Pantahub Details page

To find your device, simply connect to the same network and use pvr scan command:

$ pvr dev scan
Scanning ...
    ID: 5e4bbc3b745f14000a4f22f7 (owned)
    Host: linux-1.local.
    IPv4: []
    IPv6: [fe80::db06:d4fd:bf42:e411]
    Port: 22
    Pantahub WWW: https://www.pantahub.com/u/_/devices/5e4bbc3b745f14000a4f22f7
    PVR Clone: https://api.pantahub.com:443/trails/5e4bbc3b745f14000a4f22f7

You see that we were able to discover our device. Now open the "Pantahub WWW" URL to get to the Pantahub Details page.

Alt Text

Step 2: Get an offline copy of your device through PVR

To get an offline copy of the device, simply copy the "Share URL" from the the website above and use pvr to retrieve your local copy, e.g. (replace the URL with the one from above)

$ pvr clone https://api.pantahub.com:443/trails/5e4bbc3b745f14000a4f22f7 mydeviceclone

This will clone the device' runtime state to your local disk. you can then edit it there, and once happy push the changes back to your device through Pantahub.

Step 3: add a Pantahub config file for the pv-avahi container that sets the hostname

In order to change the hostname through avahi, we simply replace /etc/hostname with a file that has the hostname we want to use.

To seed that config file simply do this:

$ cd mydeviceclone
$ mkdir -p _config/pv-avahi/etc/
$ echo "mynewhostname" > _config/pv-avahi/etc/hostname
$ pvr add
$ pvr commit
$ pvr post -m "add /etc/hostname to pv-avahi platform"

This will upload the changes to panthaub, which will sanity check it and on success make these changes available for the device to consume.

Step 3: Success - the new hostname

Once done, to validate our work simply use pvr scan again to see:

$ pvr dev scan
Scanning ...
    ID: 5e4bbc3b745f14000a4f22f7 (owned)
    Host: mynewhostname.local.
    IPv4: []
    IPv6: [fe80::db06:d4fd:bf42:e411]
    Port: 22
    Pantahub WWW: https://www.pantahub.com/u/_/devices/5e4bbc3b745f14000a4f22f7
    PVR Clone: https://api.pantahub.com:443/trails/5e4bbc3b745f14000a4f22f7

Summary

Changing the hostname announced on pv avahi is as simple as changing the /etc/hostname visible to the pv-avahi container. With pvr this is just a couple of commands away!

Discussion (0)