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
# inbound forwarding for IPv6 tunnel
iptables -t filter -A FORWARD -i ppp0 -p 41 -d -j ACCEPT

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


### Get the global IPv4 address for your host from the command line:

### 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 :: dev tun6to4 metric 1
  • 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

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

  • 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
  • I've tried that too to have a static local address decoupled from the public local side but it doesn't work because nf_conntrack modules doesn't support sit packets therefore a sit packet is never seen on a PREROUTING chain. A module for gre tunnels exists (nf_conntrack_proto_gre.ko) – 3ronco Sep 27 '18 at 18:21

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 Leaving everything else the same, it works!


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:


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).

  • 3
    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 '14 at 16:41

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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