Skip to content

Commit

Permalink
Update, mention format specifiers
Browse files Browse the repository at this point in the history
Signed-off-by: Joachim Wiberg <[email protected]>
  • Loading branch information
troglobit committed Jul 27, 2024
1 parent bbd9265 commit 407b6c6
Showing 1 changed file with 37 additions and 11 deletions.
48 changes: 37 additions & 11 deletions _posts/2024-07-24-setting-hostname.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,49 @@ categories: [examples]
tags: [cli]
---

Notice how the hostname in the prompt does not change until the change
is committed by issuing the leave command.
A common task for initial setup of your operating system is to change
the hostname of a device. The default is a unique name composed from
the built-in default name suffixed by the last three octets of the base
MAC address.

```
admin@infix-c0-ff-ee-:/>
```

In this example the built-in name is `infix` and the last three octets
resemble my favorite morning drink. The built-in name depends on the
Infix build and can be [tailored to your product][0].

The hostname can be changed from the system configuration context:

```
admin@host:/> configure
admin@host:/config/> edit system
admin@host:/config/system/> set hostname example
admin@host:/config/system/> leave
admin@infix-c0-ff-ee:/> configure
admin@infix-c0-ff-ee:/config/> edit system
admin@infix-c0-ff-ee:/config/system/> set hostname example
admin@infix-c0-ff-ee:/config/system/> leave
admin@example:/>
```

The hostname is advertised over mDNS-SD in the `.local` domain. If
another device already has claimed the example.local CNAME, in our case,
mDNS will advertise a "uniqified" variant, usually suffixing with an
index, e.g., `example-1.local`. Use an mDNS browser to scan for
available devices on your LAN.
Notice how the hostname in the prompt does not change until the change
is committed by issuing the leave command.

There are a few format specifiers available:

- `%h`: built-in hostname, here `infix`
- `%i`: built-in identity, here `infix` (depends on branding)
- `%m`: last three octets of base MAC address (may be 00-00-00)
- `%%`: literal `%` character

One good reason to maintain a unique hostname, e.g., using `%m`, is that
it is advertised over mDNS-SD in the `.local` domain. If another device
already has claimed the `example.local` CNAME, mDNS will notice this and
advertise a "uniqified" variant, usually suffixing with an index, e.g.,
`example-1.local`. Use an mDNS browser to scan for available devices on
your LAN.

> Critical services like syslog, mDNS, LLDP, and similar that advertise
> the hostname, are restarted when the hostname is changed.
{: .prompt-info }


[0]: https://github.com/kernelkit/infix/blob/main/doc/branding.md

0 comments on commit 407b6c6

Please sign in to comment.