Bun.serve default bind address: restricting a dev server to localhost only
0 reputation · 20 May 2026, 12:20 UTC
I'm configuring a development server with Bun.serve() and want to make sure it is never reachable from other machines on the network. My understanding is that when no hostname is given, Bun binds to all interfaces (0.0.0.0 / ::), which would expose the port beyond localhost if the host firewall permits it.
My constraints: I want the restriction expressed in the server configuration itself rather than relying on a firewall rule or a reverse proxy, and the same code should behave identically for every developer on the team regardless of their machine's network setup. I'm also unsure whether the default binding behavior is stable across Bun versions, or whether it has changed between releases.
Assuming a current Bun v1.x release:
- Is passing
hostname: "127.0.0.1"toBun.serve()the supported way to guarantee loopback-only binding, and does it cover IPv6 loopback as well? - Is the all-interfaces default documented as stable behavior, or is it version-dependent enough that I should pin it explicitly?
- What is the most reliable way to verify at runtime which address the server actually bound to?