Linux - NetworkingThis forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Sorry for asking a dumb question but I couldnt find answer to this question by googling so here I am.
Does an IP address with format such as 010.008.016.040 considered as valid? If yes, where in spec/RFS says it is valid or invalid? Any pointer to that RFS will be highly appreciated.
So I have an IP 10.8.17.91 (in a /22 networn) which I can ping successfully but then if I try to ping 010.8.17.91, there is no response for that ping and if I try to ping 10.08.17.91 it says, unknown host!.
Isn't 10.8.17.91 same as 010.8.17.91 or 10.08.17.91?
Pardon me if I missed any glaring IP format specification which addresses this query.
It is not so much whether an IP address with leading zeros is "valid", it depends very much on what programs the address is being passed to and whether they recognize, and convert, octal notation.
Many programs treat numbers with leading zeros as octal (base 8), others treat them as decimal values with leading zeros. Some accept hexadecimal notation (0x1c for ex.) others do not.
A quick internet search turned up many links to discussions of the subject, but nothing definitive in the context of IP addresses.
So my best answer would be that what is "valid" for IP addresses is that which will ALWAYS be interpreted as the same decimal numeric value, and that would be those without leading zeros in the address components (octets).
In your example address, the leading octet is '10'. That is ten in decimal (0xA in hex, 12 in octal). When you pass it as '010' any programs that recognize octal will take that to be 010 octal, or 8 decimal - a different thing!
It is not so much whether an IP address with leading zeros is "valid", it depends very much on what program the address is being passed to and whether it recognizes octal notation.
Many programs treat numbers with leading zeros as octal (base 8), others do not. Some accept hexadecimal notation (0x1c for ex.) others do not.
A quick internet search turned up many links to discussions of the subject, but nothing definitive in the context of IP addresses.
So my best answer would be that what is "valid" for IP addresses is that which will ALWAYS be interpreted as the same decimal numeric value, and that would be those without leading zeros in the address components.
For example, in your address, the leading octet is '10'. That is ten in decimal (0xA in hex, 12 in octal). When you pass it as '010' and programs that recognize octal will take that to be 010 octal, or 8 decimal - a different thing!
Hope that helps.
Appreciate your inputs here astrogreek.
So the background of this thread was to find whether the passes argument to a program is a valid IP address or not (using bash).
While programming, this scenario came into my mind...
Folks
I got the answer. 010.008.016.040 is NOT a valid IP address but 010.007.016.040 is a valid IP address.
AH! Yes, in base 8, octal notation, '8' is not a valid number token, so sending it '008' means octal '8' which is not valid. '7' on the other hand is a valid octal token so 007 is a valid octal number.
This illustrates that the problem is not about valid IP addresses, but rather about numeric bases.
Quote:
Originally Posted by vrs
Linux systems (and may be other OS as well) treats the format as binary and converts it into decimal and then 'works' on it.
Updating the answer here just in case some one stumble upon this page trying to find out the answer to similar question....
Actually, IP addresses are pretty much always used as binary masks - that is what makes the scheme so efficient in many ways, so what is important is the numeric value used to arrive at the binary representation - i.e. the base of the original number.
We generally pass IP addresses as base 10 values, but if a program recognizes a number with a leading zero as base 8 then it will implicitly use the octal value as the numeric value resulting in a different binary representation.
Anyway, glad you got it working!
Last edited by astrogeek; 11-25-2014 at 02:29 PM.
Reason: The meaning of the first statement c'licked', added explanation...
Actually, IP addresses are pretty much always used as binary masks - that is what makes the scheme so efficient in many ways, so what is important is the numeric value used to arrive at the binary representation - i.e. the base of the original number.
We generally pass IP addresses as base 10 values, but if a program recognizes a number with a leading zero as base 8 then it will implicitly use the octal value as the numeric value resulting in a different binary representation.
Anyway, glad you got it working!
Thanks astrogreek.
I mis communicated in my above reply. It should have read as octal (than binary). Leading zero is converted into decimal (from octal format).
010.008.016.040 -> is not a valid octal (008) where the other 010.007.016.040 is valid octal.
and the remaining missing link is that, since this is not a valid number, that whole 15-character string will be taken as a hostname and an attempt made to look it up on DNS, which fails with "host not found".
BTW, that whole dotted quad address gets converted to a 32-bit number, so "ping 10.8.16.40" is equivalent to "ping 168300584".
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.