rust-lang/mdBook · error

no address found for

Error message

no address found for {}

What it means

`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.

Solutions

  1. Use an explicit address like `mdbook serve -n 127.0.0.1 -p 3000` (or `localhost`) instead of an unresolvable hostname.
  2. Check DNS/network connectivity: verify the hostname resolves (`getent hosts <host>` or `nslookup <host>`).
  3. Correct the --hostname value or the address passed in the serve command/config.

Example fix

// before
mdbook serve --hostname mybox.internal --port 3000

// after
mdbook serve --hostname 127.0.0.1 --port 3000
Defensive patterns

Strategy: try-catch

Validate before calling

// Pre-check address resolution
require('dns').lookup(host, (err) => { if (err) console.error(`cannot resolve ${host}`); });

Try / catch

// Rust
match mdbook::cmd::serve::execute(args) {
    Err(e) if e.to_string().starts_with("no address found") => {
        eprintln!("Unresolvable hostname; try --hostname 127.0.0.1: {e}");
        std::process::exit(1);
    }
    res => res,
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of rust-lang/mdBook@dc21064fc2 (2026-09-01). Data as JSON: /api/errors/4a9c1eabb679e93c. Report an issue: GitHub.

Appendix: source

Thrown at src/cmd/serve.rs:75

    let open_browser = args.get_flag("open");

    let address = format!("{hostname}:{port}");

    let update_config = |book: &mut MDBook| {
        book.config
            .set("output.html.live-reload-endpoint", LIVE_RELOAD_ENDPOINT)
            .expect("live-reload-endpoint update failed");
        set_dest_dir(args, book);
        // Override site-url for local serving of the 404 file
        book.config.set("output.html.site-url", "/").unwrap();
    };
    update_config(&mut book);
    book.build()?;

    let sockaddr: SocketAddr = address
        .to_socket_addrs()?
        .next()
        .ok_or_else(|| anyhow::anyhow!("no address found for {}", address))?;
    let build_dir = book.build_dir_for("html");
    let html_config = book.config.html_config().unwrap_or_default();
    let file_404 = html_config.get_404_output_file();

    // A channel used to broadcast to any websockets to reload when a file changes.
    let (tx, _rx) = tokio::sync::broadcast::channel::<Message>(100);

    let reload_tx = tx.clone();
    let thread_handle = std::thread::spawn(move || {
        serve(build_dir, sockaddr, reload_tx, &file_404);
    });

    let serving_url = format!("http://{address}");
    info!("Serving on: {}", serving_url);

    if open_browser {
        open(serving_url);
    }

View on GitHub (pinned to dc21064fc2)