Fix "ssh_init: host not found" Error in SSH
1. Use IP Address Instead of Hostname
To bypass DNS resolution issues entirely, try connecting with your server's IP address instead of its hostname.
For the FileZilla-specific variants and DNS-cache angle, see FileZilla — Use IP Instead of Hostname, systemd-resolved Linux variant, and Flush DNS Cache.
Windows Command Prompt:
nslookup yourserver.com
Linux/macOS Terminal:
dig yourserver.com +short
or
host yourserver.com
Example Output:
192.168.1.10
Use the IP Address in SSH Instead
Instead of connecting with the hostname:
ssh user@yourserver.com
Try connecting with the IP address:
ssh user@192.168.1.10
Diagnostic Result:
- If the IP connection works, the issue is definitely with DNS resolution.
- If SSH still fails even with the IP, the problem may be network-related, firewall-related, or the SSH service might not be running on the server. Proceed to the next steps.
2. Verify DNS Resolution
If the hostname is not resolving, check your system's DNS settings directly.
For Windows:
nslookup yourserver.com
For Linux/macOS:
systemd-resolve yourserver.com
or
host yourserver.com
Expected Results:
- If an IP address is returned (e.g.,
192.168.1.10), DNS is working correctly from your system's perspective. - If you see
"host not found","NXDOMAIN", or no IP address appears, DNS is failing and you should move to the next step.
3. Manually Add Hostname to /etc/hosts
If DNS is not resolving the hostname, you can manually map it to its IP address on your local system. This is a reliable workaround that bypasses external DNS entirely.
For Linux/macOS:
sudo nano /etc/hosts
Add this line at the end of the file (use your actual IP and hostname):
192.168.1.10 yourserver.com
Save (Ctrl+O) and exit (Ctrl+X).
For Windows:
- Open Notepad as Administrator.
- Click File > Open and navigate to:
C:\Windows\System32\drivers\etc\hosts - Add this line at the end of the file:
192.168.1.10 yourserver.com - Save the file and restart your SSH client or command prompt.
Now SSH should recognize the hostname by checking this local file first.
4. Flush DNS Cache
Clear old or corrupted DNS records from your system's cache to force it to retrieve fresh information.
For Windows:
ipconfig /flushdns
For macOS:
sudo killall -HUP mDNSResponder
For Linux (systemd-based distros like Ubuntu, Debian, CentOS 8+):
sudo systemd-resolve --flush-caches
After running the appropriate command for your OS, retry your SSH connection.
5. Restart Network Services
Restarting your network interface can refresh all connection settings, including DNS.
Linux/macOS:
sudo systemctl restart networking
or
nmcli networking off && nmcli networking on
Windows:
ipconfig /release
ipconfig /renew
Now try connecting again with SSH.
6. Check Firewall & SSH Port
If DNS is working but SSH still fails, the connection might be blocked by a firewall.
Test If the SSH Port Is Open
Run one of these diagnostic commands:
nc -zv yourserver.com 22
or
telnet yourserver.com 22
Interpretation:
- If it connects successfully, the SSH service is reachable on port 22.
- If you see
"Connection refused"or it times out, the SSH port is blocked, the service is not running, or the host is unreachable.
Allow SSH in Firewall (Server-Side Configuration)
For UFW (Ubuntu/Debian) - Run these on your server:
sudo ufw allow 22/tcp
sudo ufw reload
For Firewalld (CentOS/RHEL) - Run these on your server:
sudo firewall-cmd --add-service=ssh --permanent
sudo firewall-cmd --reload
Now try SSH again from your client machine.
7. Check SSH Client Configuration
Your SSH client may have incorrect settings in its configuration file that are causing the hostname resolution to fail.
- Open your user-specific SSH configuration file:
nano ~/.ssh/config - Verify the host entry for your server is defined correctly. A standard entry looks like:
Host myserver HostName yourserver.com User username Port 22 IdentityFile ~/.ssh/id_rsa - Save the file (Ctrl+O, then Enter, then Ctrl+X).
- Now test the connection using your configured alias:
ssh myserver
Ensure the HostName directive contains the correct, resolvable address.
8. Summary of Fixes
| Issue | Fix |
|---|---|
| Hostname not resolving (ssh_init: host not found) | Use server IP instead of hostname |
| DNS lookup fails | Test with nslookup or dig, and manually add host to /etc/hosts |
| DNS is outdated | Flush DNS with ipconfig /flushdns (Windows) or systemd-resolve --flush-caches (Linux) |
| Firewall blocking SSH | Open port 22 with ufw allow 22/tcp or firewall-cmd --add-service=ssh --permanent |
| SSH config incorrect | Check ~/.ssh/config and update HostName |
| Network issues | Restart networking with systemctl restart networking |
By systematically following these troubleshooting steps, SSH should work without the "ssh_init: host not found" error!


