Create new subnet over existing subnet

I have three servers that currently have ips 192.168.1.1, 192.168.1.2, and 192.168.1.3. They can see each other and talk to each other. I would like to create a second subnet, on top of the 192.168.1.x, which is 10.170.x.x.

I can assign ips to each of the three servers, 10.170.0.1, 10.170.0.2 and 10.170.0.3, with ip addr add 10.170.0.1 dev eth0. The problem I'm having is how to do the routing. I can't ping any server over the 10.170.x.x network. I believe that I need to create some peer-to-peer bridges but I have no clue on how to get started. Any ideas?


Solution 1:

As has been noted by others, when you use ip address add and don't provide a network mask or CIDR range, /32 is assumed, and so no routes are created for the subnet.

To resolve the issue, you add the CIDR range as well:

ip addr add 10.170.0.1/16 dev eth0

To make the change persistent you add it to /etc/network/interfaces. This can be done the cheap and dirty way through a post-up command, but the proper way is to add a second stanza containing only that address:

auto eth0
iface eth0 inet static
    address 192.168.1.1
    netmask 255.255.255.0
    gateway 192.168.1.250

iface eth0 inet static
    address 10.170.0.1
    netmask 255.255.0.0

Note in particular that, despite what you will read in outdated Internet guides, you should not use eth0:0 for the second IP address. This form is deprecated and has been for years (which means it is likely to be removed from Linux at any time).

Solution 2:

Try doing ip addr add 10.170.0.1/16 dev eth0 so you're specifying a netmask. I bet they're adding in the /32 IP space otherwise (though I have not confirmed that).