97

I have a security system and the network setting only allows a three-digit IP address. I can't set it to 192.168.2.100, instead I have to use 192.168.002.100.

Are these two IP addresses different? Do I need to set my router's LAN to be all 192.168.xxx.xxx in order for this to work correctly? I can't find any solid information about this.

Brock Vond
  • 1,073

10 Answers10

106

It depends on the tool.

For most purposes the two will be the same, but not always.

For example, if you use a number starting with a zero, then ping will assume the number is octal.

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users>ping 011.012.013.014

Pinging 9.10.11.12 with 32 bytes of data: Request timed out. Request timed out. Request timed out. Request timed out.

Ping statistics for 9.10.11.12: Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),

Heinzi
  • 4,258
67

Assuming all software you are using is using dot-decimal and subnetting correctly, yes they are the same.

192.168.0.1 for example is only the friendly dot-decimal notation of the dot-binary value 11000000.10101000.00000000.00000001.

Whether you type it as 192.168.0.1 or 192.168.000.001 they are both equal to 11000000.10101000.00000000.00000001

37

It depends on the tools or functions any given program uses to parse the address given. Both Microsoft and Linux as well as other OSes use a POSIX compatible inet_addr() routine for parsing addresses.

Many TCP/IP programs such as Ping and FTP use the inet_addr() sockets function to translate IP address strings into 4-byte addresses. This function accepts an IP address in standard decimal, octal, and hexadecimal notation.
Microsoft KB115388 Ping and FTP Resolve IP Address with Leading Zero as Octal

 

The inet_addr() function converts the Internet host address cp from IPv4 numbers-and-dots notation into binary data in network byte order.

In all of the above forms, components of the dotted address can be specified in decimal, octal (with a leading 0), or hexadecimal, with a leading 0X). Addresses in any of these forms are collectively termed IPv4 numbers-and-dots notation. The form that uses exactly four decimal numbers is referred to as IPv4 dotted-decimal notation (or sometimes: IPv4 dotted-quad notation).
inet_addr(3): Internet address change routines - Linux man page

As such, your specific system might require three-digit decimal notation for each octet, but this is not universal, and care should be taken to ensure the proper IP address is entered.

Of course, only valid numbers for each type will work. Out of range Octal, Hex or Decimal numbers will also fail or cause issues. Octal 088, Hex 0xGG, or Decimal 280 are all invalid examples.

cde
  • 1,856
14

As Lightness Races in Orbit and others have pointed out,

The INET(3) man page describes inet_addr and inet_aton, the standard functions used for converting the "IPv4 numbers-and-dots notation into binary form". It says

...components of the dotted address can be specified in decimal, octal (with a leading 0), or hexadecimal, with a leading 0X).

So technically, NO, an IP address with leading zeros is not (always) the same as one without leading zeros. In your case however, 192.168.2.100 and 192.168.002.100 are identical, because 002 == 2.

Any user interface which requires each component to be exactly three characters in length, with incorrectly-required leading zeros is broken.

6

Some implementations consider octets with leading zeros to be decimal other implementations consider them to be octal. As long as the octet is in the range from 0 to 7, this does not make a difference. So for example would 192.168.002.100 be interpreted as 192.168.2.100 in both implementations.

But if you were to type in an address as 192.168.010.100 it could be interpreted as either 192.168.10.100 or 192.168.8.100 depending on the implementation. It is also not unlikely that implementations do exists, which would consider leading zeros to be a syntax error. Additionally, there are scenarios in which software may insist that you have to use the canonical representation for one reason or another. For all of those reasons, I recommend on avoiding leading zeros when you write an IP address.

If you write software that need to parse an IP address, I would recommend accepting leading zeros, but output a warning to an appropriate location when it happens.

Slightly related there are implementations which allow you to have fewer than four components in the dotted notation. When there are fewer than four components the last component has more than 8 bits and the earlier components have exactly 8 bits. For example 192.168.612 would actually be a valid way to write 192.168.2.100. But again using that notation is not recommended.

kasperd
  • 2,931
0

Just a little tip: In some cases it is important to use zero prefixes in the IP addresses. An example, is Apache .htaccess deny rules.

If you use something like

deny from 11.22.33.22

Apache is so stupid that will also block access from the following IPs:

111.22.33.22

11.22.33.221

211.22.33.221

and in general, any IP address which includes 11.22.33.22

So, just to be sure that you will not block any IPs that you didn't mean to block, you should use:

deny from 011.022.033.022

to be sure that Apache will block access only from the 11.22.33.22 IP address.

0

be careful with this. it SHOULD be the same but it is NOT!
i couldn't find an explanation for this but i can definetly tell that on windows and linux ip addresses with and without leading zeroes are NOT the same! maybe this has to do with converting from other formats like hex or binary.

from my experience with windows and linux it is not tool dependend but os dependend it seems because im running in some problem using ips like 10.08.03.100:

  • note: "10.08.0.1" and 10.09.0.1 could not be found
  • note: "10.010.0.1" is resolved to 10.8.0.1

linux/debian7/8: same results with tool "ping" and "snmpget"

user@test:~$ ping 10.7.0.1
PING 10.7.0.1 (10.7.0.1) 56(84) bytes of data.
^C
--- 10.7.0.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

user@test:~$ ping 10.07.0.1
PING 10.07.0.1 (10.7.0.1) 56(84) bytes of data.
^C
--- 10.07.0.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

user@test:~$ ping 10.8.0.1
PING 10.8.0.1 (10.8.0.1) 56(84) bytes of data.
^C
--- 10.8.0.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

user@test:~$ ping 10.08.0.1
**ping: unknown host 10.08.0.1**
user@test:~$ ping 10.9.0.1
PING 10.9.0.1 (10.9.0.1) 56(84) bytes of data.
^C
--- 10.9.0.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

user@test:~$ ping 10.09.0.1
ping: unknown host 10.09.0.1
user@test:~$ ping 10.10.0.1
PING 10.10.0.1 (10.10.0.1) 56(84) bytes of data.
^C
--- 10.10.0.1 ping statistics ---
1 packets transmitted, 0 received, 100% packet loss, time 0ms

user@test:~$ ping 10.010.0.1
PING 10.010.0.1 (10.8.0.1) 56(84) bytes of data.
^C
--- 10.010.0.1 ping statistics ---
2 packets transmitted, 0 received, 100% packet loss, time 1001ms

windows7/8/10: same results with tool "ping" and "telnet"

(sorry, i dont have an english windows at hand, error tells that host could not be found)

C:\Users\user>ping 10.7.0.1

Ping wird ausgeführt für 10.7.0.1 mit 32 Bytes Daten:
STRG-C
^C
C:\Users\user>ping 10.07.0.1

Ping wird ausgeführt für 10.7.0.1 mit 32 Bytes Daten:
STRG-C
^C
C:\Users\user>ping 10.8.0.1

Ping wird ausgeführt für 10.8.0.1 mit 32 Bytes Daten:
STRG-C
^C
C:\Users\user>ping 10.08.0.1
Ping-Anforderung konnte Host "10.08.0.1" nicht finden. Überprüfen Sie den Namen,

C:\Users\user>ping 10.9.0.1

Ping wird ausgeführt für 10.9.0.1 mit 32 Bytes Daten:
STRG-C
^C
C:\Users\user>ping 10.09.0.1
Ping-Anforderung konnte Host "10.09.0.1" nicht finden. Überprüfen Sie den Namen,

C:\Users\user>ping 10.10.0.1

Ping wird ausgeführt für 10.10.0.1 mit 32 Bytes Daten:
STRG-C
^C
C:\Users\user>ping 10.010.0.1

Ping wird ausgeführt für 10.8.0.1 mit 32 Bytes Daten:
STRG-C
^C
-4

The two IP addresses are different.

However:

  • People would generally consider them the same.
  • Some software would consider them the same.
  • Some software, on some platforms, will consider them different.

If that sounds confusing, it's because there is no standard governing the way IP addresses are supposed to be written, so different programmers at different points in history, and on different platforms, all had different ideas on what should be done.

IP addresses are actually binary, and people tend to use a dotted decimal notation to represent IP addresses. Software can accept various numerical bases (ie decimal, octal, hex) and interpret things various ways based on how you write it. How you write it can tell the software what base you are writing in.

I advise you: do not use leading zeros if you mean to use dotted decimal notation. Some software will consider that a flag to mean that you are entering an octal number. If you mean to enter in a decimal number, you will not get the results that you expect.

I asked a similar question and got some good responses, so if you want to go read up on RFC's, there's good info to be had there.

-6

It should work either way. You can even ping with three-digit numbers and the computer will understand the IP address.

Edit: windows will read it as octal, this only work for Linux.

xR34P3Rx
  • 382
-12

The leading zero is meaningless. The octets are (base-10) 0-255 numbers, not strings.

Since I'm not exactly sure what you're asking (or that you know what question to ask :)): That said, the IP # must be in the same subnet as your network. If you pick 11.12.13.14 within a subnetmask of 192.168.0.0, that device will not be able to talk to or use that subnet.