Edit non-global zone IP address - non-interactively

Hi there

I have a global zone with 178 zones on it :slight_smile:

The entire box is moving to an entirely new network and I need to write a script that will configure the zones config file in /etc/zones for each of them changing the IP address - but non-interactively

The line I need to change would be , for example

<network address="10.10.10.90" physical="nxge1"/>

to a new IP ..

is there a way of me doing a 'one liner' to change the IP?

any help would be greatly appreciated

sed -E '/network address/ s#"([0-9]{1,3}\.){1,3}[0-9]{1,3}"#"new IP"#' file1
<network address="new IP" physical="nxge1"/>

If your sed doesn't have the -r or -E option (for extended regexes) , you'll need to escape the parentheses and braces.

Directly editing the zone configuration files is both risky and unsupported, as the embedded comment says:

Here is a method based on zonecfg:

while read name old new; do
    zonecfg -z $name "select net address=$old; set address=$new; end; exit"
done <<%
zone1 192.168.1.1 10.10.10.90
zone2 192.168.1.2 10.10.10.92
zone3 192.168.1.9 10.10.10.100
%
1 Like

assuming solaris 11.2 and static ipaddresses:

set allowed-address=10.10.20.97/24
set configure-allowed-address=true
set physical=net9

that's part of

zonecfg -z zonename export -f zonecfg.xml

which you can then modify with sed

sed -e 's/10.10.20.97/127.0.0.1

thanks for all your help guys, I will use a combination of the above to get the job done :slight_smile:

Avoid editing the zone xml file - use zonecfg. You can break something without ever knowing it. And yes, I agree the zonecfg interface is convoluted, but you can render the zone unbootable very easily by directly modifying the file.

If you do succumb to editing at least try to verify the change:

zonecfg -z zname
> verify