Putty can't connect over SSH to hostname, IP connection works

31,315

Solution 1

You have a problem with name resolution on the client you try to connect from (W7).

All connections are made to a destination IP address. If you supply a name, the computer first resolves that name into an IP address. This is where you fail today.

If your gentoo box / home router's IP address can't be looked up from either the hosts file, or with an A (or AAAA for IPv6) record in DNS (possibly via a CNAME), your windows machine won't understand what IP the gentoo box has.

To be able to give a good answer to your question, we need a bit more information from you, describing the network setup a bit, so we don't make wrong guesses. For instance:

  • are the windows and gentoo boxes both on the "inside" network?
  • are they both configured as DHCP clients?
  • is the router the only DHCP server on the internal network?

Did you use any DynDNS service when it was working earlier, or has the W7 installation changed somehow? (Different PC, reinstall, virus, etc?) Perhaps you had an entry in the hosts file before, when it was working, and it is now missing.

Why the router can figure out the internal/private IP address of the linux box while the windows box cannot, is because they use different sources for their name information. Maybe the router itself has that information. Is it also a DHCP server? Maybe that's why the router knows.

EDIT (2012-08-06): Based on new input,
On the gentoo box, make sure you have an entry in /etc/hosts that looks like this:

192.168.0.3   hostname.domain.tld  hostname

(replace 192.168.0.3 with the real (internal) IP address of the gentoo server, and hostname.domain.tld to be the fully qualified domain name you wish to use, and the last word on the line to be the hostname without the domain (ie, the word before the first .).

Put the same line in the %WINDIR%\System32\drivers\etc\hosts file, but remember that windows name lookups of your gentoo box will be then taken from that file, and not from DNS.

This should make the name lookups work (locally) on both the gentoo server itself, and the windows client, without consulting DNS.

In /etc/apache2/vhosts.d/00_default_vhost.conf (if that's where your web server is configured), make the ServerName entry match the FQDN (hostname.domain.tld) that you have in the /etc/hosts file.
This should allow apache to start without warnings.

Solution 2

Probably you are not using the correct name. I can imagine you are using something like an URL (http://host_name.com/). Try tou use only the name host_name.com. We need more info about the name you are using.

Share:
31,315

Related videos on Youtube

user1561108
Author by

user1561108

Updated on September 18, 2022

Comments

  • user1561108
    user1561108 over 1 year

    I have a gentoo box on my homenetwork that I'm trying to SSH into via W7 client but although I can do it via IP address when I try the hostname it won't find it. Also get a DNS error

    socket.gaierror: [Errno -2] Name or service not known
    

    when I try to startup a http server on the gentoo. I assume as this is a dns error that these issues are related.

    It was working a few months ago when I last logged in so I'm not sure what's changed in the meantime?

    EDIT:

    Ping fails on supplying hostname too but again, pinging the IP works fine.

    On my router firmware I have port forwarding setup to the linux hostname for ssh and http which works fine though. So how can router resolve hostname but not my windows box/the linux http server itself?

    EDIT 2:

    I set the static ip/hostname in etc/hosts and the http server now starts up, indicating gentoo couldn't resolve it's own name. Confused as to how that can be?

  • user1561108
    user1561108 over 11 years
    it's just a hostname on my local network - and I'm trying to login via ssh not http. The DNS error detailed above is when run the http server startup script.
  • logoff
    logoff over 11 years
    do you receive answers using ping to this host using his name?
  • logoff
    logoff over 11 years
    it seems that your network name is not being resolved at all. are you trying to access outside from your network? if the answer is no, your router does not affect at all.
  • user1561108
    user1561108 over 11 years
    a) both on inside b) not sure, how can I check this? c) yes. Used both a dyndns service and straight hostname connection before. DynDNS (no-ip.org) works now too, but hostname addressing fails.
  • user1561108
    user1561108 over 11 years
    what do you mean by access outside from my network? I can access the internet from my W7 machine if that's what you mean. And all devices have valid IP addresses handed out by the router.
  • logoff
    logoff over 11 years
    I mean your client machine must be in the same network than the server machine, because this is the scope of the machine network name. Besides, you must check if this kind of network names are resolved by your W7 machine: try to ping this machine using his network name.