Skip to main content

DNS

c.DNS calls the API's DNS group. The DNS resolvers of each interface of the host.

Methods​

MethodReturnsPermissionDescription
Get(ctx, hostname, interfaceName)*Response[Collection[DnsEntry]]dns:readGet the DNS resolvers of an interface.
Update(ctx, hostname, input)*Response[Collection[DnsResult]]dns:writeSet the DNS resolvers of an interface.
Delete(ctx, hostname, interfaceName)*Response[Collection[DnsResult]]dns:writeDrop the DNS resolvers osapi set on an interface.

Get​

func (s *DNSService) Get(
ctx context.Context,
hostname string,
interfaceName string,
) (*Response[Collection[DnsEntry]], error)

Get the DNS resolvers of an interface.

Reads the servers and the search domains of the interface: resolvectl on Linux, with resolv.conf on a host that has no resolvers per interface, such as a container, and scutil on macOS.

It sends GET /api/node/{hostname}/dns/{interface_name}, and needs the permission dns:read.

The examples of the method's definition:

An interface with servers and a domain, go run dns.go get:

resp, err := c.DNS.Get(ctx, target, "osapi0")

A Mac, go run dns.go get-2:

resp, err := c.DNS.Get(ctx, target, "en0")

Update​

func (s *DNSService) Update(
ctx context.Context,
hostname string,
input DNSUpdateInput,
) (*Response[Collection[DnsResult]], error)

Set the DNS resolvers of an interface.

Writes a netplan file of the interface's own, such as /etc/netplan/osapi-dns-eth0.yaml for eth0, under the netplan definition that matches the interface, and applies it. A definition that matches several interfaces, such as cloud-init's all for en*, gives each of them the resolvers. An empty list keeps the interface's servers or domains, and an interface with no resolvers yet starts from none. override_dhcp drops the servers DHCP gives. It runs on the Debian family, and elsewhere, and in a container, reports skipped.

It sends PUT /api/node/{hostname}/dns/{interface_name}, and needs the permission dns:write.

The examples of the method's definition:

Set the servers of an interface, go run dns.go update:

resp, err := c.DNS.Update(ctx, target, client.DNSUpdateInput{
InterfaceName: "osapi0",
Servers: []string{"9.9.9.9"},
})

Set the search domains, and keep the servers, go run dns.go update-2:

resp, err := c.DNS.Update(ctx, target, client.DNSUpdateInput{
InterfaceName: "osapi0",
OverrideDHCP: true,
SearchDomains: []string{"corp.example"},
})

Delete​

func (s *DNSService) Delete(
ctx context.Context,
hostname string,
interfaceName string,
) (*Response[Collection[DnsResult]], error)

Drop the DNS resolvers osapi set on an interface.

Removes the interface's netplan file and applies what is left. An interface osapi set nothing on does not change.

It sends DELETE /api/node/{hostname}/dns/{interface_name}, and needs the permission dns:write.

The examples of the method's definition:

An interface osapi set, go run dns.go delete:

resp, err := c.DNS.Delete(ctx, target, "osapi0")

Types​

The fields of each type are the properties of its schema in the API's spec.

DNSUpdateInput​

FieldTypeDescription
InterfaceNamestringThe interface_name of the path. The interface, such as eth0, or a fact such as @fact.interface.primary.
OverrideDHCPboolUse only these servers: drop the ones DHCP gives.
SearchDomains[]stringThe search domains; the interface's own when empty.
Servers[]stringThe DNS servers, IPv4 or IPv6; the interface's own when empty.

DnsEntry​

FieldTypeDescription
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
SearchDomains[]stringThe search domains.
Servers[]stringThe DNS servers.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

DnsResult​

FieldTypeDescription
ChangedboolWhether the host changed.
ErrorstringError message if the agent failed.
HostnamestringHostname of the agent that produced this result.
InterfaceNamestringThe interface.
StatusRowStatusWhat happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

RowStatus​

What happened on the host: ok, the operation ran and succeeded; failed, it ran and did not succeed; skipped, the host's OS family does not support it; timeout, the host did not answer, so nobody knows whether it ran.

A string, one of ok, failed, skipped, timeout.

Example​

examples/sdk/client/dns.go runs each example of this page. With no argument, it lists them.