DNS Resolution

Access your dev services by hostname instead of port numbers. Map myapp-api.local to your service with zero configuration.

10 min read Tutorial 6 of 8 Intermediate

Port Daddy can register DNS records for your services and optionally write them to /etc/hosts for OS-level resolution. This means you can access myapp-api.local in your browser instead of remembering localhost:3100.

Register DNS Records

When claiming a port, add --dns to auto-register a DNS record:

$ pd claim myapp:api --dns
Port 3100 assigned to myapp:api
DNS: myapp-api.local

Or register DNS separately:

$ pd dns register myapp:api --hostname api.local
$ pd dns list
$ pd dns status

Enable /etc/hosts Resolution

For OS-level resolution (so browsers and curl can use hostnames):

$ sudo pd dns setup     # adds managed section to /etc/hosts
$ pd dns sync           # writes current DNS records
$ pd dns status         # verify resolver is active

Port Daddy adds a clearly marked section to /etc/hosts:

# === PORT DADDY DNS (managed, do not edit) ===
127.0.0.1  myapp-api.local
127.0.0.1  myapp-web.local
# === END PORT DADDY DNS ===

Teardown

$ sudo pd dns teardown  # removes entries from /etc/hosts

A backup of /etc/hosts is created automatically before any modifications.

SDK Usage

const pd = new PortDaddy();
await pd.dnsRegister('myapp:api', { hostname: 'api.local' });
const records = await pd.dnsList();
await pd.dnsSetup();   // requires sudo
await pd.dnsSync();