1

I have two interfaces on my linux machine, lets say eth0 and eth1. eth0 is a public IP that has IPv6 address and eth1 has a private IPv4 address. If I try to nat the packets that received on eth1 interface onto IPv6 address, NAT module in the linux kernel needs to take care of converting IPv4 packet to IPv6 packet before sending out. Once a response is received from other end, it will convert the IPv6 packet back to IPv4 before giving to eth1 interface. I want to understand this conversion mechanism. example: You have a mobile with LTE mobile data connection and you want to share internet to others by creating a hotspot in mobile. Now a days, most of LTE providers are giving IPv6 address. Mobiles connected to hotspot will get IPv4 address. But, Mobiles connected hotspot are able to browse internet. All the requests from clients of mobile hotspot are IPv4 packets and the responses received by LTE from internet are IPv6 packets. That means, there is some conversion happening from ipv4 to ipv6 and vice versa in mobile linux stack.

If somebody can point me to linux code or explain the transitions required for this, it would be great. Thanks in advance.

  • Did any answer help you? if so, you should accept the answer so that the question doesn't keep popping up forever, looking for an answer. Alternatively, you could provide and accept your own answer. – Ron Maupin Aug 12 '17 at 20:32
2

Doing NAT from IPv6 to IPv4 is possible because you can embed the IPv4 address inside the IPv6 address. This is usually done with DNS64.

Doing NAT from IPv4 to IPv6 is much harder because you can't embed an IPv6 address inside an IPv4 address. That doesn't fit. Matt is still possible, but you'd have to statically configure mappings between IPv4 and IPv6 address.

I don't know if the Linux kernel can do that, but it's a bad idea anyway. Because of the different header lengths you'll run into issues with fragmentation and MTU sizes. Using a proxy would be a much better idea.

  • Thanks for a reply. Please find my below comment in reply to Ricky Beam. From that observation, I believe that Linux kernel is doing some translation of IPv4 to IPv6 and viceversa internally. Please correct me, If I am wrong. – Jagadeesh Cherukuri Oct 29 '15 at 9:02
  • 1
    Ah, those networks already do NAT64 and you want to reverse it. That is called 464xlat. You need my friend Tore's clatd implementation for that: github.com/toreanderson/clatd – Sander Steffann Oct 29 '15 at 9:14
  • 1
    Thanks for a quick reply. I am sorry that I am not able to understand your comment (those networks already do NAT64??). As per my understanding, mobile got IPv6 LTE address, the packets received by it will be IPv6 packets. And some code in mobile linux kernel is translating this to IPv4. Similarly, browsing requests from WiFi hotspot clients will be IPv4 packets and these packets will be reverse translated by same code.The link that you mentioned is not part of default linux kernel. So, it has some different implementation.If there is something wrong with my understanding, please let me know. – Jagadeesh Cherukuri Oct 29 '15 at 9:39
  • 1
    You are right. You need special software to do that translation. It's not just the kernel. In those IPv6 only networks traffic to IPv4 destinations uses NAT64. This is provided by the network operator. Most applications do not care whether they use IPv4 or IPv6. For those that do, like Skype or IPv4 hotspot service, the mobile device runs clat code. This code converts IPv4 on the device to IPv6 packets on the network, knowing that a NAT64 box will later convert them back to IPv4. The Linux kernel doesn't know all of this, the clat code does. – Sander Steffann Oct 29 '15 at 10:08
  • 1
    Steffan Thanks for the reply. I have a doubt here. I don't understand where and when this NAT64 module runs and how come clat code and NAT64 which are two different modules can do the translation and reverse translation without any compatibility issues. I mean the prefix and some other translation parameters used by NAT64 may not be know to clat code. – Jagadeesh Cherukuri Oct 30 '15 at 5:32
-3

IPv4 and IPv6 are not the same thing. You cannot NAT between them. There is no amount of "address rewriting" that can convert between them. Can you rewrite the address of an IPX packet to make it Appletalk? NO.

There are extensive products to PROXY between the two systems, but they are almost exclusively protocol dependent. (because protocols have a nasty habit of carrying address information within them.) v4 talks to v4; v6 talks to v6. THAT'S IT.

  • @ Ricky Beam, Thanks for a reply. I agree that v4 talks to v4 and v6 talks to v6. But, my question here is not conflicting this statement. Let me explain with detailed example. You have a mobile with LTE mobile data connection and you want to share internet to others by creating a hotspot in mobile. Most of LTE providers are giving IPv6 address now days. Mobiles connected to hotspot will get IPv4 address. But, Mobiles connected hotspot are able to browse internet. That means, there is some conversion happening from ipv4 to ipv6 and vice versa in mobile linux stack. I hope it is clear now. – Jagadeesh Cherukuri Oct 29 '15 at 8:56
  • 2
    Well there is NAT64 commonly used for IPv6 only clients and there are people applying IPv4 to IPv6 NAT at the data centre edge to enable v4 reachability to an otherwise IPv6 only DC network. – kll Oct 29 '15 at 9:25
  • It's not "NAT". It's a complete protocol translation. You connect to a proxy that then makes a new connection. Yes, you can put a v4 address in a v6 packet, but you cannot do the reverse; there's no way to fit a v6 address in a v4 packet. There's nothing that can be done at the network layer to correct this. v4 NAT keeps tables of what equals what. "NAT64" requires a linked "DNS64" to hack around this mismatch. – Ricky Beam Oct 29 '15 at 18:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.