{"record":{"id":"4a9c1eabb679e93c","repo":"rust-lang/mdBook","slug":"no-address-found-for","errorCode":null,"errorMessage":"no address found for {}","messagePattern":"no address found for (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/cmd/serve.rs","lineNumber":75,"sourceCode":"    let open_browser = args.get_flag(\"open\");\n\n    let address = format!(\"{hostname}:{port}\");\n\n    let update_config = |book: &mut MDBook| {\n        book.config\n            .set(\"output.html.live-reload-endpoint\", LIVE_RELOAD_ENDPOINT)\n            .expect(\"live-reload-endpoint update failed\");\n        set_dest_dir(args, book);\n        // Override site-url for local serving of the 404 file\n        book.config.set(\"output.html.site-url\", \"/\").unwrap();\n    };\n    update_config(&mut book);\n    book.build()?;\n\n    let sockaddr: SocketAddr = address\n        .to_socket_addrs()?\n        .next()\n        .ok_or_else(|| anyhow::anyhow!(\"no address found for {}\", address))?;\n    let build_dir = book.build_dir_for(\"html\");\n    let html_config = book.config.html_config().unwrap_or_default();\n    let file_404 = html_config.get_404_output_file();\n\n    // A channel used to broadcast to any websockets to reload when a file changes.\n    let (tx, _rx) = tokio::sync::broadcast::channel::<Message>(100);\n\n    let reload_tx = tx.clone();\n    let thread_handle = std::thread::spawn(move || {\n        serve(build_dir, sockaddr, reload_tx, &file_404);\n    });\n\n    let serving_url = format!(\"http://{address}\");\n    info!(\"Serving on: {}\", serving_url);\n\n    if open_browser {\n        open(serving_url);\n    }","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/rust-lang/mdBook/blob/dc21064fc21d955a0e1f67e65e336883c3e5260b/src/cmd/serve.rs#L57-L93","documentation":"`mdbook serve` resolves the --hostname/--port (or the address string) into a SocketAddr via ToSocketAddrs and takes the first result. If resolution yields no addresses, serving cannot proceed and this error is raised with the original address string.","triggerScenarios":"Running mdbook serve with a hostname that DNS cannot resolve (or no results from to_socket_addrs), e.g. `mdbook serve -n bad.host.example` or an unresolvable interface name; the iterator .next() is None.","commonSituations":"Typo in the --hostname flag; using a hostname only resolvable on another network (VPN/corporate DNS); offline machine with a hostname instead of 127.0.0.1/localhost; container without DNS configured.","solutions":["Use an explicit address like `mdbook serve -n 127.0.0.1 -p 3000` (or `localhost`) instead of an unresolvable hostname.","Check DNS/network connectivity: verify the hostname resolves (`getent hosts <host>` or `nslookup <host>`).","Correct the --hostname value or the address passed in the serve command/config."],"exampleFix":"// before\nmdbook serve --hostname mybox.internal --port 3000\n\n// after\nmdbook serve --hostname 127.0.0.1 --port 3000","handlingStrategy":"try-catch","validationCode":"// Pre-check address resolution\nrequire('dns').lookup(host, (err) => { if (err) console.error(`cannot resolve ${host}`); });","typeGuard":null,"tryCatchPattern":"// Rust\nmatch mdbook::cmd::serve::execute(args) {\n    Err(e) if e.to_string().starts_with(\"no address found\") => {\n        eprintln!(\"Unresolvable hostname; try --hostname 127.0.0.1: {e}\");\n        std::process::exit(1);\n    }\n    res => res,\n}","preventionTips":["Default to 127.0.0.1 or localhost for local serving.","Validate hostnames with DNS lookup before invoking mdbook serve.","Prefer numeric IPs in CI/containers where DNS may be unavailable."],"tags":["network","dns","serve","mdbook"],"backgroundTag":"no-address-found-for-host","analyzedSha":"dc21064fc21d955a0e1f67e65e336883c3e5260b","analyzedAt":"2026-09-01T10:15:12.134Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}