ssh question

Place to discuss Debian Linux and Debian based distributions
Post Reply
Ice9
guru
guru
Posts: 577
Joined: Thu Jan 09, 2003 12:40 am
Location: Belgium
Contact:

ssh question

Post by Ice9 » Mon Feb 20, 2006 3:49 pm

Here at home I'm using my router's dhcp server to assign IP addresses.
Each time I want to ssh into a box I have to so an nmap of the network to get the IP address, since they tend to change quite often.
I was thinking of using hostnames to ssh into the different boxen so I added a hostname to /etc/hosts and to /etc/sysconfig/network and it succesfully shows the correct hostname when querying with # hostname.

How would I go with ssh now since ssh followed by the hostname only results in
# ssh: Hostname: Name or service not known

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Mon Feb 20, 2006 7:37 pm

If you put it in your /etc/hosts file (on the machine you are trying to ssh from) it should work. I've never had a problem with it not working. I might make a suggestion though. Why don't you have a DNS server running and have your clients (or DHCP server) register your clients name so you don't have to mess with hosts? If you don't want to mess with configuring a full blown implementation of DHCP and BIND you can install dnsmasq which is an easy to configured DNS/DHCP server all in one. That's what I am currently using on my Linksys router/firewall:

http://thekelleys.org.uk/dnsmasq/doc.html

Ice9
guru
guru
Posts: 577
Joined: Thu Jan 09, 2003 12:40 am
Location: Belgium
Contact:

Post by Ice9 » Tue Feb 21, 2006 2:32 am

Void Main wrote
If you put it in your /etc/hosts file (on the machine you are trying to ssh from) it should work
You mean I have to change the hostname on the remote host and add THAT hostname to my /etc/hosts file?

Example:

PC1= Icebox
PC2= WS3
Added "WS3" hostname to /etc/hosts and /etc/sysconfig/network on PC2

Should I also add it to /etc/hosts on PC1 in order to be able to connect.
Won't I have to link the hostname to an IP address somewhere, which would be part of my problem because the IP addresses change regularly.

I'll also look into the dnsmasq option, thanks.

User avatar
Void Main
Site Admin
Site Admin
Posts: 5716
Joined: Wed Jan 08, 2003 5:24 am
Location: Tuxville, USA
Contact:

Post by Void Main » Tue Feb 21, 2006 6:56 am

The /etc/hosts files entire purpose is to map hostnames to IP addresses. You didn't put an IP address in there? That's your problem then. Names are only for us humans, the computers could care less about names, they can only connect to each other via addresses and if they don't know the address they aren't going to talk. Format for /etc/hosts is:

xxx.xxx.xxx.xxx hostname1 aliashostname


You don't want to put DHCP assigned mappings in there though because they change as you know, that's where dynamic DNS comes in. You really want to either use DHCP+DNS or make all your machines static and put an /etc/hosts on each machine. I personally use DHCP+DNS as it's all automatic, no configuring again once you set it up. I wrote a HOWTO on it for the full DHCP+DNS but now I use dnsmasq on a Linux based Linksys router. Here's the HOWTO that should show you the concept:

http://voidmain.is-a-geek.net/redhat/fe ... c_dns.html

Post Reply