Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I set up my hostname to a number, where running hostname gives:

6592

But when I run ping 6592, I get:

connect: Invalid argument

I checked the related Wikipedia page, and it does say that such a hostname is allowed (IIUC). What am I missing?

share|improve this question
add comment

2 Answers 2

up vote 11 down vote accepted

What the RFC says is actually immaterial here. The RFC specifies what goes on at the DNS level, but that's moot if ping doesn't make a DNS query in the first place. When ping receives an all-numeric argument, it interprets it as an IP address.

IPv4 addresses are technically 32-bit numbers. They are almost always written in dot-decimal notation, so-called “dotted quads” like 127.0.0.1. But they can also be written as a single number in decimal like 2130706433 or in hexadecimal like 0x7f000001.

$ ping 2130706433    # 127*2^24 + 1
PING 2130706433 (127.0.0.1) 56(84) bytes of data.
64 bytes from 127.0.0.1: icmp_seq=1 ttl=64 time=0.027 ms
$ ping 0.0.25.192
connect: Invalid argument

Addresses in the range 0.0.0.0/8 are reserved for use as source addresses in broadcasts. You can't send a packet to them, which is why connect(2) returns EINVAL.

Many programs, including most ping implementations, have no option to force a DNS lookup. You would run into similar trouble if you made a local network with all-numeric subdomains, and ended up with a valid hostname that looked like a dotted quad.

If your local network has a name, ping 6592.mynetwork will work. But you're likely to run into similar trouble down the line, as sooner or later you'll want to omit the domain name. Just go with the flow and include a letter, preferably at the start.

share|improve this answer
add comment

Well, not exactly... What Wikipedia, and in turn the RFCs say is that since the original RFC 952, which didn't allow leading numerics, you can now have them. ( Per RFC 1123 ) You still can't have all numeric though, which is your problem.

Your '6952' isn't a valid hostname, while '6952x' should be fine. But, RFCs aside, I've had problems within the last year or so with leading numerics. I'd avoid them, unless there's a compelling reason not to.

share|improve this answer
    
Can you quote where in RFC 1123 where it's said the name can't be entirely numeric. I can't find it. –  Tshepang Feb 25 '11 at 12:28
    
Exactly, the only thing I found was this: a segment of a host domain name is now allowed to begin with a digit and could legally be entirely numeric (see Section 6.1.2.4). –  Justin Ethier Feb 25 '11 at 12:46
    
The statement you quoted doesn't address my question. Maybe you misunderstood (or I'm missing something?). –  Tshepang Feb 28 '11 at 4:25
1  
I think there's ambiguity in the text between the original, 'no leading numeric' RFC and the later 'leading numeric OK' version. That's the point. All I know is fully-numeric hostnames cause frequent breakage, so they're a poor practice. RFCs are not laws, nor are they guaranteed to be perfectly implemented. –  pboin Feb 28 '11 at 14:28
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.