Example problem - We have a domain with following DNS records 330.domain.com CNAME 330.blah.domain.com 330.blah.domain.com A 10.0.1.2 foo.domain.com A 10.0.2.2 Now, when I set `search domain.com` in /etc/resolv.conf, I can use SSH to connect to foo like this `ssh user at foo` and I can connect to the 330 A record like this `ssh user at 330.blah` However I cannot connect to the 330.domain.com via `ssh user at 330` - That gets me an error: ssh: connect to host 330 port 22: Invalid argument I'm assuming that when the hostname is pure number, it ignores domain suffix. As just a number cannot be an actual IP, could this behavior be fixed in OpenSSH? Thanks, Martin
> I'm assuming that when the hostname is pure number, it ignores domain > suffix. As just a number cannot be an actual IP, could this behavior be > fixed in OpenSSH?A number _is_ (or can be) a valid IPv4. $ perl -e 'print gethostbyname(shift)."\n"' 65.65.65.65 AAAA $ perl -e 'print gethostbyname(shift)."\n"' 1094795585 AAAA You can leave out parts of the IP address: $ perl -e 'print gethostbyname(shift)."\n"' 65.65 | hd 00000000 41 00 00 41 0a |A..A.| See also http://serverfault.com/questions/638260/is-it-valid-for-a-hostname-to-start-with-a-digit for some more discussion and links.
On Thu, Mar 2, 2017 at 10:46 PM, Martin Rys <spleefer90 at gmail.com> wrote: [...]> `ssh user at 330` - That gets me an error: > ssh: connect to host 330 port 22: Invalid argument > > I'm assuming that when the hostname is pure number, it ignores domain > suffix. As just a number cannot be an actual IP, could this behavior be > fixed in OpenSSH?not really, the behaviour in question is in they system libraries, which think it's an IP address (single numeric, number.number and octal are all valid but uncommon representations of IP addresses). $ gethostip localhost localhost.localdomain 127.0.0.1 7F000001 $ gethostip 330 330 0.0.1.74 0000014A $ telnet 330 Trying 0.0.1.74... telnet: connect to address 0.0.1.74: Invalid argument You can work around it with an entry in ~/.ssh/config: Host 300 Hostname 330.blah.domain.com -- Darren Tucker (dtucker at zip.com.au) GPG key 11EAA6FA / A86E 3E07 5B19 5880 E860 37F4 9357 ECEF 11EA A6FA (new) Good judgement comes with experience. Unfortunately, the experience usually comes from bad judgement.
On Thu, Mar 2, 2017 at 7:09 AM, Darren Tucker <dtucker at zip.com.au> wrote:> On Thu, Mar 2, 2017 at 10:46 PM, Martin Rys <spleefer90 at gmail.com> wrote: > [...] >> `ssh user at 330` - That gets me an error: >> ssh: connect to host 330 port 22: Invalid argument >> >> I'm assuming that when the hostname is pure number, it ignores domain >> suffix. As just a number cannot be an actual IP, could this behavior be >> fixed in OpenSSH? > > not really, the behaviour in question is in they system libraries, > which think it's an IP address (single numeric, number.number and > octal are all valid but uncommon representations of IP addresses). > > $ gethostip localhost > localhost.localdomain 127.0.0.1 7F000001 > > $ gethostip 330 > 330 0.0.1.74 0000014A > > $ telnet 330 > Trying 0.0.1.74... > telnet: connect to address 0.0.1.74: Invalid argument > > You can work around it with an entry in ~/.ssh/config: > > Host 300 > Hostname 330.blah.domain.comNote that SSH is hardly the only tool vulnerable to t his problem. This is why most of us never use raw numbers as shortened hostnames, even if it is convenient on occasion.