So I try to do:
and it tells me:
ssh: Could not resolve hostname woofy: Name or service not known
It knows that its own hostname is "woofy"; why can't it connect to itself?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
So we know
woofy. But that name can't be resolved to an IP address.
The short answer is that you need to add an entry for
/etc/hosts. Make it resolve to 127.0.0.1. Or if your system is IPv6-capable, ::1.
Keep a backup of the previous version of
/etc/hosts in case you make a mistake (I use the handy
etckeeper package for this, but if you prefer it ye olde way, you can use a manual backup or even RCS).
The long answer is that how hostnames are resolved to IP addresses is controlled by a set of configuration files which vary slightly between Unix variants. You can configure your Unix system to resolve host names by hosts file (
/etc/hosts will work on almost any Unix system) or by DNS (systems which have direct IP reachability to the Internet will always do this). There are other alternatives too, mostly less widely used (including LDAP and NIS/NIS+). See the Wikipedia article about the Name Service Switch for more context on this.
Edit: if this still causes a DNS lookup, the problem is probably that your Name Service Switch configuration consults DNS before
/etc/hosts so the change to
/etc/hosts has no effect. Try looking at
/etc/nsswitch.conf (how the NSS is configured varies between operating systems).
Unix systems have a notion of host name that isn't related to the network subsystem. That name is what the
hostname command shows and what turns up in logs. When you make an ssh connection, it performs a DNS lookup, to find out what the name means in the context of the TCP/IP protocol family that SSH operates on.
For your sanity, you had better make sure that this host name agrees with what your neighborhood DNS server says, and with what (if anything) your system thinks it's called. In fact, DNS names are not associated with machines, but with network interfaces, so your DNS name will be associated with one of your network interfaces. On machines with no actual network connection, the host name should be associated with the loopback interface.
In practice, the hostname is stored in the file
/etc/hostname on most machines. You can change it at runtime with the
hostname command; this is done early in the boot process. The local idea of the DNS name is stored in
/etc/hosts, on the line corresponding to either the loopback interface (
127.0.0.1) or to one of the machine's network interfaces.