Windows: ssh: Could not resolve hostname: No such host is known

Published by Nyau Wai Hoe - Updated on

Secure Shell (SSH) is a tool we usually use to manage remote systems. In this guide, we’ll look into a common error message: “ssh: Could not resolve hostname [name]: No such host is known” or “Name or service not known”. This message can show up when trying to connect to a SSH server.

This error isn’t just for Linux users; it happens in Windows too, like in Windows 11 or 10. This could happen when you use SSH clients like PuTTY or the Windows Subsystem for Linux (WSL or WSL2). There are several reasons why you might see this error, and how to fix it depends on your system and setup.

Windows 11 ssh Could not resolve hostname No such host is known

What does the error actually mean?

The error “ssh: Could not resolve hostname [name]: No such host is known” or “Name or service not known” shows up when your SSH client on Windows can’t turn the hostname into a network address. It’s like trying to call someone who isn’t in your phonebook.

This issue often starts with a problem in the Domain Name System (DNS) resolution, where the system fails to connect the easy-to-remember hostname (like “server.example.com“) to its IP address. This could happen for many different reasons, like a typo in the hostname or other bigger network problems (like the server is simply down).

Windows ssh Could not resolve hostname Name or service not known

How to correctly connect to an SSH server

Double-check to make sure the hostname is correct

It might sound simple, but typos are a common issue. Make sure the hostname you are trying to connect to is spelled right and is the one you mean to use.

SSH command syntax

Check that your SSH command is set up right. It should look something like ssh username@hostname. A mistake in how you write this command can cause issues, including problems with hostname resolution.

How to correctly connect to an SSH server

These might seem like simple steps, but they can save you a lot of time if the error is just because of some small human mistakes.

Check the DNS resolution

Use nslookup or ping

You can use tools like nslookup [hostname] or ping [hostname] to check if the hostname turns into an IP address correctly. Just type these in the Command Prompt. If these tools show an IP address, then DNS is working fine for that hostname. If not, you have a DNS problem.

nslookup DNS in CMD Windows 11

What does DNS do?

DNS is like a phonebook for the internet, turning friendly hostnames into IP addresses. If DNS can’t find the hostname, your SSH client won’t know where to connect.

Check the DNS configuration

Make sure the DNS settings on your computer are set up right. Sometimes, changing to a different DNS server, like Google’s 8.8.8.8 or Cloudflare’s 1.1.1.1, can fix these issues.

These checks often help find out if the problem is with DNS resolution, which is a usual suspect behind the “ssh: Could not resolve hostname” error.

Pro tip: DNS Servers to Unblock Websites and Possibly Everything

Check your network connectivity

Also, check your network connection to see if it is the problem that is causing the SSH issues.

  1. Make sure your devices are actually online. Try opening a website or use ping 8.8.8.8 in Command Prompt to check your connection.
  2. Sometimes, problems come from wrong settings. Check that your network adapter is set up right and there are no IP conflicts or incorrect gateway settings that might be messing up your connection.
  3. If you’re using a VPN or proxy, it might be messing with your SSH connections. Try turning these off for a while to see if that fixes the problem.
  4. Try to do a quick restart for your modem, router, or any network switches.

Restart Router and Modem

Look at the “hosts” file in Windows

The Windows hosts file can skip DNS and directly link hostnames to IP addresses. A wrong entry (although rare) in this file could be why you’re seeing the “Could not resolve hostname” error in SSH.

  1. The hosts file is usually at C:\Windows\System32\drivers\etc\hosts. You’ll need to be an administrator to change this file.
  2. Open the hosts file using a text editor like Notepad, run as an administrator. Check for any lines that have the hostname you’re trying to connect to. If you see a wrong or old IP address linked to this hostname, that might be your problem.
  3. If there’s a bad entry, you can change it to the right IP address or delete the entry to let DNS handle the hostname normally. Don’t forget to save the file after you make changes.
  4. Try your SSH connection again after you edit the hosts file to see if that fixed the issue.

ssh Could not resolve hostname Windows 11

Check your firewall and security app

Windows Firewall or other security programs can sometimes block SSH connections and cause the “ssh: Could not resolve hostname: Name or service not known” or “No such host is known” error when you try to connect to a SSH server.

Try to check your Windows Firewall settings. Search for and open “Windows Defender Firewall with Advanced Security” from the Start menu. In the firewall settings, look for any rules that might be blocking outbound SSH connections (typically on port 22). If you find such rules, you can turn them off to test the connection.

Checking Firewall rules in Windows 11

If you’re using third-party antivirus or security software, it might have its own firewall or network protection rules. These can also interfere with SSH connections. You can try turning these features off temporarily to see they are the problem. Like with the Windows Firewall, make sure to turn these protections back on after testing.

In both cases, if turning off the firewall fixes the problem, consider adding an exception rule for your SSH connections instead of keeping the firewall turned off.

Related resource: Using PowerShell to Test Port Connection Without Telnet

Use IP addresses directly

Bypassing hostname resolution by using the server’s IP address directly in your SSH command is a simple way to check if DNS resolution is the main problem. Instead of relying on DNS to turn the hostname into an IP, you put the IP address right into your SSH command. This method can quickly show if the problem is with DNS or other parts of the SSH connection process.

To do this, instead of using ssh username@hostname, use ssh username@IP_Address, where IP_Address is the actual IP address of the server you’re trying to connect to. If this works and you get connected, it’s clear that the issue is with DNS resolution for the hostname, not with the SSH server or your client setup.

SSH in Windows using IP Address

Might be useful: Using FTP via Command Line (CMD) on Windows 11

Check the SSH client configuration and logs

When you get the “ssh: Could not resolve hostname” error, try to have a look at your SSH client’s settings and logs. These can give you clues on whether the problem is due to wrong settings or other underlying issues.

In Windows, if you’re using a third-party SSH client, make sure it’s set up according to the guide. For the built-in Windows SSH client, check the environment variables and any config files that might affect how it works.

SSH client configuration Putty Windows 11

Next, check the SSH client logs. The way to do this can vary depending on the SSH client you’re using. For the built-in Windows client, you can make the output more detailed by adding the -vvv flag to your SSH command, like ssh -vvv username@hostname. This command will show a lot of debug information, which is very helpful for figuring out where the connection process is going wrong.

Example: If the logs show a problem at the point of hostname resolution, this might tell you that it’s likely a DNS issue. If they show a different issue, like a problem with authentication or a timeout, then the main problem lies elsewhere.

how to debug ssh could not resolve hostname Windows 11

It might just be a server-side issue

While we’ve focused on the client side, sometimes you also need to think about the server side, especially if you haven’t solved the problem after trying a lot of things.

  1. Make sure the SSH server you want to connect to is running and reachable. If you can get to the server some other way, check that the SSH service is active.
  2. Like on the client side, the server’s firewall can stop incoming SSH connections. Check that the server’s firewall lets connections through on the SSH port (default is 22).
  3. If the server recently changed its IP address, it might take some time for the new address to spread through the DNS system. This can cause mismatches and connection issues.
  4. On the server, make sure your user account has the right permissions and that the server is set up to recognize your client correctly, whether through a password or an SSH key.

Looking at these server-side things can help you rule out outside factors that might be causing the “Could not resolve hostname” error.


Nyau Wai Hoe
Nyau Wai Hoe is the Founder and Chief Editor of WindowsDigitals.com. With a degree in software engineering and over 12 years of experience in the tech support industry, Nyau has established himself as an expert in the field, with a primary focus on the Microsoft Windows operating system. As a tech enthusiast, he loves exploring new technologies and leveraging them to solve real-life problems.

Share via
Copy link