ipcalc and sipcalc

Colin Watson cjwatson at ubuntu.com
Tue Nov 28 13:10:52 UTC 2017


On Tue, Nov 28, 2017 at 10:55:44AM +0000, thufir wrote:
> Reading the man page:
> 
> thufir at dur:~$ 
> thufir at dur:~$ ipv6calc --ipv4_to_6to4addr 192.168.1.1
> No action type specified, try autodetection...found type: conv6to4
> 2002:c0a8:101::
> thufir at dur:~$ 
> 
> 
> they give that as an example for typical usage, although they use 
> 127.0.0.1 instead.  Give me pencil, paper, and lots of time, I can 
> convert between binary and decimal.  Not so much hexadecimal...
> 
> I went to an online hex to dec converter, and c0 converts as 192.  But, 
> 2002 hex converts to 8194, so don't see how that helps at all.  Or does 
> it?
> 
> 
> so, this "converts" or "translates" ipv4 to ipv6?

I've had a hard time answering your question, because it's a bit
underspecified: you haven't told us what the basic thing you're actually
trying to achieve is.  Could you lay out the original problem you have
in a way that doesn't specify a particular solution?  I'll try to answer
anyway, but if I've failed to guess accurately at what you're trying to
do then the answers may be misleading.


There's no single way to convert IPv4 to IPv6.  Step back for a minute
and think about the problem: what are you actually trying to achieve?
You're probably trying to exchange packets between IPv4 and IPv6
networks in some way.  But you can't just send an IPv6 packet to an
IPv4-only system - it would have no idea what to do with it!  Any
address that involves embedding IPv4 in IPv6 that *actually works* must
involve a gateway of some kind that relays packets between IPv4 and IPv6
networks, which means that it must refer to some particular part of the
IPv6 address space that's set up for use in that way.

6to4 is one particular scheme for allowing a system that only has IPv4
connectivity to gain IPv6 connectivity by giving it a chunk of IPv6
address space constructed mechanically based on its IPv4 address.  It
arranges for IPv6 packets to be encapsulated inside IPv4 while they
traverse the IPv4-only link, and to be decapsulated by relay routers
that send them on to the IPv6 internet; the IPv6 addresses are such that
the relay router can extract the IPv4 address and thus send packets
going in the other direction to the right place.

So, for example, if your ISP has assigned you 203.0.113.5 as your IPv4
address [1], then you might assign IPv6 addresses on your network like
this:

  2002:cb00:7105::1
  2002:cb00:7105::2

Here, the "2002:" bit is the 6to4 prefix: that entire slice of address
space, referred to as "2002::/16" to indicate that the prefix is 16 bits
long, is reserved for use by the 6to4 scheme and nothing else.
"2002:cb00:7105::" is a prefix meaning "the 6to4-accessible network
sitting behind the IPv4 address 203.0.113.5".

Because you now have a (large!) slice of address space, you can divide
everything under that up as you see fit.  In IPv6, the first 64 bits
normally identify the network and the last 64 bits normally identify the
host, so this means you have room for 65536 subnets, and you might for
example assign host addresses within each using stateless
autoconfiguration, so the host part of the address could be derived
automatically from the system's hardware Ethernet address; or you could
assign them manually as in my example above, or use some other scheme.

I don't actually advocate using 6to4: before I had an ISP that offered
native IPv6 support, I used a tunnel from he.net instead, which I found
to be more reliable and easier to understand.  The basic idea is
similar, except you get a prefix assigned specifically to you rather
than one mechanically constructed from your IPv4 address: this means,
for example, that you don't have to renumber your network if your IPv4
address changes.


You use 192.168.1.1 as your example, so you might instead just be trying
to allocate IPv6 addresses on your private network without (yet)
worrying about connectivity to the outside world.  (I'm not sure how
useful this will be, but maybe you're just trying to divide the problem
into tractable pieces.)  In that case, you probably don't want to ask a
tool to do the conversion at all, because you only need to deal with the
last part of the address that identifies each particular host.

What I normally do is manually assign addresses to anything I might want
to connect to - hosts that run services and the like - by just
converting the host part of their address to hex, which for small
numbers of computers is trivial; everything else I leave to pick
addresses for itself using stateless autoconfiguration.  (The latter
uses a scheme that you can look up if you need to but that means it
won't clash with addresses you've assigned by just picking small
numbers.)


Anyway, this is a long-winded way to say that you should stop and
explain what you're actually trying to do, because simply converting
IPv4 to IPv6 isn't a useful thing to do without support from some kind
of relaying arrangement, and the best approach may in fact be to forget
about converting addresses entirely and use some other scheme.


[1] It definitely won't have used that particular address - this is from
    one of the small blocks of addresses reserved for use in
    documentation and examples.

-- 
Colin Watson                                       [cjwatson at ubuntu.com]




More information about the ubuntu-users mailing list