Weave Code
Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Dns Laravel Package

spatie/dns

spatie/dns is a PHP package that fetches DNS records via dig. Query all records for a domain or filter by type (A, AAAA, CNAME, MX, TXT, SRV, CAA, SOA, NS, PTR, DNSKEY, NAPTR) and read results through simple record objects.

View on GitHub
Deep Wiki
Context7

spatie/dns is a lightweight PHP package for fetching DNS records via the dig command. It provides a simple Dns class that queries any domain and returns records as objects implementing the Record interface, each exposing convenient methods like host() to inspect record data.

$dns = new Dns();
$dns->getRecords('spatie.be', ['A', 'CNAME']);
  • Supports A, AAAA, CNAME, NS, PTR, SOA, MX, SRV, TXT, DNSKEY, CAA, NAPTR
  • Fetch all records or filter by single/multiple types
  • Accepts string types or native DNS_* constants with bitwise flags
  • Clean record objects with helper accessors
Frequently asked questions about Dns
How do I install spatie/dns in a Laravel application?
Install it with composer require spatie/dns. There is no Laravel service provider, facade, config file, or auto-discovery because the package is framework-agnostic. You can use the Spatie\Dns\Dns class directly or bind it in your own service provider.
Does spatie/dns support Laravel 10, Laravel 11, and Laravel 12?
Spatie/DNS is a framework-agnostic PHP 8.0+ library, so it does not declare Laravel version constraints. It will work with any Laravel version that runs on PHP 8.0 or newer. Laravel integration is entirely up to your application code.
What DNS record types can spatie/dns retrieve?
It can retrieve A, AAAA, CNAME, NS, PTR, SOA, MX, SRV, TXT, DNSKEY, CAA, and NAPTR records. You can request all records for a domain or filter by one or more types. Records are returned as typed objects with accessors such as host(), ttl(), type(), and A::ip().
How do I get only MX or TXT records with spatie/dns?
Pass the record type as the second argument to getRecords(), for example getRecords('example.com', 'MX') or getRecords('example.com', 'TXT'). You can also pass an array like ['A', 'CNAME'] or use PHP DNS constants such as DNS_MX. The method returns only the matching record objects.
Do I need dig installed to use spatie/dns?
Dig is strongly recommended and is the primary handler. If dig is missing, the package falls back to PHP's native dns_get_record(), but behavior is not identical: retry and timeout controls are unavailable and parsing or metadata fidelity may differ. In Docker, Vapor, Lambda, or distroless images, install dnsutils or bind-utils explicitly.
How do I set a custom nameserver, timeout, or retry count in spatie/dns?
Use the fluent methods on the Dns class: useNameserver(), setTimeout(), and setRetries(). For example, call useNameserver('1.1.1.1') before getRecords(). These options apply to the dig handler and are not behaviorally identical under the native dns_get_record() fallback.
Is spatie/dns safe to use on the Laravel request hot path?
No, it is a poor fit for request-path DNS lookups. Each getRecords() call shells out through symfony/process, forking a process and typically taking tens of milliseconds with no connection reuse or batching. Move bulk domain verification or enrichment work to queued jobs or scheduled tasks.
How do I test Laravel code that uses spatie/dns?
Wrap the package behind your own interface or adapter and fake that in tests. Spatie/DNS does not ship a Laravel fake, but its small API makes a one-class wrapper practical. You can also use the handler abstraction with useHandlers() to inject custom behavior during tests.
Can spatie/dns handle long TXT records such as SPF and DMARC?
It returns TXT records as record objects, but long TXT values over 255 characters, multi-string SPF or DMARC records, IDN domains, and NAPTR or SRV records are the highest-risk parsing surfaces. Historical releases have fixed TXT, PTR, and NS parsing edge cases. Validate real-world records for your domains before relying on parsed values.
What are alternatives to spatie/dns for DNS lookups in Laravel?
You can use PHP's native dns_get_record() directly, but you lose retry and timeout controls and typed record objects. If you need DNS-over-HTTPS or API-backed lookups, implement a custom handler through the package's Handler abstraction and register it with useHandlers(). Because the library is small, replacing it with a focused wrapper is also low-effort.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo