A modern macOS Settings extension for managing the /etc/hosts file, built entirely with SwiftUI for macOS Sequoia (15.0+).
- 🎨 Native SwiftUI Interface — Integrates seamlessly with System Settings
- 🔒 Secure Privilege Escalation — Uses
SMAppServicefor safe root access - ✏️ Full CRUD Operations — Add, edit, delete, and toggle host entries
- ✅ Smart Validation — Validates IPv4/IPv6 addresses and hostnames (RFC 1123)
- 📤 Import/Export — Backup and restore your hosts configuration
- 🔍 Search & Filter — Quickly find entries with built-in search
- 💬 Comments Support — Attach notes to individual host entries
- 🔄 Auto DNS Flush — Flushes DNS cache automatically after changes
- ♿ Accessibility — Full VoiceOver support on all interactive elements
- macOS Sequoia 15.0 or later
- Xcode 16.0 or later
- Swift 5.9+
Three-tier architecture with strict privilege separation:
- Settings Extension (
HostsManagerExtension) — SwiftUI interface inside System Settings - Privileged Helper Tool (
HostsManagerHelper) — XPC service that performs root file operations - Host App (
HostsManagerApp) — Container app that registers the helper viaSMAppService - Shared — Models, protocols, and utilities shared across all targets
┌──────────────────────────────────────────┐
│ System Settings.app │
│ ┌────────────────────────────────────┐ │
│ │ HostsManagerExtension │ │
│ │ (SwiftUI Views + ViewModels) │ │
│ └────────────────────────────────────┘ │
└──────────────────────────────────────────┘
↕ XPC (NSXPCConnection)
┌──────────────────────────────────────────┐
│ HostsManagerHelper (launchd daemon) │
│ Root access → reads/writes /etc/hosts │
└──────────────────────────────────────────┘
hosts-prefpane/
├── .swiftlint.yml # SwiftLint configuration
├── HostsManager.xcodeproj/ # Xcode project (3 targets + tests)
├── HostsManagerApp/ # Container app + SMAppService registration
├── HostsManagerExtension/ # Settings extension (UI + logic)
│ ├── Models/ # HostEntry, HostsFile, ValidationError
│ ├── Services/ # HostsFileService, ValidationService, XPCService
│ ├── ViewModels/ # HostsViewModel, EditorViewModel
│ └── Views/ # SwiftUI views + HostsFileDocument
├── HostsManagerHelper/ # Privileged XPC daemon
├── Shared/ # Constants, Logger, protocols, extensions
│ ├── Extensions/
│ └── Utilities/
└── Tests/
├── ValidationTests/ # IP address & hostname validation
├── ParserTests/ # hosts file parsing & serialization
└── HostsManagerTests/ # Service, ViewModel & model unit tests
open HostsManager.xcodeprojSelect the HostsManagerApp scheme → Product → Build (⌘B).
Or via command line:
xcodebuild -project HostsManager.xcodeproj \
-scheme HostsManager \
-configuration Debug \
buildxcodebuild test -project HostsManager.xcodeproj \
-scheme HostsManager \
-destination 'platform=macOS,arch=arm64' \
CODE_SIGNING_ALLOWED=NOOr in Xcode: Product → Test (⌘U).
69 tests across 5 test suites — all passing:
| Suite | Tests | Coverage |
|---|---|---|
ValidationTests |
10 | IP/hostname validation rules |
ParserTests |
10 | hosts file parsing & serialization |
HostEntryTests |
21 | Model properties, sorting, Codable |
EditorViewModelTests |
18 | Input validation, entry creation |
HostsFileServiceTests |
13 | CRUD operations, error propagation |
swiftlint lint # 0 violations, 0 seriousElevated privileges are required to modify /etc/hosts. Mitigations include:
- ✅ Privileged operations isolated in a separate helper binary
- ✅ XPC communication with strict protocol validation (
HelperProtocol) - ✅
XPCServiceProtocolenables full dependency injection for unit tests (no helper process needed) - ✅ Helper managed by
SMAppService— no shell scripts orAuthorizationExecuteWithPrivileges - ✅ Automatic backup created before every write operation
- ✅ Full input validation for IP addresses and hostnames
Last updated: March 1, 2026
| Phase | Description | Status |
|---|---|---|
| 1–4 | Source code (models, services, views, helper) | ✅ Complete |
| 5 | Configuration (Info.plist, entitlements, Package.swift) | ✅ Complete |
| 6 | Xcode project setup & target configuration | ✅ Complete |
| 7 | Testing — 69 unit tests, CI green (xcodebuild test) |
✅ Complete |
| 8 | Polish — SwiftLint 0 violations, accessibility, refactor | ✅ Complete |
| 9 | Distribution (signing, notarization, installer) | 🔲 Pending |
- Phase 1: Project structure and infrastructure
- Phase 2: Data models and business logic
- Phase 3: Privileged helper tool with XPC
- Phase 4: SwiftUI interface
- Phase 5: Configuration files
- Phase 6: Xcode project setup
- Phase 7: Testing and compilation verification
- Phase 8: Polish, accessibility, SwiftLint, and code quality
- Phase 9: Code signing, notarization, and distribution
MIT License — see LICENSE file for details.
Contributions are welcome. Please open an issue or submit a pull request.
For issues or questions, please open an issue on GitHub.
This project targets macOS Sequoia (15.0+) and uses the modern Settings Extension API, replacing the legacy
.prefPanebundle format.