To reduce bot traffic you must login to view /lordwelch/gokrazy/commit/edba3d33ffa9ec9d281a9073309fa9f72575ab97?files=docs%2Fquickstart%2Findex.html.
The GitHub login only links via username.

Files
2024-09-09 18:01:25 +02:00

4.1 KiB
Raw Permalink Blame History

title, menuTitle, weight
title menuTitle weight
DHCP Client DHCP Client 21

Each gokrazy instance comes with a built-in DHCP client (see Instance Config → GokrazyPackages for more details on system packages) to set the IP address after obtaining a DHCPv4 lease from the local networks DHCP server.

Network Interfaces

The gokrazy DHCP client by default runs for eth0. If you want to use a different network interface, perhaps a USB ethernet adapter, you can set the -interface command-line flag:

{{< highlight json "hl_lines=10-14" >}} { "Hostname": "dynamic", "Packages": [ "github.com/gokrazy/fbstatus", "github.com/gokrazy/hello", "github.com/gokrazy/serial-busybox", "github.com/gokrazy/breakglass", ], "PackageConfig": { "github.com/gokrazy/gokrazy/cmd/dhcp": { "CommandLineFlags": [ "-interface=enp0s58" ] } } } {{< /highlight >}}

If you configure gokrazy to connect to a WiFi network, the gokrazy/wifi package will run another instance of the gokrazy DHCP client with the -interface=wlan0 flag set.

Static Network Configuration

If you want the DHCP client to not actually fetch a lease, but apply a statically supplied network configuration instead, you can set the -static_network_config flag to the name of a file which contains a JSON-encoded DHCP lease in rtr7/dhcp4.Lease format, for example:

{
  "IP":      "192.168.178.2",
  "Netmask": "",
  "Router":  "192.168.178.1",
  "DNS":     ["192.168.178.1", "8.8.8.8"]
}

Specifically, the following fields are currently respected:

  • IP+Netmask
  • Router
  • DNS

You can configure the gokrazy DHCP client to pick up this configuration by setting Package config: Command-line flags and Package config: Extra files:

{{< highlight json "hl_lines=10-17" >}} { "Hostname": "dynamic", "Packages": [ "github.com/gokrazy/fbstatus", "github.com/gokrazy/hello", "github.com/gokrazy/serial-busybox", "github.com/gokrazy/breakglass" ], "PackageConfig": { "github.com/gokrazy/gokrazy/cmd/dhcp": { "CommandLineFlags": [ "-static_network_config=/etc/gokrazy/static-dhcp-lease.json" ], "ExtraFilePaths": { "/etc/gokrazy/static-dhcp-lease.json": "static-dhcp-lease.json" } } } } {{< /highlight >}}

Interface priority

The gokrazy DHCP client automatically configures the route priority for default routes of ethernet interfaces (eth*) to 1, whereas on WiFi interfaces (wlan*), the priority is 5 (Linux prefers lower priorities).

This means you can configure your gokrazy instance to work with both, WiFi and wired network. Whenever a link is down, the gokrazy DHCP client changes its priority to 1024, meaning outgoing traffic will quickly switch away when an interface loses its link. In other words: When you un-plug the network cable, the device still works via WiFi.

If you need to influence the interfaces route priority, you can use the -extra_route_priority flag to add to the default priority. For example, to prefer sending traffic out via the WiFi interface if both WiFi and ethernet are connected, use:

{{< highlight json "hl_lines=10-14" >}} { "Hostname": "dynamic", "Packages": [ "github.com/gokrazy/fbstatus", "github.com/gokrazy/hello", "github.com/gokrazy/serial-busybox", "github.com/gokrazy/breakglass", ], "PackageConfig": { "github.com/gokrazy/gokrazy/cmd/dhcp": { "CommandLineFlags": [ "-extra_route_priority=10" ] } } } {{< /highlight >}}