Convert IPv4 into IPv6

by Nish Vamadevan on 15/11/2009 · 17 comments

I was going through 6to4 tunnel configs and thought I’d post some info on converting IPv4 address into IPv6 Address. This is pretty straight forward and its obviously involves HEX conversion.

Method 1 (Please also see Method 2 below as I think it is much more easier)

Here, I will convert the address 192.168.25.234

First we divide each octet by 16 and write down the remainder, primary school maths! :)

192 ÷ 16 = 12 remainder 0
168 ÷ 16 = 10 remainder 8
25 ÷ 16 = 1 remainder 9
234 ÷ 16 = 14 remainder 10

We also know that HEX has the following Values

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

So we can write 192.168.25.234 into HEX like so… C0A8:19EA

Now we will change the HEX Address C0A8:19EA into regular IPv4

C0 = (12 x 16) + 0 = 192
A8 = (10 x 16) + 8 = 168
19 = (1 x 16) + 9 = 25
EA = (14 x 16) + 10 = 234

QED :)

Method 2

Another easier way to convert is to convert the octets into Binary, in this case we will still use the IP address 192.168.25.234

Split those above 32Bit into equal 16 Bits as HEX is based on Base of 16, then Add them up.

C0
A8
19
EA

Hope I have explained it thoroughly so you could follow… If you have any doubts, feel free to add your comments.

{ 16 comments… read them below or add one }

Eryck November 27, 2009 at 13:10

I liked that. Nice and easy :)

Reply

Charlie April 18, 2010 at 21:16

Nice:)

Reply

Rakesh May 3, 2010 at 07:33

Cool ;-)

Reply

Nish Vamadevan June 1, 2010 at 13:14

thanks .it was interesting.but would you please explain about subneting, for example /64 or /128?

Reply

javad June 1, 2010 at 13:15

thanks .it was interesting.but would you please explain about subneting, for example /64 or /128?

Reply

Nish Vamadevan June 1, 2010 at 13:48

I will try and write one at the end of the month on IPv6 Subnetting.

Reply

parthasarathi.j January 9, 2011 at 12:44

how i config this ipv6 in linux. give an example cmd..

Reply

Nish Vamadevan January 15, 2011 at 04:35

Please refer to your Linux Manual.

Reply

jors February 8, 2011 at 17:26

I know I am posting a comment in a very outdated post, but… since each address space is completely different, does it make any sense converting ipv4 ipv6? I mean, if we were to translate your ipv4 example address (192.168.25.234) to an ipv6 one, it would look something like: 0000:0000:0000:0000:0000:0000:c0a8:19ea, which I guess it isn’t something wrong, but somewhat strange.

Are you are actually extracting the ipv4 address contained in a 6to4 ipv6 address, isn’t it? (Because in other case, the conversion wouldn’t make sense)

Cheers.

Reply

Nish Vamadevan February 11, 2011 at 20:30

It is how you look at the IP Address, and at the end of the day, v4 is 32Bit and v6 is 128Bit…

Conversion is done for many reasons, for example v6 device trying to talk to a v4 Device, and only way they can understand each other is to convert the language (so to speak) they talk…

Another example is a 6to4 Tunnel (RFC 3056) , where a conversion is needed…

Also another practical example is, Imagine you have a cluster of Servers running on v4 and you want to transition to v6… Easy way to transition is to get the list of v4 Addresses, write a bit of Bash/PHP Script convert them to v6…

Finally, a v6 address does look intimidating but when you apply Zero/Leading Zero compression, it does look rather presentable :)

Hope it answers your question.

Reply

sanjeev August 15, 2011 at 09:55

hi

thanks for that conversion seems very good, however in method 2 this line seems wrong

9-14- (1110) (1010) 10- A this line should be

E-14 (1110)(1010) 10-A

Please let me know if this is just a typo as I see that the end result was correct

Reply

Nish Vamadevan November 23, 2011 at 20:19

I have fixed the typo. Thanks!

Reply

Christopher Paulin October 17, 2011 at 20:32

The 9 in the lower left corner of the last chart should be an E. E in hexadecimal = 14 in decimal = 1110 in binary.

Reply

rohit November 14, 2011 at 10:09

Thank’s Bro

Reply

Pale Writer November 16, 2011 at 01:13

Sorry I couldn’t get here sooner to proof this for you, but you SHOULD be getting the same result w/ method 2 as you did w/ method 1, as you’re “converting” the same source IPv4 address. The first cut rendered an 0xE correctly, but you show a 0×9 in the second.

That ?type-O? aside, there remains a distinct shortage of information on the REST of IPv4IPv6 conversion which this little decimal-to-hex tutorial might logically have addressed.

While this tickled some of your audience, once upon a time, this critic would prefer to hang with a different group, but – thanks for the effort.

pw

Reply

Nish Vamadevan November 23, 2011 at 20:22

It was a typo, I should have proof read…

Reply

Leave a Comment

 

{ 1 trackback }

Previous post:

Next post: