DHCP Client
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 network’s 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:
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.
NTP Servers
The DHCP client requests NTP servers (DHCP option 42) in addition to the usual IP, router and DNS options. If your DHCP server provides NTP servers, the gokrazy NTP client uses them automatically; otherwise it falls back to its default servers.
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:
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:
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 interface’s 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: