https://github.com/libdns/unifi
UniFi Network implementation for libdns
https://github.com/libdns/unifi
libdns unifi
Last synced: 29 days ago
JSON representation
UniFi Network implementation for libdns
- Host: GitHub
- URL: https://github.com/libdns/unifi
- Owner: libdns
- License: mit
- Created: 2026-02-02T19:04:09.000Z (4 months ago)
- Default Branch: main
- Last Pushed: 2026-04-16T17:06:47.000Z (about 2 months ago)
- Last Synced: 2026-05-02T20:40:00.717Z (about 1 month ago)
- Topics: libdns, unifi
- Language: Go
- Homepage: https://pkg.go.dev/github.com/libdns/unifi
- Size: 29.3 KB
- Stars: 2
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# UniFi for [`libdns`](https://github.com/libdns/libdns)
[](https://pkg.go.dev/github.com/libdns/unifi)
This package implements the [libdns interfaces](https://github.com/libdns/libdns) for [UniFi Network](https://developer.ui.com), allowing you to manage DNS records through the UniFi Network's DNS policy API.
## Supported Record Types
This provider supports the following DNS record types:
- **A** - IPv4 address records
- **AAAA** - IPv6 address records
- **CNAME** - Canonical name (alias) records
- **MX** - Mail exchange records (Without TTL)
- **TXT** - Text records (Without TTL)
- **SRV** - Service records (Without TTL)
## Configuration
The provider requires three pieces of configuration:
1. **API Key** - Your UniFi API authentication key
2. **Site ID** - The UUID of the UniFi site containing the DNS policies
3. **Host URL** - The base URL of your UniFi controller API
### Example Usage
```go
package main
import (
"context"
"log"
"net/netip"
"time"
"github.com/libdns/libdns"
"github.com/libdns/unifi"
)
func main() {
provider := unifi.Provider{
ApiKey: "your-api-key",
SiteId: "your-site-uuid",
BaseUrl: "https://192.168.1.1/proxy/network/integration/v1",
}
// List existing records
records, err := provider.GetRecords(context.Background(), "example.com")
if err != nil {
log.Fatal(err)
}
// Add a new A record
newRecords, err := provider.AppendRecords(context.Background(), "example.com", []libdns.Record{
libdns.Address{
Name: "www",
IP: netip.MustParseAddr("192.0.2.1"),
TTL: 3600 * time.Second,
},
})
if err != nil {
log.Fatal(err)
}
}
```
## Getting Your Credentials
### API Key
1. Log into your UniFi Network Console
2. Navigate to **Integrations**
3. Create a new **API Key**
4. Set the key as your `UNIFI_API_KEY` environment variable or use it as `ApiKey` parameter
### Site ID
Execute the following request to retrive the ID of your sites:
```curl
curl -k -X GET 'https://YOU_UNIFI_NETWORK_CONTROLLER/proxy/network/integration/v1/sites' -H 'X-API-KEY: YOUR_API_KEY' -H 'Accept: application/json'
```
### Base URL
The base URL is the base path of your UniFi Network API endpoint:
- **Default**: `https://YOU_UNIFI_NETWORK_CONTROLLER/proxy/network/integration/v1` (replace IP with your device IP)
- **CloudKey/Controller**: `https://YOU_UNIFI_NETWORK_CONTROLLER:8443/proxy/network/integration/v1`