A command-line utility to programmatically change the DNS settings of your macOS network services using Python and
networksetup. It is based on Yggland datas.
- Choose from pre-configured public DNS providers:
- OpenDNS
- Cloudflare
- Quad9
- Or reset to default
- Supports both IPv4 and IPv6 addresses
- Configure one or multiple network services (e.g.,
Wi-Fi,Ethernet,iPhone USB) - Easily reset DNS to DHCP-provided values
- macOS
- Python 3.7+
- Admin privileges (
sudorequired to change network settings)
You can install via pip (if published on PyPI):
pip install macos-dns-switcherOr install from source:
git clone https://github.com/JimmyMtl/macos-dns-switcher.git
cd macos-dns-switcher
pip install .Run the CLI tool with:
sudo mdns- Select one or more network services (e.g., Wi-Fi, Ethernet)
- Choose a DNS provider:
0– Default (reset to DHCP)1– OpenDNS2– Cloudflare3– Quad9
- The tool applies the selected DNS settings to all selected services
To confirm the DNS settings applied to a service:
networksetup -getdnsservers "Wi-Fi"Replace "Wi-Fi" with your actual service name if different.
To remove custom DNS settings and restore DHCP:
sudo mdnsThen:
- Select the target service(s)
- Choose option
0to reset
- Only works on macOS via
networksetup - DNS settings apply system-wide and may not persist if overwritten by VPNs or profiles
MIT License
Feel free to open an issue or submit a pull request if you’d like to contribute or request a feature!