{"id":17354698,"url":"https://github.com/openmohan/lightdns","last_synced_at":"2025-04-14T23:10:37.144Z","repository":{"id":54399595,"uuid":"151525334","full_name":"openmohan/lightdns","owner":"openmohan","description":"A basic DNS Server (Work in progres)","archived":false,"fork":false,"pushed_at":"2021-02-20T14:14:52.000Z","size":11,"stargazers_count":44,"open_issues_count":3,"forks_count":8,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T11:11:37.505Z","etag":null,"topics":["dns","dns-server","godns"],"latest_commit_sha":null,"homepage":"https://medium.com/@openmohan/dns-basics-and-building-simple-dns-server-in-go-6cb8e1cfe461","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/openmohan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-10-04T05:58:52.000Z","updated_at":"2024-07-09T15:01:52.000Z","dependencies_parsed_at":"2022-08-13T14:30:56.244Z","dependency_job_id":null,"html_url":"https://github.com/openmohan/lightdns","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmohan%2Flightdns","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmohan%2Flightdns/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmohan%2Flightdns/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/openmohan%2Flightdns/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/openmohan","download_url":"https://codeload.github.com/openmohan/lightdns/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248975316,"owners_count":21192210,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dns","dns-server","godns"],"created_at":"2024-10-15T17:37:46.785Z","updated_at":"2025-04-14T23:10:37.123Z","avatar_url":"https://github.com/openmohan.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lightdns\r\n\r\nThis is a light weight DNS Server which serves A type record for now.\r\n\r\n## Installation\r\n`go get github.com/openmohan/lightdns`\r\n\r\n### Requirements\r\n* Go 1.90\r\n\r\n## Usage\r\n1. Import the package `\tlightdns \"github.com/openmohan/lightdns\"`\r\n2. Create a DNS Server `dns := lightdns.NewDNSServer(port_int)`\r\n3. Add Zone data using the function `AddZoneData`\r\n\r\n```dns.AddZoneData(zone, staticRecords, lookupFunction, ZoneType)```\r\n\r\n## Example\r\nIf the records data available we can code it and Add the zone data\r\n```\t\r\n\tvar googleRecords = map[string]string{\r\n\t\t\"mail.google.com\":  \"192.168.0.2\",\r\n\t\t\"paste.google.com\": \"192.168.0.3\",\r\n\t}\r\n\tdns.AddZoneData(\"google.com\", googleRecords, nil, lightdns.DNSForwardLookupZone)\r\n```\r\n\r\nor\r\n \r\nIf the data is not static and has to be taken from a DB or from any other sources or calculated dynamically then use lookup function.\r\nDefine a lookup function in the format \r\n\r\n`func lookupFunc(domain string) (ip string, err error)` ie: given a domain name string as parameter, IP string and error value has to be returned.\r\n```\r\n\tfunc lookupFunc(string) (string, error) {\r\n\t\t//Do some action\r\n\t\t//Get data from DB\r\n\t\t//Process it further more\r\n\t\treturn \"192.2.2.1\", nil\r\n\t}\r\n\tdns.AddZoneData(\"amazon.com\", nil, lookupFunc, lightdns.DNSForwardLookupZone)\r\n```\r\n4. Start the DNS Server by `dns.StartAndServe()`\r\n\r\n# Complete Example\r\n```\r\npackage main\r\n\r\nimport (\r\n\tlightdns \"github.com/openmohan/lightdns\"\r\n)\r\n\r\nvar records = map[string]string{\r\n\t\"mail.amazon.com\":  \"192.162.1.2\",\r\n\t\"paste.amazon.com\": \"191.165.0.3\",\r\n}\r\n\r\nfunc lookupFunc(string) (string, error) {\r\n\t//Do some action\r\n\t//Get data from DB\r\n\t//Process it further more\r\n\treturn \"192.2.2.1\", nil\r\n}\r\n\r\nfunc main() {\r\n\tvar googleRecords = map[string]string{\r\n\t\t\"mail.google.com\":  \"192.168.0.2\",\r\n\t\t\"paste.google.com\": \"192.168.0.3\",\r\n\t}\r\n\tvar microsoftRecords = map[string]string{\r\n\t\t\"mail.microsoft.com\":  \"192.168.0.78\",\r\n\t\t\"paste.microsoft.com\": \"192.168.0.25\",\r\n\t}\r\n\tdns := lightdns.NewDNSServer(1234)\r\n\tdns.AddZoneData(\"google.com\", googleRecords, nil, lightdns.DNSForwardLookupZone)\r\n\tdns.AddZoneData(\"microsoft.com\", microsoftRecords, nil, lightdns.DNSForwardLookupZone)\r\n\r\n\t/* Incase if the records are not static or to be taken from DB or from any other sources\r\n\tlookupFunc method can be used.append*/\r\n\tdns.AddZoneData(\"amazon.com\", nil, lookupFunc, lightdns.DNSForwardLookupZone)\r\n\tdns.StartAndServe()\r\n}\r\n\r\n```\r\n\r\n## Work in progress\r\n### Support for\r\n1. MX, AAAA, SOA and other records\r\n2. Reverse lookup zone\r\n\r\n### Code\r\n 1. Use goroutines for optimizing the speed\r\n 2. Unit Test Cases\r\n 3. Logging mechanism for monitoring and debugging\r\n 4. Error handling\r\n\r\n\r\n## Contributing\r\nPull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.\r\n\r\n\r\n## License\r\n[MIT](https://choosealicense.com/licenses/mit/)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenmohan%2Flightdns","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fopenmohan%2Flightdns","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fopenmohan%2Flightdns/lists"}