Solved

Cannot ssh using domain name, only IP address

Posted on 2009-05-10
21
720 Views
Last Modified: 2012-05-06
I have a small LAN running Ubuntu on several machines.  I can login using SSH from one to another, but only if I use the IP address.  Assume I am trying to ssh to a machine with an IP of 192.168.0.10 and a hostname of Desktop.

If I enter "ssh me@192.168.0.10" it logs me into Desktop to a prompt me@Desktop:~$

But if I try

"ssh me@Desktop" I get a message "ssh: Desktop: Name or service not known" even though I know that the hostname Desktop exists.

What am I missing?
0
Comment
Question by:Bloodrule
  • 8
  • 6
  • 5
  • +2
21 Comments
 
LVL 2

Expert Comment

by:stany0
ID: 24347320
edit /etc/hosts file
format:
<IP> <HOSTNAME>.<DOMAIN> <ALIAS>
example:
127.0.0.1 localhost.localdomain localhost
0
 
LVL 12

Expert Comment

by:geowrian
ID: 24347323
What happens if you ping Desktop? Maybe it's not resolving the NetBIOS name.
0
 
LVL 12

Expert Comment

by:geowrian
ID: 24347331
@stany0
Good idea. Keep in mind that's for *nix. Windows users will have to edit the hosts file in c:\Windows\system32\drivers\etc (assuming C is the Windows drive).

stany0's suggestion isn't a long-term fix; however, but does let us know if the problem is network based or application-based.
0
 

Author Comment

by:Bloodrule
ID: 24347340
If I ping Desktop I get a "Unknown host Desktop" error.
0
 

Author Comment

by:Bloodrule
ID: 24347347
Would you mind telling me exactly what I might enter using your suggestion?

127.0.0.1 localhost.localdomain localhost

If the IP address of my machine is 192.168.0.10 (static) and  If the hostname is Desktop, what exactly should I enter using your example above as the template?
0
 
LVL 12

Expert Comment

by:geowrian
ID: 24347353
@Bloodrule
That's your problem then...your computer isn't resolving "Desktop" to it's IP address. You can follow stany0's advice to make it work, but it will only work until it's IP changes. The long-term fix is to figure out why your computer isn't seeing it advertising it's name, or why the ssh server isn't advertising it, or if something is blocking the traffic.

Some question that can help identify the exact problem:
1) Can other computers on the same network get to it via "Desktop"?
2) Can you ping any computers on your network by their computer names?
3) Does the workgroup (or domain?) name on your computer match the workgroup name on the ssh server PC?
0
 
LVL 12

Expert Comment

by:geowrian
ID: 24347357
@Bloodrule
If your workgroup/domain name was WORKGROUP:
192.168.0.10 Desktop.WORKGROUP Desktop
0
 

Author Comment

by:Bloodrule
ID: 24347377
Thanks for your helpful advice.  Here comes a dumb question:  How do I determine what my workgroup/domain name is?
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24347379
is it available in dns? check your dns server
0
 
LVL 12

Expert Comment

by:geowrian
ID: 24347383
Windows:
Right-Click "My Computer"
Choose Properties
Choose "Computer Name" tab
Look where it says "Workgroup"

*nux:
hostname    (actually hostname -s gives just the workgroup)
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 

Author Comment

by:Bloodrule
ID: 24347390
Sorry but I don't know how to check my dns server?  Is that I command I issue in Linux or is it a setting in my router?  
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24347409
from the system you are trying to ssh from, run

nslookup Desktop

and see if you get error message or resolved ip. What is your client OS?
0
 

Author Comment

by:Bloodrule
ID: 24347599
When I run nslookup Desktop, I get this response:

Server:         192.168.0.1
Address:      192.168.0.1#53

** server can't find Desktop: NXDOMAIN

Not sure what to make of this.  Your help is appreciated.
0
 
LVL 40

Assisted Solution

by:omarfarid
omarfarid earned 200 total points
ID: 24347628
this means that your dns server is not resolving name to ip address. Can you put full domain name e.g.

Desktop.domain
0
 

Author Comment

by:Bloodrule
ID: 24347685
When I run nslookup Desktop.domain (I hope that's what you meant for me to try) I get exactly the same error message, namely

Server:         192.168.0.1
Address:      192.168.0.1#53

** server can't find Desktop: NXDOMAIN
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24347712
Please put your domain name for the domain part. What OS are you running ?
0
 

Author Comment

by:Bloodrule
ID: 24347737
I am running Ubuntu 8.10 on each machine.  I am not sure what you mean by "put your domain name for the domain part".  Sorry.
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24348251
can you show the content of the following files:

/etc/hosts
/etc/resolv.conf
0
 

Author Comment

by:Bloodrule
ID: 24349562
/etc/hosts:

127.0.0.1    localhost
192.168.0.10   Desktop


/etc/resolv.conf
nameserver    192.168.0.1
0
 
LVL 40

Expert Comment

by:omarfarid
ID: 24351241
can you show also /etc/nsswitch.conf
0
 
LVL 10

Accepted Solution

by:
lanboyo earned 300 total points
ID: 24359752
It looks like you do not have a dns server serving dns for the local network. The .1 address is probably your internet router , which is proxying dns requests externally to whatever your isp assigns. If you want to get it working quickly, basically you will need to copy the contents of etc hosts into the other hosts file. Not the localhost or loopback part.

Windows uses netbios over tcp to resolve hostnames like this, this is not a great idea on *nix.

So if you really don't want to modify host files, you need to set up a local dns server, and you need to make dhcp aware of it, which may mean disabling the router's dhcp and setting up your own. Host files may be easier.
0

Featured Post

Save on storage to protect fatherhood memories

You're the dad who has everything. This Father's Day, make sure your family memories are protected. My Passport Ultra has automatic backup and password protection to keep your cherished photos and videos safe. With up to 3TB, you have plenty of room to hold the adventures ahead.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have seen several blogs and forum entries elsewhere state that because NTFS volumes do not support linux ownership or permissions, they cannot be used for anonymous ftp upload through the vsftpd program.   IT can be done and here's how to get i…
Note: for this to work properly you need to use a Cross-Over network cable. 1. Connect both servers S1 and S2 on the second network slots respectively. Note that you can use the 1st slots but usually these would be occupied by the Service Provide…
This is a video describing the growing solar energy use in Utah. This is a topic that greatly interests me and so I decided to produce a video about it.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now