As requested via a bug report, network configuration now supports bash expansion. This will make giving servers multiple IP addresses a snap. Here's an example

config_eth0=( "192.168.0.{1..20}/24 brd +" ) gives you 20 IP addresses.

config_eth0=( "192.168.{1..20}.{1..20}/24 brd +" ) gives you 400 IP addresses. (20x20)

config_eth0=( "192.168.{1..20}.{1..20}/24 brd 192.168.{1..20}.{1..20}" )
Currently doesn't work as expected - it tries to add 160000 IP addresses with most of them duplicates thanks to a sequence in the broadcast field. Not sure how to solve this at present - but I don't see it as that much of a problem at this time.

The problem is that to get the first two examples working correctly, I need to replace spaces with _ (any char will do as long as it's not space) so that expansion works just by clever use of quoting and arrays - no loops.

Here's the current code - which accepts a string and returns an array

expand_parameters() {
    local x="$( eval echo ${@// /_} )"
    local -a a=( ${x} )
    a=( "${a[)
    a=( "${a[@](@]/#/\"}")/%/\"}" )
    echo "${a[*]//_/ }"
}

Any ideas about how to fix it are welcome :)

Next Post Previous Post