dnsclientconf

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

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

Go to latest
Published: Jul 7, 2015 License: MIT Imports: 4 Imported by: 2

README

dns-client-conf - Simple and portable cli tool and golang package for work with operating system dns client settings

GoDoc Build Status

Installation

To install dns-client-conf, please use go get.

Command line tool
$ go get github.com/ArtemKulyabin/dns-client-conf/cmd/dns-client-conf
...
$ dns-client-conf help
...
Package
$ go get github.com/ArtemKulyabin/dns-client-conf
...

Usage

Command line tool
$ sudo dns-client-conf add 8.8.8.8 8.8.4.4 # Google Public DNS
DNS servers added successfully
$ dns-client-conf show
8.8.8.8
8.8.4.4
...
$ sudo dns-client-conf add 77.88.8.8 77.88.8.1 # Yandex.DNS
DNS servers added successfully
$ dns-client-conf show
77.88.8.8
77.88.8.1
...
$ sudo dns-client-conf dhcp # Receive dns addresses by DHCP protocol
DNS servers received by DCHP protocol successfully
$ dns-client-conf show # My ISP provider DNS servers
141.105.32.88
141.105.32.89
127.0.1.1
...
Package
package main

import (
  "log"
  "github.com/ArtemKulyabin/dns-client-conf"
)

func main() {

  dnsconf := dnsclientconf.NewDNSConfigurator()

  addrs, err := dnsconf.GetNameServers()
  if err != nil {
    log.Fatal(err)
  }

  err = dnsconf.AddNameServers([]string{"8.8.8.8", "8.8.4.4"})
  if err != nil {
    log.Fatal(err)
  }

  err = dnsconf.DHCPNameServers()
  if err != nil {
    log.Fatal(err)
  }
}

Cross compilation

For cross compilation you may use the Gox. Example:

$ gox github.com/ArtemKulyabin/dns-client-conf/cmd/dns-client-conf
...

Operating system support

  • Linux, FreeBSD, OpenBSD, NetBSD, Darwin(OS X), Windows
Tested on
  • Ubuntu 14.04, FreeBSD 10.1, OpenBSD 5.6, NetBSD 6.1.5, OS X Yosemite 10.10.3, Windows 7

Documentation

Overview

Package dnsclientconf provides a portable interface for operating system dns client settings.

Index

Constants

View Source
const (
	ResolvConfigPath         = "/etc/resolv.conf"
	DhclientConfigPath       = "/etc/dhcp/dhclient.conf"
	DhclientConfigPathBackup = "/etc/dhcp/dhclient.conf.auto"
	InterfaceName            = ""
)

Variables

This section is empty.

Functions

This section is empty.

Types

type DNSConfigurator

type DNSConfigurator interface {
	GetNameServers() ([]net.IP, error)
	AddNameServers(addrs []net.IP) error
	DHCPNameServers() error
	ReloadNameServers() error
	SetInterface(iface *net.Interface)
}

DNSConfigurator is the interface that wraps the NameServers methods. In most cases all methods need Administrator priviledges(except GetNameServers).

GetNameServers is the method that returns the list of host dns addresses. Side effect free.

AddNameServers reads the list of ip addresses and changes host operating system dns settings. If you want cancel this method effect, please call DHCPNameServers.

DHCPNameServers is the method that revert previously configured name servers addresses. Generally applies dhcp protocol.

ReloadNameServers is the method that safety refresh dns settings.

func NewDNSConfigurator

func NewDNSConfigurator() DNSConfigurator

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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