
Share Hosts File Configurations With a Team
Share hosts file configurations with your team using version control, export/import, documentation and collaboration workflows.
Manage hosts files without the terminal
ToggleHosts helps you manage environments visually on Windows, macOS, and Linux, with automatic DNS flush and backups.
One-time payment
Effective team collaboration requires consistent development environments. When working on projects that require specific hosts file configurations, sharing these settings across team members becomes crucial. This comprehensive guide covers multiple methods for sharing hosts file configurations, from simple documentation to advanced version control and tool-based approaches.
How to share hosts file configurations with your team
To share hosts file configurations across a team, keep the entries in version control, a committed snippet or setup script, rather than copying them by hand. Each developer appends the shared block to their hosts file (or imports a shared profile in a tool), then flushes DNS. This keeps everyone on the same local domains.
Why Share Hosts File Configurations?
Consistency Across Team
When all team members use the same hosts file configurations:
- Everyone tests against the same local domains
- Fewer "it works on my machine" issues
- Easier debugging and support
- Consistent development experience
Faster Onboarding
New team members can:
- Get up and running quickly
- Avoid manual configuration errors
- Understand project structure faster
- Start contributing sooner
Reduced Errors
Shared configurations help:
- Prevent typos in domain names
- Ensure correct IP addresses
- Maintain proper organization
- Avoid missing critical entries
Method 1: Version Control (Git)
Creating Hosts File Templates
The most common approach is to include a hosts file template in your repository:
# hosts.example (committed to Git)
# Copy this file to /etc/hosts or merge with your existing hosts file
# ===================
# PROJECT: My Application
# ===================
127.0.0.1 api.myapp.test
127.0.0.1 frontend.myapp.test
127.0.0.1 admin.myapp.test
# ===================
# STAGING ENVIRONMENT
# ===================
198.51.100.5 staging.myapp.comGit Workflow
# Add template to repository
git add hosts.example
git commit -m "Add hosts file template for local development"
git push
# Team members:
# 1. Clone repository
# 2. Copy hosts.example content
# 3. Merge with their /etc/hosts.gitignore Configuration
Never commit actual hosts files:
# .gitignore
/etc/hosts
hosts.local
hosts.backup
*.hosts.localMultiple Environment Templates
Create separate templates for different environments:
# hosts.dev.example
127.0.0.1 dev-api.myapp.test
127.0.0.1 dev-frontend.myapp.test
# hosts.staging.example
198.51.100.5 staging-api.myapp.com
198.51.100.5 staging-frontend.myapp.com
# hosts.prod.example (for reference only)
203.0.113.10 api.myapp.com
203.0.113.10 www.myapp.comREADME Documentation
Include setup instructions in README:
## Local Development Setup
### Hosts File Configuration
1. Copy contents from `hosts.example`
2. Append to your `/etc/hosts` file:cat hosts.example >> /etc/hosts
3. Flush DNS cache:sudo dscacheutil -flushcache sudo killall -HUP mDNSResponder
4. Verify configuration:ping api.myapp.test
Method 2: Export/Import Workflows
Manual Export
Team members can export their relevant entries:
# Extract project-specific entries
grep "myapp" /etc/hosts > myapp-hosts.txt
# Or extract a section
sed -n '/# PROJECT: My App/,/# END PROJECT: My App/p' /etc/hosts > myapp-hosts.txtStructured Export Format
Create a script to export in a structured format:
#!/bin/bash
# export-hosts.sh
PROJECT="myapp"
OUTPUT="hosts-export.txt"
echo "# Hosts file export for $PROJECT" > $OUTPUT
echo "# Generated: $(date)" >> $OUTPUT
echo "" >> $OUTPUT
grep "$PROJECT" /etc/hosts >> $OUTPUT
echo "Exported to $OUTPUT"JSON Export Format
For tool integration, use JSON:
{
"project": "myapp",
"version": "1.0",
"entries": [
{
"ip": "127.0.0.1",
"domains": ["api.myapp.test", "api.local"]
},
{
"ip": "198.51.100.5",
"domains": ["staging.myapp.com"]
}
],
"metadata": {
"created": "2026-02-06",
"author": "Team",
"environments": ["development", "staging"]
}
}Import Script
Create import script for team:
#!/bin/bash
# import-hosts.sh
TEMPLATE_FILE="hosts.example"
BACKUP_FILE="/etc/hosts.backup.$(date +%Y%m%d)"
# Backup current hosts file
sudo cp /etc/hosts "$BACKUP_FILE"
echo "Backed up to $BACKUP_FILE"
# Append template
sudo sh -c "echo '' >> /etc/hosts"
sudo sh -c "cat $TEMPLATE_FILE >> /etc/hosts"
# Flush DNS
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
echo "Hosts file updated. DNS cache flushed."Method 3: Documentation-Based Sharing
Wiki Pages
Maintain hosts file documentation in your wiki:
# Hosts File Configuration
## Development Environment
Add these entries to your `/etc/hosts`:
127.0.0.1 api.myapp.test 127.0.0.1 frontend.myapp.test
## Staging Environment
For staging testing:
198.51.100.5 staging.myapp.com
## Verification
Test your configuration:
ping api.myapp.test # Should resolve to 127.0.0.1
README Files
Include in project README:
## Quick Start
### 1. Hosts File Setup
# Development 127.0.0.1 api.myapp.test 127.0.0.1 frontend.myapp.test
# Staging (optional) 198.51.100.5 staging.myapp.com
See `hosts.example` in your repository for a complete configuration template.Markdown Documentation
Create dedicated documentation file:
# hosts-configuration.md
## Overview
This document describes the hosts file configuration required for local development.
## Required Entries
### Development
- `api.myapp.test` → 127.0.0.1
- `frontend.myapp.test` → 127.0.0.1
### Staging
- `staging.myapp.com` → 198.51.100.5
## Setup Instructions
1. Open `/etc/hosts` with sudo
2. Add entries from Required Entries section
3. Save file
4. Flush DNS cacheMethod 4: Tool-Based Sharing (ToggleHosts)
Using ToggleHosts for Team Collaboration
ToggleHosts provides built-in sharing capabilities:
Export Configuration:
- Create hosts file profile in ToggleHosts
- Export as JSON or plain text
- Share with team via file or repository
Import Configuration:
- Receive exported configuration
- Import into ToggleHosts
- Apply to local hosts file
ToggleHosts JSON Format
{
"name": "My App Development",
"entries": [
{
"ip": "127.0.0.1",
"hostnames": ["api.myapp.test", "frontend.myapp.test"]
}
],
"metadata": {
"created": "2026-02-06",
"updated": "2026-02-06"
}
}Team Workflow with ToggleHosts
- Team Lead creates configuration in ToggleHosts
- Export configuration to JSON file
- Commit JSON to repository (optional)
- Team Members import JSON into ToggleHosts
- Apply configuration to local hosts file
Advanced Sharing Strategies
Environment-Specific Configurations
Create separate configurations per environment:
# configs/
# ├── hosts.dev.json
# ├── hosts.staging.json
# └── hosts.prod.json (reference)Configuration Management Script
#!/bin/bash
# manage-hosts.sh
ENV=${1:-dev}
CONFIG_FILE="configs/hosts.$ENV.json"
if [ ! -f "$CONFIG_FILE" ]; then
echo "Configuration file not found: $CONFIG_FILE"
exit 1
fi
# Parse JSON and update hosts file
# (requires jq: brew install jq)
jq -r '.entries[] | "\(.ip) \(.hostnames | join(" "))"' "$CONFIG_FILE" | \
sudo tee -a /etc/hosts
sudo dscacheutil -flushcache
echo "Applied $ENV configuration"Versioned Configurations
Track configuration versions:
{
"version": "2.1.0",
"project": "myapp",
"changelog": [
{
"version": "2.1.0",
"date": "2026-02-06",
"changes": "Added admin subdomain"
}
],
"entries": [...]
}Team Onboarding Workflows
New Team Member Checklist
## Onboarding Checklist
- [ ] Clone repository
- [ ] Review hosts.example
- [ ] Copy hosts configuration to /etc/hosts
- [ ] Flush DNS cache
- [ ] Verify domains resolve correctly
- [ ] Test local development setupAutomated Setup Script
#!/bin/bash
# setup-dev-environment.sh
set -e
echo "Setting up development environment..."
# Check if hosts.example exists
if [ ! -f "hosts.example" ]; then
echo "Error: hosts.example not found"
exit 1
fi
# Backup current hosts file
BACKUP="/etc/hosts.backup.$(date +%Y%m%d_%H%M%S)"
sudo cp /etc/hosts "$BACKUP"
echo "Backed up hosts file to $BACKUP"
# Check if entries already exist
if grep -q "myapp.test" /etc/hosts; then
echo "Warning: myapp.test entries already exist in hosts file"
read -p "Continue anyway? (y/n) " -n 1 -r
echo
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
exit 1
fi
fi
# Append hosts.example to /etc/hosts
sudo sh -c "echo '' >> /etc/hosts"
sudo sh -c "echo '# Added by setup script - $(date)' >> /etc/hosts"
sudo sh -c "cat hosts.example >> /etc/hosts"
# Flush DNS
sudo dscacheutil -flushcache
sudo killall -HUP mDNSResponder
echo "Setup complete!"
echo "Verify with: ping api.myapp.test"Handling Different Local Setups
IP Address Variations
Some team members may need different IPs:
# hosts.example
# Replace LOCAL_IP with your machine's IP if needed
LOCAL_IP=127.0.0.1
# LOCAL_IP=192.168.1.100 # For mobile device testing
$LOCAL_IP api.myapp.test
$LOCAL_IP frontend.myapp.testPlatform-Specific Notes
## Platform Notes
### macOS
- Use .test domains (recommended)
- Flush DNS: `sudo dscacheutil -flushcache`
### Linux
- Use .test or .local domains
- Flush DNS: `sudo systemd-resolve --flush-caches`
### Windows
- Use .test domains
- Flush DNS: `ipconfig /flushdns`Docker vs Native Setups
# hosts.example
# For Docker users: ports may differ
# For native: use standard ports
# Docker setup
127.0.0.1 api.myapp.test # Port 3001
127.0.0.1 frontend.myapp.test # Port 3002
# Native setup
127.0.0.1 api.myapp.test # Port 80
127.0.0.1 frontend.myapp.test # Port 80Best Practices for Team Sharing
1. Use Templates, Not Actual Files
Always share templates (hosts.example) rather than actual hosts files:
- System-specific differences
- Personal entries shouldn't be shared
- Easier to customize
2. Document Everything
Include:
- Purpose of each entry
- Which environment it's for
- When to use it
- How to verify it works
3. Version Control
Track changes:
- Use Git for templates
- Tag versions
- Maintain changelog
- Review changes in PRs
4. Regular Updates
Keep configurations current:
- Update when domains change
- Remove obsolete entries
- Document new requirements
- Communicate changes to team
5. Clear Naming Conventions
Use consistent naming:
# Good
api.myapp.test
frontend.myapp.test
admin.myapp.test
# Avoid
api.test
web.test
admin.test6. Test Before Sharing
Verify configurations:
- Test on clean system
- Verify all domains resolve
- Check DNS cache flushing
- Document any issues
Troubleshooting Shared Configurations
Issue: Entries Not Working After Import
Solutions:
- Verify file format (Unix line endings)
- Check for syntax errors
- Ensure proper permissions
- Flush DNS cache
- Verify IP addresses are correct
Issue: Conflicts with Existing Entries
Solutions:
- Check for duplicate entries
- Review existing hosts file
- Merge carefully
- Document conflicts
- Use tools to detect duplicates
Issue: Team Members Have Different Results
Solutions:
- Verify same configuration version
- Check platform differences
- Verify DNS cache flushed
- Test with ping/nslookup
- Document platform-specific notes
CI/CD Integration
Automated Testing
Include hosts file setup in CI:
# .github/workflows/test.yml
- name: Setup hosts file
run: |
echo "127.0.0.1 api.myapp.test" | sudo tee -a /etc/hosts
sudo systemd-resolve --flush-caches || trueDocker Compose Testing
# docker-compose.test.yml
services:
test:
image: node:18
extra_hosts:
- "api.myapp.test:host-gateway"Security Considerations
Sensitive Information
Never commit:
- Production IP addresses (unless public)
- Internal network IPs
- Staging credentials
- Personal entries
Access Control
For sensitive configurations:
- Use private repositories
- Limit access to team members
- Use environment variables
- Encrypt sensitive data
Conclusion
Sharing hosts file configurations across your team is essential for consistent development environments and efficient collaboration. Whether you choose version control templates, export/import workflows, documentation, or specialized tools, the key is establishing a clear process that everyone can follow.
The best approach depends on your team's workflow:
- Small teams: Documentation + templates
- Git-based teams: Version control + README
- Complex setups: Tool-based sharing (ToggleHosts)
- Multiple environments: Structured JSON + scripts
Remember to:
- Use templates, not actual hosts files
- Document everything clearly
- Keep configurations versioned
- Test before sharing
- Update regularly
For teams looking to streamline hosts file management, ToggleHosts (4.99 €) provides an excellent solution with export/import capabilities, team sharing features, and profile management. It eliminates manual editing overhead and ensures consistency across team members.
Start sharing your hosts file configurations today and watch your team's development workflow become more efficient and consistent.
Sources and further reading
- The hosts file explained (Wikipedia)
- hosts(5) manual page (man7.org)
- How DNS works (Cloudflare Learning)
Frequently Asked Questions
Use version control (Git) with hosts file templates, export/import tools like ToggleHosts, or maintain documentation with configuration examples. Version control is best for teams already using Git.
Not recommended - hosts files are system-specific. Instead, commit a hosts.example template file that team members can copy and customize for their local setup.
You can manually copy entries, use scripts to extract relevant sections, or use tools like ToggleHosts that provide export functionality in JSON or plain text formats.
Plain text hosts file format is universal, but JSON is better for structured data and tool integration. Markdown works well for documentation. Choose based on your team's workflow.
Create separate configuration files for each environment (hosts.dev, hosts.staging) or use environment-specific sections in your hosts file template. Document which entries belong to which environment.
Use templates with placeholders, provide clear documentation, and use tools that support customization. Focus on sharing the structure and required entries, not exact IP addresses.
Related Articles
Manage Multiple Hosts Files by ProjectLocal development
Manage Multiple Hosts Files by Project
10 min read
How to Sync WSL2 with Windows Hosts File for Local Domains (2026)Local development
How to Sync WSL2 with Windows Hosts File for Local Domains (2026)
5 min read
Fix NET::ERR_CERT_COMMON_NAME_INVALID with Hosts File (2026)Troubleshooting
Fix NET::ERR_CERT_COMMON_NAME_INVALID with Hosts File (2026)
4 min read