How can I do DNS lookup in Go?

Go’s "net" package in the stdlib has standard DNS client functions. For example, given a domain name, you can look up IP addresses:

package main

import (

func main() {
	ips, err := net.LookupIP("")
	if err != nil {
		fmt.Fprintf(os.Stderr, "Could not get IPs: %v\n", err)
	for _, ip := range ips {
		fmt.Printf(" IN A %s\n", ip.String())

Go’s stdlib either uses the C stdlib (via cgo), or a pure Go DNS resolver. On my machine, it uses cgo, which you can see with:

$ GODEBUG=netdns=9 go run main.go
go package net: using cgo DNS resolver
go package net: hostLookupOrder( = cgo IN A IN A 2a00:1450:4009:80d::200e
I just released Vidrio, a free app for macOS and Windows to make your screen-sharing awesomely holographic. Vidrio shows your webcam video on your screen, just like a mirror. Then you just share or record your screen with Zoom, QuickTime, or any other app. Vidrio makes your presentations effortlessly engaging, showing your gestures, gazes, and expressions. #1 on Product Hunt. Available for macOS and Windows.

With Vidrio

With generic competitor

More by Jim

Tagged . All content copyright James Fisher 2017. This post is not associated with my employer. Found an error? Edit this page.