Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Currently I have a setup where, due to configuration that would take forever to fix, I have a server that can only be accessed by ipv4. I also, however, have a server that can be accessed by ipv6. I was wondering if I could use iptables to forward ipv6 traffic on a certain port from one of the servers to another server using ipv4 traffic.

share|improve this question
2  
What you're looking for is called NAT64, which I don't think iptables will do (yet). –  Chris S Jun 3 '11 at 2:06
    
Chris is right on - the NAT64 RFCs just got published, I'd give it a while until anything really supports it. That said, you may be able to accomplish your goal in a different way, but we don't have enough detail to know for sure. For instance, if it's an HTTP server, you could reverse-proxy the requests between protocols. –  Shane Madden Jun 3 '11 at 4:52

4 Answers 4

IPtables cannot currently do this, so you need a userspace process to proxy the connections. socat is a suitable tool for this:

socat TCP6-LISTEN:1234,fork TCP4:1.2.3.4:1234
share|improve this answer
1  
thanks, this was helpful! In case anyone is looking for a UDP solution: socat UDP6-RECVFROM:64444,fork UDP4-SENDTO:localhost:64443 worked for me –  Alexander Feb 20 at 12:32

Recent versions of xinetd can also listen on IPv6 and then forward the connection to an IPv4 address.

A sample configuration which listens for IPv6 connections on port 3389 and forwards them to port 3389 of an internal IPv4 address:

service rdp_port_forward
{
    flags           = IPv6
    disable         = no
    type            = UNLISTED
    socket_type     = stream
    protocol        = tcp
    user            = nobody
    wait            = no
    redirect        = 10.187.20.42 3389
    port            = 3389
}

This may be useful in more restricted environments since xinetd is likely to be installed with your base system or available in approved vendor repositories.

share|improve this answer

As noted in the comments on your question, NAT64 is far from being ready, even 3 years later.

You could, however, try 6tunnel, as suggested by puzzlement.

Fortunately, it is present in the Debian and Ubuntu repositories, so you can install it very easily using sudo apt-get install 6tunnel. If you are using another system, you'll have to build it from source.

Building from source really isn't hard, and is just a matter of running some commands (as root):

git clone https://github.com/wojtekka/6tunnel && cd 6tunnel && ./autogen.sh && make && make install

Here's its syntax, simplified:

6tunnel [-4|-6] [-l local-host] original-port destination-host destination-port
  • The [-4|-6] is optional and lets you specify whether you'll bind (listen) on IPv4 or IPv6 (respectively).
  • -l is also optional. It lets you choose on which address (IPv4 or IPv6) you want to bind.
  • The original port is the port on which you'll bind.
  • The destination host is where you'll forward the traffic to. It can be anywhere: localhost, or somewhere else on your network or on the Internet.
  • The destination port is the port on the destination host which will receive your forwarded traffic.

For example, if you want to allow an IPv4-only server, listening on port 1337, to be accessed over IPv6, use:

6tunnel -6 1337 localhost 1337

The above command will listen on port 1337 on IPv6, and forward the traffic to port 1337 on the same machine via IPv4. It will then run in the background, so you don't have to worry about it.

Actually, you should set up a cron job to make sure that it is still running. 6tunnel provides an example for your convenience! Running it on boot shouldn't be a bad idea either.

For more documentation, run 6tunnel -h or man 6tunnel.

share|improve this answer
    
Posting it as new answer because editing the current answer by puzzlement would change way too much, and could get rejected as a suggested edit! –  Léo Lam Jul 12 at 15:02

More for the benefit of people finding this page than the OP necessarily (I came here looking for a solution to IPv6 connectivity for an IPv4 (Twisted) application), one possibility is the application 6tunnel, listens on IPv6 and forwards requests to another interface and port.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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