Localhost not working on Mac: 7 fixes that actually work (2026)
Localhost refuses to load on your Mac? Here are 7 tested solutions: server check, hosts file, firewall, blocked ports. Step-by-step troubleshooting guide.
Locahl Team
Table of Contents
- Quick Diagnosis
- Solution #1: Check that the server is running
- Check your terminal
- Check if a process is listening
- Check the correct port
- Solution #2: Free up an occupied port
- Identify the process
- Kill the process
- Solution #3: Check the firewall
- macOS Firewall
- Third-party applications
- Quick test
- Solution #4: Check the hosts file
- Check the content
- Repair if necessary
- Solution #5: Flush DNS cache
- Solution #6: Check the listening address
- Important difference
- Force the address in your server
- Solution #7: Tool-specific problems
- Node.js / npm
- Docker
- MAMP / XAMPP
- Test with 127.0.0.1 vs localhost
- Use custom local domains
- Prevent future problems
- Conclusion
You start your development server, open localhost:3000 in your browser, and... nothing. "This site can't be reached", "ERR_CONNECTION_REFUSED", or an endless loading page. Frustrating, isn't it?
This guide will help you diagnose and fix localhost problems on Mac, step by step.
Quick Diagnosis
Before diving into solutions, let's identify the type of problem:
| Symptom | Likely Cause | Solution | |---------|--------------|----------| | ERR_CONNECTION_REFUSED | Server not started or wrong port | Solution #1 | | Page loads forever | Firewall or timeout | Solution #3 | | localhost OK but domain.local not | Hosts file | Solution #4 | | Worked yesterday, not today | DNS cache or zombie process | Solution #2, #5 |
Simplify your hosts file management
Locahl lets you manage your hosts file visually, without touching the terminal. Automatic DNS flush, multiple environments, and backups included.
Solution #1: Check that the server is running
It seems obvious, but this is the most common cause.
Check your terminal
Does your server display "Listening on port 3000" or similar?
# Example with npm
npm run dev
# Expected output
> ready - started server on 0.0.0.0:3000Check if a process is listening
lsof -i :3000If nothing appears, no process is listening on that port.
Check the correct port
Make sure you're accessing the right port in your browser. If your server says "port 8080", don't go to localhost:3000.
Solution #2: Free up an occupied port
If you see "Port 3000 already in use", another process is blocking the port.
Identify the process
lsof -i :3000Result:
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
node 12345 user 23u IPv4 0x1234 0t0 TCP *:3000 (LISTEN)Kill the process
kill -9 12345Or to kill all processes on a port:
lsof -ti :3000 | xargs kill -9Solution #3: Check the firewall
macOS firewall or security applications can block local connections.
macOS Firewall
1. Open System Settings > Network > Firewall 2. Click Options... 3. Make sure your application (Node, Python, etc.) is allowed
Third-party applications
Apps like Little Snitch, Lulu, or certain antiviruses can block localhost. Check their rules.
Quick test
Temporarily disable the firewall to test:
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate offDon't forget to re-enable it afterwards:
sudo /usr/libexec/ApplicationFirewall/socketfilterfw --setglobalstate onSolution #4: Check the hosts file
If localhost doesn't resolve to 127.0.0.1, the problem is in the hosts file.
Check the content
cat /etc/hostsYou should see:
127.0.0.1 localhost
::1 localhostRepair if necessary
If these lines are missing:
sudo nano /etc/hostsAdd:
127.0.0.1 localhost
::1 localhostSave (Ctrl+O, Enter, Ctrl+X) then flush the DNS cache.
Solution #5: Flush DNS cache
A corrupted DNS cache can prevent localhost from working.
sudo dscacheutil -flushcache && sudo killall -HUP mDNSResponderSolution #6: Check the listening address
Some servers listen on 127.0.0.1 only, others on 0.0.0.0.
Important difference
- 127.0.0.1: Accessible only from your machine
- 0.0.0.0: Accessible from any interface (useful for Docker, VM)
Force the address in your server
// Node.js / Express
app.listen(3000, '0.0.0.0', () => {
console.log('Server running');
});# Python / Flask
app.run(host='0.0.0.0', port=3000)Solution #7: Tool-specific problems
Node.js / npm
# Clean npm cache
npm cache clean --force
# Delete node_modules and reinstall
rm -rf node_modules package-lock.json
npm installDocker
# Check that Docker Desktop is running
docker ps
# Restart Docker if necessary
killall Docker && open /Applications/Docker.appMAMP / XAMPP
1. Check that Apache/Nginx is running (green light) 2. Check the port in preferences (80 vs 8888)
Test with 127.0.0.1 vs localhost
If localhost fails but http://127.0.0.1:3000 works, the problem is in DNS resolution, not your server.
# Test localhost
curl -I http://localhost:3000
# Test direct IP
curl -I http://127.0.0.1:3000Use custom local domains
Rather than localhost, you can use domains like myproject.test for more clarity.
Prevent future problems
1. Use different ports per project (3000, 3001, 8000, etc.) 2. Stop servers properly (Ctrl+C) instead of closing the terminal 3. Use a manager like Locahl to avoid hosts file conflicts
Conclusion
Localhost problems on Mac usually have simple causes: server not started, port occupied, or stale DNS cache. By following this guide methodically, you should resolve 99% of cases.
If the problem persists, check your application logs and make sure your development environment is properly configured.
Ready to simplify your workflow?
Stop wasting time with the terminal. Locahl lets you manage your hosts file in a few clicks, with automatic validation and no risk of errors.
- Intuitive visual interface
- Automatic DNS flush
- Multi-environment management
- Automatic backups
- JSON Import/Export
Reader Reviews
"Solution #3 (firewall) was my issue. 2 hours of debugging solved in 5 minutes thanks to this article."
September 12, 2025
"Very comprehensive! The diagnostic table at the beginning helped me quickly identify the cause."
November 28, 2025
"Good troubleshooting article. Would have liked more details on Docker but otherwise perfect."
January 5, 2026
Frequently Asked Questions
Why isn't localhost working on my Mac?
The most common causes are: server not started, port already in use, firewall blocking, corrupted hosts file, or stale DNS cache.
How do I check if a server is running on localhost?
Use the command 'lsof -i :PORT' (e.g., lsof -i :3000) to see if a process is listening on the desired port.
Are localhost and 127.0.0.1 the same?
Technically yes, but localhost goes through DNS resolution (hosts file) while 127.0.0.1 is a direct IP. If localhost fails but 127.0.0.1 works, the problem is in your hosts file.
How do I free up an occupied port on Mac?
Identify the process with 'lsof -i :PORT', then kill it with 'kill -9 PID'. Example: kill -9 12345.
Can Mac firewall block localhost?
Yes, if the firewall is in strict mode or if a third-party security application blocks local connections. Check in System Settings > Network > Firewall.
Related Articles
Hosts File Not Working After Edit on Mac: Complete Fix Guide
Your hosts file changes not taking effect? Learn how to fix DNS cache issues, browser cache, file permissions, syntax errors, and encoding problems on macOS.
Locahl Team
Hosts File Permission Denied on Mac: Every Fix Explained
Getting "permission denied" when editing hosts file? Learn how to fix sudo access, System Integrity Protection (SIP), file ownership, chmod permissions, and disk permissions on macOS.
Locahl Team
Why Your Hosts File Changes Disappear After Reboot (and How to Fix It)
Hosts file changes gone after restarting Mac? Learn why macOS resets hosts file, how System Integrity Protection (SIP) affects it, daemon configurations, and backup strategies to persist your changes.
Locahl Team