> ## Documentation Index
> Fetch the complete documentation index at: https://number0-improve-contact.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# DHT

DHT address lookup publishes and resolves endpoint records on the
[BitTorrent Mainline](https://en.wikipedia.org/wiki/Mainline_DHT) distributed hash
table. The records are the same signed records that
[DNS address lookup](/connecting/dns-address-lookup) uses. The difference is where they
are stored. DNS address lookup publishes them to a hosted server and resolves over DNS,
while DHT address lookup puts them on the BitTorrent Mainline DHT. That removes the
dependency on a hosted server: any endpoint can publish and resolve without a
central party, at the cost of slower lookups than DNS.

<Frame>
  <img src="https://www.iroh.computer/animations/publish-relay-dht.svg" alt="Bob publishes his signed record to several nodes of the Mainline DHT; Alice resolves it by querying several nodes" style={{ width: '100%' }} />
</Frame>

DHT address lookup is not enabled by default. It lives in the separate
[`iroh-mainline-address-lookup`](https://crates.io/crates/iroh-mainline-address-lookup)
crate, which you add alongside `iroh`.

```toml theme={null}
[dependencies]
iroh = "1"
iroh-mainline-address-lookup = "0.4"
```

Add the `DhtAddressLookup` to the endpoint with `Endpoint::builder`. You can run it
next to the default DNS address lookup, or build from `presets::Minimal` to use only the
DHT.

```rust theme={null}
use iroh::{Endpoint, endpoint::presets};
use iroh_mainline_address_lookup::DhtAddressLookup;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let endpoint = Endpoint::builder(presets::N0)
        .address_lookup(DhtAddressLookup::builder())
        .bind()
        .await?;
    // your code here
    Ok(())
}
```

DHT address lookup also combines well with [mDNS address lookup](/connecting/local-address-lookup)
for both global and local address lookup without depending on centralized infrastructure.

For the record format shared with DNS address lookup, see the
[Address Lookup concept page](/concepts/address-lookup).
