-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

How not-to create dozens of files

I sometimes need to assign 10 consecutive ip addresses to an interface on a machine, and found a way not to create 10 configuration files.

Howto

As not shown in the official , I spotted something in the /etc/sysconfig/network-scripts/ifup-aliases file :

range specification files:

One can specify ranges of alised ipaddress using ifcfg-$DEV-range* files. Specify multiple ranges using multiple files, such as ifcfg-eth0-range0 and ifcfg-eth0-range1, etc. In these files, the following configuration variables specify the range:

IPADDR_START    -- ipaddr to start range at. eg "192.168.30.1"
IPADDR_END      -- ipaddr to end range at. eg "192.168.30.254"
CLONENUM_START  -- interface clone number to start using for this range. eg "0"

The above example values create the interfaces eth0:0 through eth0:253 using ipaddrs 192.168.30.1 through 192.168.30.254, inclusive.

Other configuration variables such as NETMASK and BROADCAST may be specified in the range file and will apply to all of the ipaddresses in the range. Range files also inherit configuration from the ifcfg-$DEV file just like normal.

Note that IPADDR_START and IPADR_END are required to be in the same class-c block. I.e. IPADDR_START=192.168.30.1 and IPADDR_END=192.168.31.255 is not valid.

So, let’s test this ! I want as alias to my lo file the ip addresses from 172.16.96.128 to 172.16.96.137 using a /24 prefix and 10.0.0.10 to 10.0.0.15 using a /23 prefix.

cat > /etc/sysconfig/network-scripts/ifcfg-lo-range0 << EOF
IPADDR_START=172.16.96.128
IPADDR_END=172.16.96.137
# Start at 0, we don't have any other aliases configured
CLONENUM_START=0
NETMASK=255.255.255.0
EOF
cat > /etc/sysconfig/network-scripts/ifcfg-lo-range1 << EOF
IPADDR_START=10.0.0.10
IPADDR_END=10.0.0.15
# Start at 10 as we already have other aliases
CLONENUM_START=10
NETMASK=255.255.254.0
EOF
service network restart

Result :

ip addr show lo
=>1: lo:  mtu 16436 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet 172.16.96.128/24 brd 172.16.96.255 scope global lo:0
    inet 10.0.0.10/23 brd 10.0.1.255 scope global lo:10
    inet 172.16.96.129/24 brd 172.16.96.255 scope global secondary lo:1
    inet 172.16.96.130/24 brd 172.16.96.255 scope global secondary lo:2
    inet 172.16.96.131/24 brd 172.16.96.255 scope global secondary lo:3
    inet 172.16.96.132/24 brd 172.16.96.255 scope global secondary lo:4
    inet 172.16.96.133/24 brd 172.16.96.255 scope global secondary lo:5
    inet 172.16.96.134/24 brd 172.16.96.255 scope global secondary lo:6
    inet 172.16.96.135/24 brd 172.16.96.255 scope global secondary lo:7
    inet 172.16.96.136/24 brd 172.16.96.255 scope global secondary lo:8
    inet 172.16.96.137/24 brd 172.16.96.255 scope global secondary lo:9
    inet 10.0.0.11/23 brd 10.0.1.255 scope global secondary lo:11
    inet 10.0.0.12/23 brd 10.0.1.255 scope global secondary lo:12
    inet 10.0.0.13/23 brd 10.0.1.255 scope global secondary lo:13
    inet 10.0.0.14/23 brd 10.0.1.255 scope global secondary lo:14
    inet 10.0.0.15/23 brd 10.0.1.255 scope global secondary lo:15

Well done !

Article originally posted on my old website at this url, but has been enhanced here as it was really small and lacked of an valid/complete example.

-----BEGIN PGP SIGNATURE-----
Comment: GPGTools - http://gpgtools.org

iQIcBAEBCAAGBQJW5eRIAAoJEBeKS2x6xuR7bIwP/AtkK9fL9a8gtUOmF++U8+2n
Ot2H+sXpmj1keTJsiufN+VY8p0zvDomgQbuhbmpWQoql5Cr3K6QhEEFAeYdf/q3m
IzSwt9ybiYKZhL5wDZkWIq/T59QOf2pJ+BrYfCSvjB3CMcUt3IlWM8rECceUUWg5
mbf9WqZ9pXA4EsjESB34umeX+beB19eQLgY48O/f/ru0Te8Uy32hy6z6QjSJ0scu
Fn4zBXxHPADIKLZpHCN6iBXWV20205k9LoVzkEjb9cmisg2CptDHv3JLbMlPixYb
gR32+wVQdNtinOGj4/yLbGmYjhUA8p+dv9Bg6i9pc4pZoD6pPuNf5xoNqSGJSX29
gO19w+viCLM48Dn4/2ltt6L/pmyx9MwRqcf/JX2GkC05rVqXKHqUyoQ5obtqnwOs
Vk79Xdvl+KJre2FjW8NnAjjLvXtbGWZqhi/ujxxu7+gF13Nz0ZXXeMd8q16ZtbD7
4hAaVO61OrNiS0J4tZ7TU493zxhkyxkkZAsYRMz0xqkOkH9UrUOONwCtP6nQ1iqN
1D7yCNx2gUGknXqqKR+4Td+O1BlIkseJddugg1va/7wM06mlfcXyBeCI2u3ijbtZ
2CdUxSy1SPYWE4f73qD4GMGbkmNOaKda7TQxJ8S88rP28DTbyHZsA2NZx50y2bAH
RgqiwyLM0D03tADbhpIq
=3XIP
-----END PGP SIGNATURE-----

Hint: To validate signature, please view page source and copy html code between BEGIN PGP Signed message and END PGP Signature anchors.

Created the 2009-12-23

Share this


Article content

Resources

10 last blog posts

Related to this article

blog comments powered by Disqus