Can I bind a (large) block of addresses to an interface?
I have a /48 IPv6 block. I'd like to be able to do this:
$ wget --bind-address=<1st-ipv6> http://www.some-url.com $ wget --bind-address=<2nd-ipv6> http://www.some-url.com $ wget --bind-address=<3rd-ipv6> http://www.some-url.com etc...
for any of the 2^80 available IPs in my /48 block.
According to my tests, assigning lots of IPs to an interface makes things slow (in terms of HTTP requests per second). And obviously, I can't assign billions of IPs to one interface. Is there a way to tell Linux to accept any IP that belong to my /48 block, or to modify wget so that it can be done?
Jan 17 2013 EDIT: I found out how to do it. Your kernel version must be at least 3.3, because from this version, this patch is applied: http://lists.openwall.net/netdev/2011/11/08/8
Then you have to run as root (as said by David Schwartz):
# ip -6 route add local your_ipv6_block/48 dev lo
You have to assign this route to the lo interface, even if it won't be the outgoing interface to reach the Internet.
Then you have to modify wget's sources. In src/connect.c, inside the function connect_to_ip(), after the socket is created, add this:
setsockopt(sock, SOL_IP, IP_FREEBIND, &v, sizeof(v));
Then compile wget (the compiler may complain about IP_FREEBIND not being defined, how to solve this is out of scope here) and install it.
Then you can successfully do:
$ wget --bind-address=<any_ipv6_in_your_block> http://www.some-url.com