Problem :
I am setting up a machine that I will use in a test network and which will host many web sites. I would like this host to have many (on the order of 20k) IP addresses.
I know I could add them all with a script doing, say
ip addr add <ip>/<mask> dev eth0
and get them all that way. In fact, that works just fine, but it does not survive a reboot obviously.
If I modify /etc/sysconfig/network-scripts/ifcfg-eth0
I can assign a static IP that will be persistent, but I don’t believe I can assign more than one that way.
Is there a way to assign a lot of static IPs persistently?
I suppose at worst I could create my own IP service and have it run the ip
commands via a systemd service, but I was wondering if there is a more canonical way to do this.
Solution :
I haven’t checked if it supports 10s of thousands, but it seems that you can specify many addresses within the ifcfg-
file directly if you tell NetworkManager you’re going to do so.
The first step was to tell NetworkManager which I did as
nmcli con mod eth0 ipv4.method manual
Then I modified /etc/sysconfig/network-scripts/eth0
so it had
IPADDR0=<ip0>
NETMASK0=<mask0>
IPADDR1=<ip1>
NETMASK1=<mask1>
and then eth0
had both of those addresses (after a reboot at least).
Update: Alas for me, this method only allows up to 256 addresses per interface. (You can see the limit for version 0.9.10 which ships with Fedora 21 in the source on line 1366 of src/settings/pluginos/ifcfg-rh/reader.c if you’re interested.)
It’s easy, when you figured it out.
I know two ways, either individual ifcfg-eth:x
files for single addresses or ifcfg-eth0-rangex
files for IP ranges. The file is placed in /etc/sysconfig/network-scripts/
folder.
So first case. Just copy /etc/sysconfig/network-scripts/ifcfg-eth0
to /etc/sysconfig/network-scripts/ifcfg-eth0:0
. Open it in an editor and change DEVICE to eth0:0 and IPADDR to what you want. The reload your network(systemctl restart network
on centos 7). Repeat step and increase x with one.
Second case you copy /etc/sysconfig/network-scripts/ifcfg-eth0
to /etc/sysconfig/network-scripts/ifcfg-eth0-range0
. Then open the file in an editor and replace IPADDR with IPADDR_START and add IPADDR_END with the corresponding start and stop IPs of the range. Reload the network as mentioned before and the changes are active.
copy /etc/sysconfig/network-scripts/ifcfg-eth0
to /etc/sysconfig/network-scripts/ifcfg-eth0:0
and edit it
DEVICE="eth0:0"
BOOTPROTO="static"
IPADDR=192.168.230.252
NETWORK=192.168.230.0
NETMASK=255.255.255.0
IPV6INIT="yes"
NM_CONTROLLED="yes"
ONBOOT="yes"
you must be on same network.
reboot.
If you can’t reboot try ifconfig eth0:0 up
(didn’t test this part)
see http://www.cyberciti.biz/faq/linux-creating-or-adding-new-network-alias-to-a-network-card-nic/