3

For example with IPv4 addresses I can add the alias 172.16.0.0/12 to a loopback adapter:

ip addr add 172.16.0.0/12 dev lo

and I am then able to ping any address from 172.16.0.1 - 172.31.255.255 without needing to add millions of aliases.

What confuses me is why I can't do that same "trick" with an IPv6 address. For example if I run:

ip addr add fdf0::/64 dev lo

I am able to only ping6 fdf0:: but not ping6 fdf0::1

user1634494
  • 131
  • 1
  • 2
    IPv4 uses an address range for loopback, so the mask is actually used in Linux as a way to assign this range. IPv6 only defines a single loopback address. so the mask is ignored. I'd classify this as an implementation choice. – dirkt Jun 02 '20 at 04:39
  • This was asked and answered in the general case, also noting what this question does not that this is peculiar to Linux, at https://unix.stackexchange.com/q/508157/5132 . dirkt, question comments are not for answers. – JdeBP Jun 02 '20 at 06:52
  • I wonder what the point is in adding these addresses to the loopback interface. Why do you want to have millions of addresses to point back to your local host? – Johan Myréen Jun 02 '20 at 11:34
  • 1
    Well you can artificially make it work by comparing with what did ipv4 and adding the minimal "missing" part after adding the address, which is : `ip -6 route add table local local fdf0::/64 dev lo` . Why, how, is it any good? No idea. Now I'm sure I will have given work to future consultants coming to debug this a few years later. – A.B Jun 02 '20 at 12:34
  • @A.B This works perfectly! I am a little confused about how this actually works but are there any resources you can point me too (I am pretty new to linux networking as you can tell). The reason I need so many IP addresses is for a testing framework for a product that expects a large number of unique IP addresses. The framework can "pretend" to be 1million unique devices by using the destination IP address from the caller. More realistically this will probably be only 100,000 IPs but making that many aliases (or actually getting 100k static IPs) seemed problematic. – user1634494 Jun 02 '20 at 16:06
  • As I said, "no idea". The reason has to be like dirkt said, that some things done in IPv4 are done differently in IPv6. So the automatic routes added by the kernel aren't added the same way. Doing this might bite you later by making other things not work when they should. – A.B Jun 02 '20 at 16:17
  • See also: https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=linux-2.6.37.y&id=ab79ad14a2d51e95f0ac3cef7cd116a57089ba82 – A.B Oct 10 '21 at 09:47

0 Answers0