1

I want add a range or IP address 192.168.1.128 to 192.168.1.254 to my debian host I know, there is an range file (such as ifcfg-eth0-range0) in RedHat/CentOS, they have IPADDR_START/IPADDR_END, but how to do in debian?

4 Answers 4

2

You could an ifup to use a script to add the addresses for you. Create the following script as /etc/network/if-up.d/eth0

#!/bin/bash

if [ "$IFACE" eq "eth0" ]; then
    for IP in {128..254}; do
        ip addr add 192.168.1.${IP}/24 dev eth0
    done
fi

# EOF

/24 should be replaced by the appropriate subnet mask.

A corresponding script in /etc/network/if-down.d/eth0 should be created using "ip addr" del in place of "ip addr add".

Be sure to run chmod +x on both scripts.

You can test the script using the command IFACE=eth0 /etc/network/if-up.d/eth0.

You could also create the file as /usr/local/sbin/eth0-aliases and run it from an up option in /etc/network/interfaces. Add up /usr/local/sbin/eth0-aliases to the eth0 stanza. If you use this mechanism you don't need the if condition in the script.

1

You have to do it manually for each interface. Edit /etc/network/interfaces and add each one to that e.g.

auto lo
iface lo inet loopback

auto eth0
auto eth0:1
auto eth0:2
iface eth0 inet static
         address 192.168.10.1
         netmask 255.255.255.0
         gateway 192.168.10.100

iface eth0:1 inet static
         address 192.168.10.2
         netmask 255.255.255.0
         gateway 192.168.10.100

iface eth0:2 inet static
         address 192.168.10.3
         netmask 255.255.255.0
         gateway 192.168.10.100
.
.
.
0

Linode published a great article on how to do this

http://www.linode.com/wiki/index.php/Multiple_IPs

2
  • Note that this doesn't cover how to add a range. It just describes the "descriptive method", i.e. multiple iface eth0:1 stanzas. Mar 20, 2014 at 5:23
  • This link has rotted. While you're at it, add something relevant to this answer so it can stand alone.
    – sysadmin1138
    Apr 4, 2021 at 21:21
-1

You can probably only add every IP on its own to a virtual interface. Refer to this FAQ entry.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .