• RSS

  • Polls

    Which CCIE Are You Pursuing?

    View Results

    Loading ... Loading ...
  • Search

  • Recent Comments

  • Popular Posts

  • Recent Posts

  • Heat Map

  • Follow Me

  • « CCIE R&S Core Knowledge Question(4) | Main | 10 Steps To A Quality Cisco Certification »

    Converting IPv4 to IPv6 and back

    By admin | April 9, 2009

    Converting from IPv4 to IPv6

    Is so easy, yet everyone seem to convert a IPv4 address to binary, then to IPv6. Why? Why waste time and do things the long way? Not cool.

    Firstly before starting I will assume everyone knows the following:


    A = 10
    B = 11
    C = 12
    D = 13
    E = 14
    F = 15

    Two more things I would like to mention before explaining the conversion.
    An IPv4 address : example 192.168.99.1

    An IPv6 address : example 2001:0db8:85a3:0000:0000:8a2e:0370:7334

    Then converting is easy. Lets take the following IPv4 address : 192.168.99.1 and convert it to Hex.

    Step1 >

    Divide the first octet (192) by 16 (since Hex is a Base-16)
    IE : 192/16 = 12 times exactly with 0 left over
    - 12 in Hex is represented as C
    - 0 (zero) in Hex is, you guessed it, 0
    Thus 192 in HEX is C0

    Step2 >

    Repeat step 1 with the second octet (168),
    IE : 168/16 = 10 times with 8 left over because 10*6 = 160,
    - 10 in HEX is A
    - 8 in HEX is 8
    Thus 168 in HEX is A8

    Step3 >

    Repetition rules!!! Third octet (99)
    IE : 99/16 = 6 times with 3 left over
    - 6 in HEX is 6
    - 3 in HEX is 3
    Thus 99 in HEX is 63

    Step4 >

    Last octet
    IE : 1/16 = 0 times with 1 left over
    - 0 in HEX is, yeah it is 0
    - 1 in HEX is 1
    Thus 1 in HEX is 01

    So the IPv4 address of 192.168.99.1 in IPv6 address format is C0A8:6301
    See, not all that difficult, if you know your 16 multiplication table, you can do this in your head, no problems.

    - – - -

    Converting back from IPv6 to IPv4

    Now to convert the address C0A8:6301 back to IPv4, the reverse method would apply.

    Let me point one more thing about Base-16 out to understand why I’m doing what I am below:

    160 = 1

    161 = 16

    Taking the same address C0A8:6301, first divide the address into 2 Tuple-groupings (2 Hex Characters) = C0 A8 63 01

    Step1 >

    Take C0 and multiply the first character ‘C’ by 16 and the second character ‘0′ by 1.
    Add the two decimal values together to get the IPv4 decimal value
    IE: ((C=12)*16) + (0*1) = 192

    Step2 >

    Repeat the same process with A8,
    IE: ((A=10)*16) + (8*1) = 168

    Step3 >

    Repeat the same process with 63,
    IE: (6*16) + (3*1) = 99

    Step4 >

    Repeat the same process with 01,
    IE: (0*16) + (1*1) = 1

    This will give you an IPv4 address of 192.168.99.1

    Easy, easy!

    Source

    Tags: IPv4, IPv6

    Topics: CCNA, CCNA R&S, TCP/IP | 4 Comments »

    Related posts

    Random Posts

    4 Responses to “Converting IPv4 to IPv6 and back”

    1. Derek Morr Says:
      April 9th, 2009 at 10:13 pm

      I’m not sure what you’re trying to accomplish.

      “So the IPv4 address of 192.168.99.1 in IPv6 address format is C0A8:6301″

      That’s not correct.

      If you want to represent an IPv4 address as an IPv6 address, use an IPv4-mapped address. For example, ::ffff:c0a8:6301 (alternative written as ::ffff:192.168.99.1). IPv4-mapped addresses are commonly used with IPv6 wildcard sockets on a dual-stacked machine.

      If you want to convert between IPv6 and IPv4 on the wire, you’d have to use one of the proposed translators that the IETF is currently defining.

    2. Jim Says:
      April 13th, 2009 at 2:12 pm

      He’s showing you how to accomplish 6-to-4 tunnels basically. Those tunnels always concatenate 2002::/16 with the IPv4 address. Of course you can’t just throw the IPv4 dotted decimal notation after 2002::/16 so you have to convert it to hex and create a 48 bit prefix. So for example 192.168.1.34 becomes 2002:C0A8:122::/48.

      The routers then take care of rest as far as extracting the the IPv4 address from the IPv6 address then encapsulating the IPv6 packet to to be sent over an IPv4 network. Then at the other end the IPv6 packet is decapsulated from the IPv4 packet.

      Yes his wording was wrong but if you work with IPv6 it’s quite clear when this kind of conversion from IPv4 to a hex address is required.

      Thanks for the great trick by the way.

    3. UC IPv6 Says:
      April 14th, 2009 at 8:36 pm

      He’s showing the format of the IPv6 as compare to IPv4. Very basic.

    4. Abhishek Says:
      April 23rd, 2009 at 7:14 pm

      i want to convert 2001:0DB8::1428:57AB into an equavalent IPv4 address..!! how should i convert this into an equavalent IPv4 address..!!

    Comments

    You must be logged in to post a comment.