I have a development environment set up where I have a separate loopback address for multiple websites.
For example, I have the following:
127.0.0.1 www.example.com
127.0.0.2 foo.example.com
127.0.0.3 bar.example.com
127.0.0.4 waffles.example.com
I'd like an equivalent solution for IPv6.
I already know that you can use ::1 as a loopback address, but ::2, ::3, etc don't seem to work.
Are there any other loopback addresses in IPv6? Is there a way to have multiple unique loopback addresses?
Technically ::2, ::3 etc. are part of ::0.0.0.0/96, the "ipv4 compatible ipv6 address" range. It's deprecated, but you probably don't want to use that range.
For a lab environment, use unique local addressing. Go to https://www.ultratools.com/tools/rangeGenerator and generate yourself a prefix. Then you can pick whatever addresses you want out of that prefix, and assign them to the loopback interface.
Your loopback adress is ::1/128. Note the width of the subnet which restricts it to just one host. change the subnetmask to something wider and check your routing table. Or use link-local adresses.
I recommend using RFC 4193 addresses for this. RFC 4193 allows you to construct your own /48 for local use by taking the byte value
fd
followed by 5 random bytes. You are allowed to put anything you see fit after the first 48 bits, so if you wanted a /64 you can takefd
followed by 7 random bytes as in this example for Linux systems:Using RFC 4193 has the advantage compared to earlier answers that you are not violating any RFCs in doing so and the addresses can be used without an interface identifier.
Each of the ranges mentioned in earlier answers are either using ranges reserved for different purposes or link-local addresses which require an interface identifier whenever used.
There exists an expired draft suggesting that the range
1::/32
gets allocated for additional loopback addresses like you are asking for. However since that draft expired years ago and no such allocation was ever made you cannot use1::/32
for this.There is a RFC proposal called A Larger Loopback Prefix for IPv6, which proposes using
1::/32
as loopback addresses. However, the proposal was not approved and expired already in 2013.from Can I bind a (large) block of addresses to an interface?
it's the only thing that worked for me. linux-specific, of course.
nota bene: because this may conflict with 0.0.0.0/8 addresses at some time in the future,
::127.0.0.0/104
would probably be a better choice.Using link-local addressing seems to be the only valid option. What most suggestions here ignore is the fact that the IPv6 prefix declares scope, and I would not want my presumably private addressing to be in global scope.
So for Linux:
And specify interface when referring to such addresses. Testing with netcat:
Verifying correct scope:
Still it seems not very elegant having to add every single IP to be able to bind to it. With 127.0.0.0/8, you can bind to any address without prior assigning them.