Solaris tip of the week: unique private subnets for your local zones
If you tried my earlier suggestion and created your own development environment based on Solaris zones,
(global zone as firewall to set of local zones on a private subnet),
you might have encountered the following conflict when deploying two of these environments to the same subnet:
# ifconfig -a
...
bge0:5: flags=4201100842<BROADCAST,RUNNING,MULTICAST,ROUTER,IPv4,CoS,DUPLICATE> mtu 1500 index 2
zone zone6
inet 172.0.1.6 netmask ffffff00 broadcast 172.0.1.255
...
The ifconfig output indicates that the interface could not be brought up because there is a duplicate IP found on the same subnet.
We can be a little smarter in selecting a default subnet - to guarantee uniqueness, let's select the 4th octet of the
primary hostname to construct our private subnet.
For example:
# hostname
opensolaris
# getent hosts opensolaris
192.168.1.200 opensolaris
The idea is to use the 4th octet (200) to define the private subnet for our local zones. In a 24-bit subnet (255.255.255.0) the 4th octet is guaranteed to be unique.
Thus instead of defaulting our subnet to 172.0.1.0, our unique private subnet address is:
octet4=`getent hosts \`hostname\` | awk '{print $1}' | awk -F\. '{print $4}'`
defaultSubnet=172.0.${octet4}.0
echo $defaultSubnet
172.0.200.0
Regards,
Jay
(global zone as firewall to set of local zones on a private subnet),
you might have encountered the following conflict when deploying two of these environments to the same subnet:
# ifconfig -a
...
bge0:5: flags=4201100842<BROADCAST,RUNNING,MULTICAST,ROUTER,IPv4,CoS,DUPLICATE> mtu 1500 index 2
zone zone6
inet 172.0.1.6 netmask ffffff00 broadcast 172.0.1.255
...
The ifconfig output indicates that the interface could not be brought up because there is a duplicate IP found on the same subnet.
We can be a little smarter in selecting a default subnet - to guarantee uniqueness, let's select the 4th octet of the
primary hostname to construct our private subnet.
For example:
# hostname
opensolaris
# getent hosts opensolaris
192.168.1.200 opensolaris
The idea is to use the 4th octet (200) to define the private subnet for our local zones. In a 24-bit subnet (255.255.255.0) the 4th octet is guaranteed to be unique.
Thus instead of defaulting our subnet to 172.0.1.0, our unique private subnet address is:
octet4=`getent hosts \`hostname\` | awk '{print $1}' | awk -F\. '{print $4}'`
defaultSubnet=172.0.${octet4}.0
echo $defaultSubnet
172.0.200.0
Regards,
Jay