[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: hostname of remote computer



Seb wrote:
> I use SSH to connect to a laptop computer that is in an institutional
> network.  I would like to set an entry for it in my local /etc/hosts, so
> that I don't have to type the IP address every time I want to connect to
> is and simply use an alias.

I assume the laptop gets a dynamic address from DHCP and doesn't
register a dynamic DNS address for it?

If you only need this for ssh then you can add an entry in your ssh
configuration file ~/.ssh/config similar to this one:

Host foo.example.com
  Hostname 192.0.32.10
  HostKeyAlias foo.example.com

And if you don't want to type in the full name you can set up a short
hostname for it too.

Host foo
  Hostname 192.0.32.10
  HostKeyAlias foo.example.com

> As per the man page, /etc/hosts has:
> 
> IP_address canonical_hostname [aliases]

That means something like this:

  192.0.32.10  foo.example.com  foo  bar

The IP address is first on the line.  The next entry is taken as the
fully qualified domain name when converting from IP address to name.
Any additional entries on the line are taken as additional aliases.
Note that the FQDN (fully qualified domain name) does not mean the
canonical name.  I know the man page says that but times have
changed.

> To get the canonical_hostname I thought I'd easily get it by typing
> "dnshostname" when logged into the remote laptop, but that returns
> nothing, and "domainname" returns '(none)'.  How should this
> canonical_hostname be specified in this case?

Normally you would look up the IP address in DNS and see what PTR
record is returned for it.  That name is typically the canonical
hostname.

  $ host quantz.debian.org
  quantz.debian.org has address 206.12.19.122

  $ host 206.12.19.122
  122.19.12.206.in-addr.arpa domain name pointer quantz.debian.org.

So here we would say that the canonical name is quantz.debian.org but
it does also have other names.

  $ host qa.debian.org
  qa.debian.org has address 206.12.19.122

But many hosts don't really have canonical hostnames anymore.  Not
since the addition of dual homed or multi-networked hosts with
potentially several IP addresses possibly on each network interface
not to mention VPN addresses.  Because then it is possible for a host
to have multiple names in the reverse DNS for the different IP
addresses.  So with that in mind a host really doesn't have one single
canonical name in many cases.  But when it does that is what we call
it.

Bob

Attachment: signature.asc
Description: Digital signature


Reply to: