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
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.

- 115
- 5

- 27,737
- 3
- 37
- 69
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
.
.
.

- 115,471
- 20
- 215
- 297
Linode published a great article on how to do this

- 4,657
- 1
- 17
- 29
-
Note that this doesn't cover how to add a range. It just describes the "descriptive method", i.e. multiple `iface eth0:1` stanzas. – Alastair Irvine Mar 20 '14 at 05:23
-
This link has rotted. While you're at it, add something relevant to this answer so it can stand alone. – sysadmin1138 Apr 04 '21 at 21:21
You can probably only add every IP on its own to a virtual interface. Refer to this FAQ entry.

- 328
- 4
- 22