{"record":{"id":"fa039e449b324e45","repo":"bettercap/bettercap","slug":"error-reading-hosts-from-file-s-v","errorCode":null,"errorMessage":"error reading hosts from file %s: %v","messagePattern":"error reading hosts from file (.+?): (.+?)","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/dns_spoof/dns_spoof.go","lineNumber":128,"sourceCode":"\t} else if err, address = mod.IPParam(\"dns.spoof.address\"); err != nil {\n\t\treturn err\n\t} else if err, domains = mod.ListParam(\"dns.spoof.domains\"); err != nil {\n\t\treturn err\n\t} else if err, hostsFile = mod.StringParam(\"dns.spoof.hosts\"); err != nil {\n\t\treturn err\n\t} else if err, ttl = mod.StringParam(\"dns.spoof.ttl\"); err != nil {\n\t\treturn err\n\t}\n\n\tmod.Hosts = Hosts{}\n\tfor _, domain := range domains {\n\t\tmod.Hosts = append(mod.Hosts, NewHostEntry(domain, address))\n\t}\n\n\tif hostsFile != \"\" {\n\t\tmod.Info(\"loading hosts from file %s ...\", hostsFile)\n\t\tif err, hosts := HostsFromFile(hostsFile, address); err != nil {\n\t\t\treturn fmt.Errorf(\"error reading hosts from file %s: %v\", hostsFile, err)\n\t\t} else {\n\t\t\tmod.Hosts = append(mod.Hosts, hosts...)\n\t\t}\n\t}\n\n\tif len(mod.Hosts) == 0 {\n\t\treturn fmt.Errorf(\"at least dns.spoof.hosts or dns.spoof.domains must be filled\")\n\t}\n\n\tfor _, entry := range mod.Hosts {\n\t\tmod.Info(\"%s -> %s\", entry.Host, entry.Address)\n\t}\n\n\tif !mod.Session.Firewall.IsForwardingEnabled() {\n\t\tmod.Info(\"enabling forwarding.\")\n\t\tmod.Session.Firewall.EnableForwarding(true)\n\t}\n","sourceCodeStart":110,"sourceCodeEnd":146,"githubUrl":"https://github.com/bettercap/bettercap/blob/8eca2820f3c41d2004434ed5a291d87462caeeb7/modules/dns_spoof/dns_spoof.go#L110-L146","documentation":"Error wrapping in the dns_spoof module's Configure (module startup parameter handling): HostsFromFile failed while parsing the file given via dns.spoof.hosts (missing file, bad syntax, or lines that do not map to the configured address). The original error is wrapped with the file path and returned, aborting module configuration; Configure is invoked by Start.","triggerScenarios":"Thrown at modules/dns_spoof/dns_spoof.go:128 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the path in dns.spoof.hosts exists and is readable by the bettercap process","Fix syntax errors in the hosts file (each line must contain a valid hostname/IP mapping)","Check file permissions and, if run as root, that the path is not on an unmounted volume","Test the file with a minimal one-entry hosts file to isolate the failing line"],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"8eca2820f3c41d2004434ed5a291d87462caeeb7","analyzedAt":"2026-09-02T12:49:00.712Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T16:17:10.729Z"}