You are not logged in.

#1 2011-02-21 05:59:53

updateleo
Member
Registered: 2008-11-10
Posts: 4

Is there a better way to add aliases to an interface?

Hello All,

I need a little help in adding/binding a few thousand IPs to an interface --e.g. from the wiki:  'https://wiki.archlinux.org/index.php/Co … P_aliasing' the process is to edit the rc.conf and add:
eth0="eth0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255"
eth0_0="eth0:0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255"
.
.
eth0_1000="eth0:0 192.168.X.X netmask 255.255.255.0 broadcast 192.168.X.255"
INTERFACES=(lo eth0 eth0_0 ... eth0_1000)

but this solution does not seem practical; in addition, if I create more than two aliases and do an 'ifconfig' only the first two show -- e.g.
1- stop /etc/rc.d/network
2- edit /etc/rc.conf
eth0="eth0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255"
eth0_0="eth0:0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255"
eth0_1="eth0:0 192.168.0.3 netmask 255.255.255.0 broadcast 192.168.0.255"
eth0_2="eth0:0 192.168.0.4 netmask 255.255.255.0 broadcast 192.168.0.255"
INTERFACES=(lo eth0 eth0_0 eth0_1 eth0_2)
3- start  /etc/rc.d/network
4- ifconfig -a
only eth0 and eth0:0 display

would it be an option to add the 'ifconfig' cmd to the rc.local to bind the IPs after boot?

any help will be appreciated
Thanks

Offline

#2 2011-02-21 07:59:43

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Is there a better way to add aliases to an interface?

With that many ips, I would probably use iproute2 utils (namely ip addr add) instead of ifconfig.
Maybe put some shell scripting in rc.local or create a custom rc.d daemon script to add the ips.

/etc/rc.d/network_holycrap start

Aside: Why in the name of all that is holy would _one machine_ need thousands of IPs!?!?


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#3 2011-02-21 08:55:22

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,237
Website

Re: Is there a better way to add aliases to an interface?

cactus wrote:

Aside: Why in the name of all that is holy would _one machine_ need thousands of IPs!?!?

I'm curious too, but I have a feeling I'm going to regret knowing...

Something like this in rc.local (or your own init script in /etc/rc.d/) should get you going.... Assuming you're using contiguous addresses.

Requires iproute2

/etc/rc.local

/path/to/add_range.sh 192.168.1.1 192.168.1.254 eth0
/path/to/add_range.sh 192.168.2.1 192.168.2.254 eth0
/path/to/add_range.sh 192.168.3.1 192.168.3.254 eth0

add_range.sh

IPADDR_START=$1
IPADDR_END=$2
DEVICE=$3

ipaddr_prefix=${IPADDR_START%.*}
ipaddr_startnum=${IPADDR_START##*.}
ipaddr_endnum=${IPADDR_END##*.}

if [ "${IPADDR_START%.*}" != "${IPADDR_END%.*}" ]; then
        echo $"error: IPADDR_START and IPADDR_END don't agree" >&2; exit 1
fi

if [ $ipaddr_startnum -gt $ipaddr_endnum ]; then
        echo $"error: IPADDR_START greater than IPADDR_END" >&2; exit 1
fi

ipaddr_num=$ipaddr_startnum
ipaddr_clonenum=$CLONENUM_START

while [ $ipaddr_num -le $ipaddr_endnum ]; do
         IPADDR="$ipaddr_prefix.$ipaddr_num"
         ip a a $IPADDR/24 dev $DEVICE
         let 'ipaddr_num=ipaddr_num+1'
         let 'ipaddr_clonenum=ipaddr_clonenum+1'
done

Credit: CentOS network init script; modified (from initscripts package, licensed under GPLv2)

Last edited by fukawi2 (2011-02-21 08:57:29)

Offline

#4 2011-02-21 10:00:18

cactus
Taco Eater
From: t͈̫̹ͨa͖͕͎̱͈ͨ͆ć̥̖̝o̫̫̼s͈̭̱̞͍̃!̰
Registered: 2004-05-25
Posts: 4,622
Website

Re: Is there a better way to add aliases to an interface?

fukawi2 wrote:
cactus wrote:

Aside: Why in the name of all that is holy would _one machine_ need thousands of IPs!?!?

I'm curious too, but I have a feeling I'm going to regret knowing...

haha. yeah.
I fear it will come down to something like "why not just use net.ipv4.ip_nonlocal_bind=1 ?" or "use routing"

tongue

Last edited by cactus (2011-02-21 10:00:36)


"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍

Offline

#5 2011-02-21 15:00:07

updateleo
Member
Registered: 2008-11-10
Posts: 4

Re: Is there a better way to add aliases to an interface?

First of all, thank you for all your replies and I will try them a bit later and let you know of the result.
The reason for adding the IPs on the arch server is because the box will serve as a VOIP simulator (running individual users with a unique IP) to test a soft switch. So eventually I will need to add the max number of IPs a linux box can hold.

Offline

#6 2011-02-21 21:57:58

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,237
Website

Re: Is there a better way to add aliases to an interface?

updateleo wrote:

...the max number of IPs a linux box can hold.

Is there a limit other than hardware capabilities?

Offline

#7 2011-02-22 03:52:10

updateleo
Member
Registered: 2008-11-10
Posts: 4

Re: Is there a better way to add aliases to an interface?

SOLVED
fukawi2, cactus thanks for your help; iproute2 and the script was the solution.
there is no limit on the amount of IPs you can add to linux, but I meant the box I was working with, as it has 8G of memory so I can possibly add six thousand IPs before I start seeing performance issues.

Thanks again.

Last edited by updateleo (2011-02-22 03:52:49)

Offline

#8 2011-02-22 10:46:29

ghen
Member
From: Belgium
Registered: 2010-08-31
Posts: 124

Re: Is there a better way to add aliases to an interface?

It would be more interesting to generalize this.  rc.conf could eg. refer to an external file listing "ip" or "ifconfig" commands to configure the network, like on NetBSD (/etc/ifconfig.<interface>).  And refer to /etc/hostname for the hostname.

This way, /etc/rc.conf could be shared between multiple machines serving the same purpose, and differing only in network configuration.

Offline

Board footer

Powered by FluxBB