DEV Community

Cover image for What Is mDNS? Access Devices on Your Local Network by Name
Rijul Rajesh
Rijul Rajesh

Posted on

What Is mDNS? Access Devices on Your Local Network by Name

Hello, I'm Rijul. I'm building git-lrc, a micro AI code reviewer that runs on every commit. It's free and source-available on GitHub. Star git-lrc to help more developers discover the project. Do give it a try and share your feedback

Have you ever seen devices on a local network being accessed using a name instead of an IP address?

When I first came across this, I found it pretty interesting.

That technology is called mDNS, or Multicast DNS.

It allows devices on the same local network to discover and communicate with each other using names instead of IP addresses, without requiring a traditional DNS server.

A Simple Example

Suppose your PC has this IP address:

192.168.1.20
Enter fullscreen mode Exit fullscreen mode

And its hostname is:

my-pc.local
Enter fullscreen mode Exit fullscreen mode

Your phone is connected to the same network and has:

192.168.1.30
Enter fullscreen mode Exit fullscreen mode

Normally, if you want to access a web application running on port 3000 on your PC, you might use:

http://192.168.1.20:3000
Enter fullscreen mode Exit fullscreen mode

With mDNS, you can instead use:

http://my-pc.local:3000
Enter fullscreen mode Exit fullscreen mode

You don't need to remember the IP address.

The .local hostname is resolved to the correct device on the local network.

How Does Normal DNS Work?

With traditional DNS, the process looks roughly like this:

You
 ↓
DNS Server
 ↓
"What IP address belongs to example.com?"
 ↓
DNS Server looks up the address
 ↓
IP address returned
Enter fullscreen mode Exit fullscreen mode

The DNS server maintains or retrieves the mapping between a hostname and an IP address.

For example:

example.com → 93.184.216.34
Enter fullscreen mode Exit fullscreen mode

But mDNS works differently.

There isn't a central DNS server that needs to know the address of every device on your local network.

How Does mDNS Work?

Let's say your phone wants to find:

my-pc.local
Enter fullscreen mode Exit fullscreen mode

It can send a multicast query asking:

"Who has my-pc.local?"
Enter fullscreen mode Exit fullscreen mode

The request is sent to the local network.

The PC that owns that hostname responds:

"That's me. I'm 192.168.1.20."
Enter fullscreen mode Exit fullscreen mode

The basic flow looks like this:

Phone
  ↓
"Who has my-pc.local?"
  ↓
Local network
  ↓
PC
  ↓
"That's me. I'm 192.168.1.20"
Enter fullscreen mode Exit fullscreen mode

The phone can then connect to the PC using the returned IP address.

Where Does Multicast Come In?

The M in mDNS stands for Multicast.

For IPv4, mDNS uses the multicast address:

224.0.0.251
Enter fullscreen mode Exit fullscreen mode

You can think of this address as a specific multicast group on the local network.

The devices communicate through this group:

                 Wi-Fi / LAN
                     |
          ┌──────────┼──────────┐
          ↓          ↓          ↓
         PC        Phone      Laptop
          |          |          |
          └──── 224.0.0.251 ───┘
Enter fullscreen mode Exit fullscreen mode

When a device sends an mDNS query to 224.0.0.251, devices listening to that multicast group can receive it.

So if your phone asks:

"Who has my-pc.local?"
Enter fullscreen mode Exit fullscreen mode

the PC can hear the request and respond because it owns that hostname.

Why Is This Useful?

mDNS is particularly useful on local networks where devices need to discover each other without requiring you to manually configure DNS.

For example:

http://my-pc.local:3000
ssh my-pc.local
Enter fullscreen mode Exit fullscreen mode

This is useful for things like:

  • Accessing development servers
  • Connecting to computers on your home network
  • Device discovery
  • Printers and other network devices
  • Local development and testing

You don't have to keep track of an IP address that might change.

Wrapping Up

mDNS is essentially DNS for your local network, without requiring a traditional DNS server.

Instead of asking a central DNS server:

"What IP belongs to this hostname?"
Enter fullscreen mode Exit fullscreen mode

a device can ask the local network:

"Who has this hostname?"
Enter fullscreen mode Exit fullscreen mode

The device that owns the name responds with its IP address.

And that's the basic idea behind mDNS.

See you in another article.

AI agents write code fast. They also silently remove logic, change behavior, and introduce bugs -- without telling you. You often find out in production.

git-lrc fixes this. It hooks into git commit and reviews every diff before it lands. 60-second setup. Completely free.

Any feedback or contributors are welcome! It's online, source-available, and ready for anyone to use.

Give it a ⭐ star on Github

Top comments (0)