0

I have a server (Ubuntu 14.04) and want to assign these multiple public ip addresses.

Expected:

  • I want to ping all IP-Addresses from XXX.XXX.XXX.128 to XXX.XXX.XXX.143

Current Setup:

  • IP-Addresses XXX.XXX.XXX.128/28 (255.255.255.240)
  • I can only ping XXX.XXX.XXX.128
  • Interface configuration (/etc/network/interfaces):

    auto eth0:0
    iface eth0:0 inet static
        address XXX.XXX.XXX.128
        netmask 255.255.255.240
    
René Preuß
  • 11
  • 1
  • 2
  • A big problem is that the `x.x.x.128` address is the subnet address (unusable), and the `x.x.x.143` address will be the broadcast address (also unusable). – Ron Maupin Jan 10 '16 at 13:36

3 Answers3

4

You can specify multiple IP addresses simply by defining multiple interfaces on the same device in your interfaces file. For example:

auto eth0
iface eth0 inet static
  address 192.168.0.129
  netmask 255.255.255.240
iface eth0 inet static
  address 192.168.0.130
  netmask 255.255.255.240

and so on. In older versions you needed to use the eth0:0, eth0:1, eth0:2 etc. syntax when defining interfaces to do this but I'm fairly sure 14.04 supports it without.

Other ways of doing the same thing include using the "up" line in the iface stanza to add extra IPs when you bring the interface up, as so:

auto eth0
iface eth0 inet static
  address 192.168.0.129
  netmask 255.255.255.240
  up /sbin/ip address add 192.168.0.130/28 dev eth0
  down /sbin/ip address delete 192.168.0.130 dev eth0

The down clause is recommended to ensure that the interface is brought down cleanly if it is ever shut down or disconnected. You can specify multiple up or down commands, or perhaps in your case as you have a large list of ips you want to add to the interface, call a script which uses the ip command to add/remove the desired IPs.

Bear in mind that in the subnet you've defined, .128 and .143 are reserved as the network and broadcast addresses, so you shouldn't assign those to an interface. You also haven't specified a default gateway for outgoing traffic. The subnet mask isn't used to declare "I want all these IPs", it is information about the network that the interface is on, allowing the system to work out whether it can send traffic directly to an IP (if it's in its local subnet) or it needs to be routed via a gateway (defined on the interface using a "gateway A.B.C.D" line). You should find out what the actual subnet mask and gateway details are for your network if the /28 isn't accurate.

Carcer
  • 919
  • 5
  • 12
1

From the cli you can use ip addr add <ip address/netmask> dev <devicename> for example

ip addr add XXX.XXX.XXX.129/28 dev eth0

You could use a simple for loop to loop over the last octet. Don't forget also that x.x.x.128/28 only has 14 usable addresses as .128 is the network address and .143 is the broadcast and as such aren't useable.

user9517
  • 114,104
  • 20
  • 206
  • 289
1

In addition to the answer of Iain:

  • The syntax you're using (eth0:0) is legacy and deprecated.

  • If you want to use the IPs permanently, use the following as a hint on how to use /etc/network/interfaces:

    auto eth0
    iface eth0 inet static
        [insert your current settings]
        up   ip addr add XXX.XXX.XXX.129/28 dev $IFACE label $IFACE:0
        down ip addr del XXX.XXX.XXX.129/28 dev $IFACE label $IFACE:0
        up   ip addr add XXX.XXX.XXX.130/28 dev $IFACE label $IFACE:1
        down ip addr del XXX.XXX.XXX.130/28 dev $IFACE label $IFACE:1
        [continue for all your IPs accordingly]
    
gxx
  • 5,483
  • 2
  • 21
  • 42