Non hexadecimal ifconfig (Solaris 8, 9 & 10) August 6, 2007
Posted by claudio in Uncategorized.Tags: Perl, Solaris, UNIX
trackback
Solaris is nice, but its ifconfig is pretty annoying. It gives you an hexadecimal netmask.This gives you two choices. One learn to decipher all those f’s or write a ridiculous small wrapper script. Guess what I did.
Here is what a typical ifconfig output looks like in Solaris:
root@labo:~# ifconfig -a
lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
hme0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 10.0.81.9 netmask ffffff00 broadcast 10.0.81.255
ether 0:3:ba:10:aa:51
root@labo:~# ifconfig hme0
hme0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 10.0.81.9 netmask ffffff00 broadcast 10.0.81.255
ether 0:13:bb:15:aa:11
This is what is looks like with the wrapper:
root@labo:~# ifconfig_new -a
lo0: flags=1000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4> mtu 8232 index 1
inet 127.0.0.1 netmask 255.0.0.0
hme0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 10.0.81.9 netmask 255.255.255.0 broadcast 10.0.81.255
ether 0:3:ba:10:aa:51
root@labo:~# ifconfig_new hme0
hme0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 10.0.81.9 netmask 255.255.255.0 broadcast 10.0.81.255
ether 0:13:bb:15:aa:11
The script is written in perl and it uses the Solaris shipped version. No additional modules where used.
You can download the script here. The checksum of the script is fb26efd3f1c804ed7019c4ced37c2563.
For reference, you could always just keep your netmasks in hex since they make more sense that way anyhow:
ifconfig hme0 10.0.81.9 netmask 0xffffff00 broadcast + up