1

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?

6
  • 1
    Maybe it's a route issue ? What's netstat -r output ? – Nabil Bourenane Apr 1 '15 at 15:19
  • What network are you pinging them from? Are you pinging the servers from the servers or from another host? – joeqwerty Apr 1 '15 at 15:38
  • @joeqwerty I'm pinging 10.170.0.1 from 10.170.0.2. No response. – Ricardo Marimon Apr 2 '15 at 14:07
  • What do you mean by "on top of"? – Michael Hampton Apr 4 '15 at 18:03
  • @MichaelHampton by "on top of" I mean that the actual packets travel over the existing 192.168.x.x subnet. It is like renaming the existing subnet to a new one. – Ricardo Marimon Apr 4 '15 at 18:17
12
+200

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

0
3

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

1

This is an interesting challenge to which there are a number of solutions. The wording of your question does leave some questions, but I think from context I have an idea what you're trying to do.

I assume these hosts are all on the same physical network segment - e.g. connected to a hub or switch and can ping each other on the 192.168.1.x network without going through a router. In this case, you really want a second network in parallel to the original - a slight nitpick, but relevant to understanding what's happening, I think.

I do think it's likely that Eric Renouf's answer above is hot on the trail - by default iproute2 is likely to add a 32-bit netmask - 255.255.255.255 - which is correct in a number of situations where routing is involved / necessary, such as at a large hosting provider where some machines have several IP addresses, handed out over time. You likely want a 24-bit netmask - 255.255.255.0 - or even a 16-bit, if you truly intend to use the entire 10.170.x.x space.

As an aside, the '.x.x' bit of the addresses is really an important detail here, typically we would describe a network using its' "network address", the bottom address in a particular subnetted range. In this case, your network addresses are 192.168.1.0/24 and 10.170.0.0/16. It's possible to have subnets smaller than class C-sized / 24-bit, where the network address isn't zero. I won't go into too much detail, but strongly suggest investing some time reading about subnetting.

Now that we know to avoid the default netmask, and why, consider:

ip addr del 10.170.0.1 dev eth0
ip addr add 10.170.0.1/16 dev eth0

Repeat on each machine. If you want these configured at boot, also consider adding this line as as post-up command in /etc/network/interfaces.

Hope this helps!

1

I was able to get this working by adding a route with a source address:

for the 192.168.1.1 / 10.170.0.1 machine, it would be

$ ip route add 10.170/16 dev eth0 src 10.170.0.1

more generally

$ ip route add 10.170/16 dev eth0 src "ip address of host"

0

I think the right way to do it is as follows:

  • create subinterfaces (e.g. eth0:1) for the new subnet,
  • assign sub interfaces to a tagged VLAN (you may need to install vlan package if you host is linux)
  • configure VLAN with the same ID on your router AND you switch,
  • do normal destination based routing between your 198.168.1.x network and 10.170.x.x network with your router.

This may or may not work if servers attached to unmanaged switch, but with "smart" or managed switches this is not a problem.

I have this configuration working with 2 IPv6 networks from different providers with bunch of hosts with a single ethernet interface communicating on both networks and it works great.

0

You just need to check your routing, I think you just missed that.

ip route show

Probably, what failed there is that you've assigned the IP address to each host without indicating the network mask, you may try this by doing

ip add add 10.170.0.1/24 dev eth0

This will also add the mask, thus creating the routing entry needed for your hosts to know how to reach each other.

If you just want to add the routing entry

ip route add 10.170.0.0/24 dev eth0
0

Are the server virtual machines ? if so, you may consider adding supplemental interfaces..

However, as mentioned by others, just add the IPs with appropriate netmask, then the two host are able to communicate.

ctxadm@ctx-router1:~$ sudo ip addr add 10.75.0.5/24 dev eth1

Proof from 2 debian running on vmware :

ctxadm@ctx-router1:~$ sudo ip addr list eth1
3: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
   link/ether 00:0c:29:a4:1f:e6 brd ff:ff:ff:ff:ff:ff
   inet 10.92.0.254/24 brd 10.92.0.255 scope global eth1
   inet 10.75.0.5/24 scope global eth1

ctxadm@web1:~$ sudo ip addr list eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
   link/ether 00:0c:29:22:1a:8a brd ff:ff:ff:ff:ff:ff
   inet 10.92.0.20/24 brd 10.92.0.255 scope global eth0
   inet 10.75.0.6/24 scope global eth0

ctxadm@ctx-router1:~$ ping 10.75.0.6
   PING 10.75.0.6 (10.75.0.6) 56(84) bytes of data.
   64 bytes from 10.75.0.6: icmp_req=1 ttl=64 time=0.157 ms
   64 bytes from 10.75.0.6: icmp_req=2 ttl=64 time=0.185 ms

ctxadm@ctx-router1:~$ sudo arp -a
   ? (192.168.0.20) at 20:cf:30:7f:6c:3e [ether] on eth0
   ? (10.75.0.6) at 00:0c:29:22:1a:8a [ether] on eth1
   ? (192.168.0.1) at 00:10:18:de:ad:05 [ether] on eth0

That's it !

To debug use tcpdump, check arp entry..

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.