On Fri, Jan 21, 2022 at 09:34:35PM -0500, gene heskett wrote: > /etc/resolv.conf has: > search coyote.den > nameserver 192.168.xx.1 > > the search line says to look in the /etc/hosts file, failing that, the > nameserver line sends the dns lookup query to the router
No, that's not correct. The config file that says "look in /etc/hosts first, then look in DNS next" is /etc/nsswitch.conf. Specifically, it's the line that begins with "hosts:" in that file. The "search" line in /etc/resolv.conf means "if I type ftp roadrunner, I want it to act as if I had typed ftp roadrunner.coyote.den". In other words, it's the default DNS search domain for looking up the *other computers* on your local area network. > However when I set hostname with hostname, the 169.bs stays out of the > picture and networking works the world until a reboot. Well, yes. The "hostname" command sets the current hostname, which resides in memory only. It has no permanent effect. And it has nothing at all to do with IP addresses. Or DNS. > Setting the hostname with hostnamectl to the alias in /etc/hosts for this > machine, gets me exactly the same hostname but then the route reported by > "ip a" is the 169.bs.bs.bs and I can't get out of my shirt pocket to even > ping the router at 192.168.xx.1. Routing has nothing to do with your system's hostname. At all. At the most basic level, your system's default route is set by whatever mechanism sets up your network interfaces. On Debian, this can be any of *several* different pieces of software, depending on what's installed and what you've got in your config files. In the *most* basic possible configuration, your routing table will be one automatic entry for your ethernet interface (created from the IP address and netmask which are assigned to that interface), and then one "default" route which is assigned for reaching every host that's *not* part of your LAN. E.g. in /etc/network/interfaces you'd have something like this: auto enp2s0 iface enp2s0 inet static address 192.168.1.21/24 gateway 192.168.1.1 This tells the "ifupdown" software package that you'd like it to manage the enp2s0 network interface, assigning the IP address 192.168.1.21 with a 24-bit netmask, which automatically creates a route to the 192.168.1.0/24 network. In addition, it will create a default route via the 192.168.1.1 address. None of this has *anything* to do with your system's hostname. None of this has *anything* to do with your /etc/hosts file. None of this has *anything* to do with DNS. Of course, there are many other ways to configure network interfaces in Debian. You might be using Network-Manager, for example. Or systemd's systemd-networkd(8). Or you might be using /etc/network/interfaces but telling it to ask for configuration from DHCP. Also, by the way, "ip a" does not report routes. That's "ip r". unicorn:~$ ip r default via 10.0.0.1 dev lan0 10.0.0.0/24 dev lan0 proto kernel scope link src 10.0.0.7 ------------------------------------ You're probably still confused. Let's go over everything again, from the beginning. Your computer has a *network interface*. This interface has some kind of name. The names are very complicated and I don't want to introduce that particular piece of complexity here. Let's say that you've somehow managed to determine your interface's name. Let's say, for this example, that your interface's name is enp2s0. In order for your network interface to *work*, it has to be assigned an IP address and a netmask. This can come from DHCP, or it can come from files that you configure on your system. With an IP address and a netmask, you will be able to communicate with other computers on your *local area network*, by using their IP addresses. If you have a default route, then you can potentially talk to computers *outside* of your LAN. This default route can come from DHCP, or from local files. E.g. with a properly configured default route, you will be able to run commands like "ping 8.8.8.8" and get responses. If you'd like to communicate with other computers by name instead of by IP addresses, you can either put their names and IP addresses in the /etc/hosts file (a simple text file), *or* you can configure your computer to use DNS. DNS is configured in the /etc/resolv.conf file. The most basic piece consists of "nameserver" lines which contain the IP addresses of DNS resolvers which will look up computer names for you. These nameservers can come from DHCP, or they can be configured in your local files. Your computer can also have a hostname. This is how your computer identifies itself when it logs things, so that you can tell which computer wrote which piece of the logfile. Your computer can be named whatever you like. Its name has meaning only to you. Other computers do not know what your hostname is, and they do not care. If you want other computers to be able to contact you by a name, then you add that name to DNS, *or* to the /etc/hosts files of those other computers. The name that you put in DNS or other machines' /etc/hosts files does *not* have to be the same as your hostname. Your hostname is private. It's what your computer calls itself. It's not what other computers call you. Your computer can also have a *list of search domains* for use in hostname lookups. This is typically something you'd only care about if you have a LAN with multiple computers on it, which all want to talk to each other. If you're just a single computer that's on the Internet, you *do not care* about this at all. The main purpose of a list of search domains is to save typing. Let's say you've got a LAN with hosts that are (publically) called "cat.coyote.den" and "dog.coyote.den". If you want to log into the first one, you could type "ssh cat.coyote.den". But that's a lot of typing. If you have "coyote.den" in your list of search domains, then you can simply type "ssh cat". The host resolver will try each of the domains in your search list, one by one, as suffixes, until one of them works. This list of search domains is configured in your local /etc/resolv.conf file. It can be a static entry, or it can come from DHCP.