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.

I have a Linux router without an ipv6 stack and a Linux host inside the NAT. How do I use iptables to forward 6to4 traffic back and forth between the NAT router and the host and then configure the 6to4 tunnel on the host using the router's public IPv4 address?

This recipe (on the router) gets an ipv6 ping to the host's eth0 but they don't make it onto the tun6to4 interface. Wireshark says "ICMP Destination unreachable (Port unreachable)" as an ipv4 response to the 6to4 ping.

# inbound destination NAT for IPv6 tunnel. ppp0 is router's WAN interface.
iptables -t nat -A PREROUTING -i ppp0 -p 41 -j DNAT --to 192.168.1.100
# inbound forwarding for IPv6 tunnel
iptables -t filter -A FORWARD -i ppp0 -p 41 -d 192.168.1.100 -j ACCEPT

I am using this script on the Linux host, passing the router's public ip:

#!/bin/bash

### Get the global IPv4 address for your host from the command line:
GLOB_IP4=$1

### Compute the 6TO4 tunnel IPv6 address:
GLOB_IP6TO4=$(printf "2002:%02x%02x:%02x%02x::1" $(echo $GLOB_IP4 | tr . ' '))

### Setup the tunnel
ip tunnel add tun6to4 mode sit remote any local $GLOB_IP4 ttl 64
ip link set dev tun6to4 up
ip addr add $GLOB_IP6TO4/16 dev tun6to4
ip route add 2000::/3 via ::192.88.99.1 dev tun6to4 metric 1
share|improve this question
    
Unless you did something to block the traffic, the Linux machine will "accept" the traffic normally, given that you enable the sit tunnel. What exactly are you asking? Setup the sit tunnel? Open the firewall with iptables? –  Juliano Nov 28 '09 at 17:27
add comment

3 Answers

iptables -t nat -A PREROUTING -d 192.0.2.75 -p 41 -j DNAT --to 10.0.0.2 on the router should do the trick, assuming that all flows are initiated from outside to your IP address (given as 192.0.2.75 in this example). If your IPv6-capable box starts things, then regular catch-all SNAT rules should do the trick.

share|improve this answer
    
Whoops, you're right. Fixed, with added special sauce. –  womble Nov 28 '09 at 20:14
    
I've been able to get the packets to the box, but not into the tunnel.. –  joeforker Nov 28 '09 at 22:00
add comment

The Secret Sauce

I thought the local tunnel address would affect 6to4 encapsulation and would have to be my global IPv4 address.

ip tunnel add tun6to4 mode sit remote any local $GLOB_IP4 ttl 64

It had to be the host's address, in my case 192.168.1.100. Leaving everything else the same, it works!

share|improve this answer
add comment

Sadly this cannot be done when having a linux router between the internet and your linux box behind the nat.

As stated by the iptables manual:

DNAT

This target is only valid in the nat table, in the PREROUTING and OUTPUT chains, and user-defined chains which are only called from those chains. It specifies that the destination address of the packet should be modified (and all future packets in this connection will also be mangled), and rules should cease being examined. It takes one type of option: --to-destination ipaddr[-ipaddr][:port-port] which can specify a single new destination IP address, an inclusive range of IP addresses, and optionally, a port range (which is only valid if the rule also specifies -p tcp or -p udp)

you can "-j DNAT --to" only if the protocol is TCP or UDP, this will not work with protocol 41 (6to4).

share|improve this answer
1  
You seem to have misread this. The manual section you quoted says that you can only specify a destination port when using TCP or UDP. –  Michael Hampton Jan 11 at 16:41
add comment

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.