20090531

Solaris IP shortcuts

Today, I had to modify my routing table under Solaris 10u7 (5/09), and I made a typo.
Instead of writing 10.0.2.1, I typed 10.0.21... and it has worked.

sol10u7 [~]# route add default 10.0.21
add net default: gateway 10.0.21
sol10u7 [~]# netstat -rn

Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ---------- ---------
default 10.0.0.21 UG 1 0
10.0.0.0 10.0.2.16 U 1 0 e1000g0
224.0.0.0 10.0.2.16 U 1 0 e1000g0
127.0.0.1 127.0.0.1 UH 1 54 lo0


I've also tried to use 10.1 and 10.1.1, and another success has been met.

sol10u7 [/etc/krb5]# route add default 10.1
add net default: gateway 10.1
sol10u7 [/etc/krb5]# netstat -rn

Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ---------- ---------
default 10.0.2.2 UG 1 0
default 10.0.0.1 UG 1 0
10.0.0.0 10.0.2.16 U 1 24 e1000g0
224.0.0.0 10.0.2.16 U 1 0 e1000g0
127.0.0.1 127.0.0.1 UH 1 58 lo0
sol10u7 [/etc/krb5]# route add default 10.1.1
add net default: gateway 10.1.1
sol10u7 [/etc/krb5]# netstat -rn

Routing Table: IPv4
Destination Gateway Flags Ref Use Interface
-------------------- -------------------- ----- ----- ---------- ---------
default 10.0.2.2 UG 1 0
default 10.0.0.1 UG 1 0
default 10.1.0.1 UG 1 0
10.0.0.0 10.0.2.16 U 1 24 e1000g0
224.0.0.0 10.0.2.16 U 1 0 e1000g0
127.0.0.1 127.0.0.1 UH 1 58 lo0

The deletion works in the same manner.

sol10u7 [~]# route delete default 10.0.21
delete net default: gateway 10.0.21

Nice. Is it a bug, or is it a feature ;-) ?
I know there's a similar IPv6 behaviour - reducing the number of Zeros in address notation, but I didn't know it's also related to IPv4.

2 comments:

Unknown said...

I once was as surprised as you, when in a TCP/IP class, the teacher told us that 10.1 and even 10.300 are both valid IP addresses.

The thing is that 10.* is a Class A network, so unless you specify the netmask, your OS will understand you specified a /8. That mean first 8 bits are the network address (10), while the other 24 bits represent the host address (no subnetting done here).

Look at those example:

root# ifconfig nge0:1 10.1
root# ifconfig nge0:1
nge0:1:
inet 10.0.0.1 netmask ff000000 broadcast 10.255.255.255
root# ifconfig nge0:1 10.300
root# ifconfig nge0:1
nge0:1:
inet 10.0.1.44 netmask ff000000 broadcast 10.255.255.255

This is not a bug, it's perfectly correct, following IP rules.

Marcin Wiśnios said...

Thank you for the profound explanation.