nexns

package module
v0.0.0-...-ddd4ab3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 10, 2024 License: MIT Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

NexNS CoreDNS Plugin

NexNS CoreDNS Plugin 是一个与 NexNS Controller 协同工作的 CoreDNS 插件,旨在提供开箱即用的 DNS 解析服务。与传统 DNS 解决方案不同,NexNS CoreDNS Plugin 通过与 NexNS Controller 集成,实现了更灵活、可扩展且安全的 DNS 解析。

特点

  • 集成 NexNS Controller: 所有名称记录都由 NexNS Controller 管理和同步,解决了传统 DNS Zone Transfer 协议的各种限制。
  • 动态 DNS 记录管理: 实现了实时的 DNS 记录管理,使得修改和更新 DNS 记录变得更加简便。
  • 源地址过滤: 支持根据请求源地址返回不同的 DNS 记录,轻松区分返回局域网和互联网查询结果。
  • 开箱即用: 简单易用的配置和安装步骤,使得 NexNS CoreDNS Plugin 能够快速投入生产环境。

使用步骤

  1. 下载 CoreDNS:

    git clone https://github.com/coredns/coredns.git
    
  2. 编辑 plugin.cfg :

    请确保nexns位于forward、alternate等插件前,否则轮不到nexns来处理就已经返回查询结果。

    log:log
    nexns:github.com/JourneyBean/nexns-coredns-plugin
    forward:forward
    
  3. 编译:

    make gen && make
    
  4. 编辑 Corefile :

    . {
        log
        # cache # 注意:如果需要基于源地址返回不同记录,请不要前置缓存!NexNS提前将所有记录保存在内存,因此也无需担忧其查询速度。
        nexns {
            controller http://localhost:8000
        }
        cache
        forward . 192.168.1.1:53
    }
    
  5. 运行:

    ./coredns -conf Corefile -p 53
    

使用示例

$ dig A example.com. @127.0.0.1 -p 53 +short
1.2.3.4

$ dig A example.com. @192.168.1.123 -p 53 +short
2.3.4.5

打包

  • Debian/Ubuntu
  • OpenWRT
  • Archlinux

待补充

贡献

待补充

许可证

MIT许可,详见LICENSE。

Documentation

Index

Constants

View Source
const MaxPacketSize = 512
View Source
const MaxTxtRecordSize = 255

Variables

This section is empty.

Functions

This section is empty.

Types

type Domain

type Domain struct {
	ID      int    `json:"id"`
	Name    string `json:"domain"`
	Mname   string `json:"mname"`
	Rname   string `json:"rname"`
	Serial  string `json:"serial"`
	Refresh int    `json:"refresh"`
	Retry   int    `json:"retry"`
	Expire  int    `json:"expire"`
	TTL     int    `json:"ttl"`
}

Domain 包含了域名、SOA、DNSSEC信息

type DomainData

type DomainData struct {
	Domain Domain
	Zones  []Zone
}

DomainData 包含了一个域下的所有信息

type NexnsPlugin

type NexnsPlugin struct {
	Next          plugin.Handler
	ControllerURL string
	ClientId      string
	ClientSecret  string
	Database      Trie
}

func (*NexnsPlugin) Init

func (p *NexnsPlugin) Init() error

func (*NexnsPlugin) Name

func (p *NexnsPlugin) Name() string

func (*NexnsPlugin) RequestWithCredentials

func (p *NexnsPlugin) RequestWithCredentials(url string) (*http.Response, error)

func (*NexnsPlugin) ServeDNS

func (p *NexnsPlugin) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error)

type RRSet

type RRSet struct {
	ID      int      `json:"id"`
	Name    string   `json:"name"`
	Type    string   `json:"type"`
	Records []Record `json:"records"`
}

RRSet 包含了DNS资源记录集的信息

type Record

type Record struct {
	ID   int    `json:"id"`
	TTL  int    `json:"ttl"`
	Data string `json:"val"`
}

Record 包含了DNS资源记录的信息

type Trie

type Trie struct {
	// contains filtered or unexported fields
}

Trie represents the Trie data structure

func BuildTrie

func BuildTrie(data []DomainData) *Trie

BuildTrie builds a Trie from a list of DomainData

func (*Trie) Delete

func (t *Trie) Delete(domain string)

delete, domain must be exact

func (*Trie) Insert

func (t *Trie) Insert(domainData *DomainData)

Insert inserts a domain into the Trie

func (*Trie) Search

func (t *Trie) Search(domain string) *DomainData

Search searches for a domain in the Trie and returns the corresponding DomainData 从根开始,最长匹配

type TrieNode

type TrieNode struct {
	// contains filtered or unexported fields
}

TrieNode represents a node in the Trie

type WSNotification

type WSNotification struct {
	Type   string `json:"type"`
	Action string `json:"action"`
	Domain int    `json:"domain"`
}

type Zone

type Zone struct {
	ID     int      `json:"id"`
	Name   string   `json:"name"`
	Rules  []string `json:"rules"`
	RRsets []RRSet  `json:"rrsets"`
}

Zone 包含了区域(zone)的规则信息

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址