Can I or how can I add custom IPv6 address on loopback interface of the host A and ping it from the host B?

I've tried to add something like this ::ffff:5:4:3:2, however ip -6 route says, that this destination is unreachable with error 101, but I can ping it from host A. When I set this address on tap0, for instance, route is reachable, but still "unpingable" from host B. I can't understand which addresses loopback allows, why my custom is unreachable, why I can ping it from host A, how to enable route_localnet and rp_filter for IPv6.

OS: ArchLinux, kernel 4.10.

I know the way to do it for IPv4, but IPv6 works completely (or not?) different.

  • What is the problem you are trying to solve? Whay can't you use IPv6 site-local addresses from the fc00::/7 block? By using technology in ways it was not intended to be used you are bound to run into problems the designers didn't anticipate. – Johan Myréen May 24 '17 at 5:34
  • @JohanMyréen, I think it's brilliant when people try to do such things for their own growth. Moreover, I've found the way to do this. However, I stlll cannot understand why ip -6 route says address is unreachable. – marar May 24 '17 at 5:43
  • Ok. But don't complain if your hack breaks in the future. I can understand doing something like this is it adds some value, but not it it just complicates things that could be done the easy way. – Johan Myréen May 24 '17 at 5:56
  • 1
    A loop back address is predefined in the protocol and the operating system's drivers. What you're trying to do is to make a virtual interface and route it so that it can be reached by another machine which is possible but your question is too flawed to properly answer. – Julie Pelletier May 24 '17 at 6:13

Yes. Just as you can do this with IPv4, this is called routing. You have to tell one host how to reach another host.

Let's say we have two hosts, A and B.

Host A has its default loopback address of ::1 as well as your custom address on the loopback interface. (In my example, the custom address is going to be fd56:dcaa:2099::1. I chose this from a Unique Local Address. You should use ULA addresses for purposes like these.)

Host A also has an Ethernet interface, let's call it eth0. In IPv6, it'll have an IPv6 link local address. It may have other IPv6 addresses. You can find these by running ip -6 addr eth0. Here's an example from my system:

$ ip -6 addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 state UP qlen 1000
    inet6 2601:404:ce00:adc0:9d6c:9e16:a9a9:b03b/64 scope global temporary dynamic 
       valid_lft 593594sec preferred_lft 74600sec
    inet6 2601:404:ce00:adc0:bc87:129a:ed5d:814/64 scope global temporary deprecated dynamic 
       valid_lft 78769sec preferred_lft 0sec                                                                                                                                                                                      
    inet6 2601:404:ce00:adc0:1453:3734:6742:4500/64 scope global mngtmpaddr noprefixroute dynamic                                                                                                                                 
       valid_lft 2591820sec preferred_lft 604620sec                                                                                                                                                                               
    inet6 fe80::5520:a68f:5416:a68c/64 scope link                                                                                                                                                                                 
       valid_lft forever preferred_lft forever

In that list are four different addresses (you may have more). For our purposes, you want the one that says "scope link" after it. On my system (and so in my example), that's fe80::5520:a68f:5416:a68c.

On host B, let's also has an interface eth0. To allow host B to reach host A's special loopback address, host B needs to know where to find it. You do that by adding a entry to host B's routing table:

# ip route add fd56:dcaa:2099::1 via fe80::5520:a68f:5416:a68c dev eth0

What we're doing is telling host B's kernel that it can reach fd56:dcaa:2099::1 (host A's special address on its loopback interface) at fe80::5520:a68f:5416:a68c (host A's link-local address on its eth0 interface), but that host B needs to try to reach fe80::5520:a68f:5416:a68c from host B's eth0 interface. (That's the tricky thing about link-local addresses. The address itself is only meaningful in the context of a given network segment. Study the OSI networking model for more details.)

Once you have that entry in host B's routing table, you should be able to ping host A's custom address from host B, since host B now knows to use host A's link local address as a router to reach that address.

| improve this answer | |
  • What's the point in doing it like this? If you want host A and B to communicate over IPv6, why not assign ULA addresses to the Ethernet interfaces and be done with it, like I suggested yesterday? Is there some specific problem the original poster is trying to solve that warrants these complications, including the IPv4 mapped IPv6 address, which really shouldn't be used on the wire. If there is, then it might be a good idea to mention it in the question. – Johan Myréen May 25 '17 at 13:54
  • The specific question asked was "Can I or how can I add custom IPv6 address on loopback interface of the host A and ping it from the host B?" And that was the question I answered. There are circumstances where this is useful, such as assigning the same IP address to multiple DNS servers and using a router to load balance traffic between the nodes. Placed on the loopback interface, the address doesn't disappear in the event of hotplug. And you'd probably want to use dynamic routing to insert the route into host B's routing table. But that's more than the question strictly asked. – Michael Mol May 25 '17 at 13:58
  • And of course, with ULA addresses directly on the Ethernet interfaces, you don't need to add any route, if hosts A and B are on the same link. – Johan Myréen May 25 '17 at 14:26
  • Sure. But that wasn't the question that was asked. – Michael Mol May 25 '17 at 15:06

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.