IPv6 startup script

From DD-WRT Wiki

(Difference between revisions)
Jump to: navigation, search
Revision as of 08:04, 5 June 2009 (edit)
Markus (Talk | contribs)
(Undo revision 25583 by Ausimus1 (Talk))
← Previous diff
Revision as of 10:04, 22 April 2010 (edit) (undo)
Jaap-Jan (Talk | contribs)
(Instructions - New version of the script (eth1 added, stopping after 3 tries, removed extra space at the beginning of the line))
Next diff →
Line 6: Line 6:
Any feedback on the script welcome in [http://www.dd-wrt.com/phpBB2/viewtopic.php?t=27817 this forum topic]. Any feedback on the script welcome in [http://www.dd-wrt.com/phpBB2/viewtopic.php?t=27817 this forum topic].
- #!/bin/sh+==Instructions==
- #+Use this script once you have been assigned a SixXS tunnel to connect that tunnel. Once your tunnel has been up for a week, you earn enough credits to request a subnet (/48 IPv6 allocation) which you can then use for hosts on your network. See the instructions in the SETUP VALUES section for more info.
- # SIXXS IPv6 startup script for WRT54G+ 
- # From http://www.dd-wrt.com/wiki/index.php/IPv6_startup_script+See [http://www.sixxs.net/main/ http://www.sixxs.net/main/] for info on how to request tunnels and subnets.
- + 
- ##################################+Any feedback on the script welcome in [http://www.dd-wrt.com/phpBB2/viewtopic.php?t=27817 this forum topic].
- ### SETUP VALUES ###+ 
- ### Change these before running ##+ #!/bin/sh
- ##################################+ #
- + # SIXXS IPv6 startup script for WRT54G
- # The IPv6 prefix (/64) of the tunnel initially assigned to you by SixXS (including the ::).+ # From http://www.dd-wrt.com/wiki/index.php/IPv6_startup_script
- # Only the ::1 and ::2 are used from this range, for the PoP and your router, respectively.+
- # You need to keep the tunnel up for a week in order earn enough credits to request a /48 subnet (see below) which can then be used by hosts on your network.+ ##################################
- TUNNELPREFIX="2001:db8:1111:1111::"+ ### SETUP VALUES ###
- + ### Change these before running ##
- # The IPv4 address of the SixXS PoP you're using+ ##################################
- SIXXS4="1.1.1.1"+
- + # The IPv6 prefix (/64) of the tunnel initially assigned to you by SixXS (including the ::).
- # MTU - must match your SixXS tunnel settings and radvd's "AdvLinkMTU" value; 1280 is the default but it can be increased.+ # Only the ::1 and ::2 are used from this range, for the PoP and your router, respectively.
- # This script will give you a recommendation when you run it, but it should be 20 less than your IPv4 MTU.+ # You need to keep the tunnel up for a week in order earn enough credits to request a /48 subnet
- MTU=1280+ # (see below) which can then be used by hosts on your network.
- + TUNNELPREFIX="2001:db8:1111:1111::"
- # A /64 from your /48 subnet prefix assigned by SixXS, INCLUDING the /64+
- ## This should match what you announce to the network with radvd (set in Administration -> Management in the web interface)+ # The IPv4 address of the SixXS PoP you're using
- # If you have not yet been assigned this (you need to keep the tunnel up for a week to earn enough credits), leave blank/commented out+ SIXXS4="1.1.1.1"
- ###SUBNET="2001:db8:2222::/64"+
- + # MTU - must match your SixXS tunnel settings and radvd's "AdvLinkMTU" value; 1280 is the default but it can be increased.
- # Space-separated list of extra IPs you want for your router, such as:+ # This script will give you a recommendation when you run it, but it should be 20 less than your IPv4 MTU.
- # * Local (RFC 4193, currently draft) address e.g. fdxx:xxxx:xxxx:yyyy::1/64; or+ MTU=1280
- # * site-local (as per RFC 1918, but obseleted by RFC 3879) address e.g. fec0::1/64+
- # * Any other local or global fixed address you want (note that we already assign the above SUBNET address)+ # A /64 from your /48 subnet prefix assigned by SixXS, INCLUDING the /64
- # This is optional, leave blank/commented out if not wanted.+ ## This should match what you announce to the network with radvd (set in Administration -> Management in the web interface)
- ###ADDITIONALIP6="fec0::1/64"+ # If you have not yet been assigned this (you need to keep the tunnel up for a week to earn enough credits), leave blank/commented out
- + ##SUBNET="2001:db8:2222::/64"
- ##################################+
- ### END OF SETUP VALUES ##+ # Space-separated list of extra IPs you want for your router, such as:
- ##################################+ # * Local (RFC 4193, currently draft) address e.g. fdxx:xxxx:xxxx:yyyy::1/64; or
- + # * site-local (as per RFC 1918, but obseleted by RFC 3879) address e.g. fec0::1/64
- logger -st sixxs -- "Starting IPv6 setup"+ # * Any other local or global fixed address you want (note: we already assign the above SUBNET address)
- + # This is optional, leave blank/commented out if not wanted.
- # Get the tunnel endpoint addresses+ ###ADDITIONALIP6="fec0::1/64"
- MYTUNNELIP="${TUNNELPREFIX}2"+
- SIXXSTUNNELIP="${TUNNELPREFIX}1"+ ##################################
- + ### END OF SETUP VALUES ##
- # Get our external IPv4 (in case the IP isn't available, because we don't have a connection yet, retry until we succeed)+ ##################################
- while [ -z ${EXTIP} ]; do+
- # PPPoE devices are on ppp0, all others are on vlan1; we try both+ logger -st sixxs -- "Starting IPv6 setup"
- DEV=ppp0+
- EXTIP=`/usr/sbin/ip -4 addr show dev ${DEV} | grep inet | awk '{print $2}' | cut -d/ -f1`+ # Get the tunnel endpoint addresses
- if [ -z ${EXTIP} ]; then+ MYTUNNELIP="${TUNNELPREFIX}2"
- # Not on ppp0 - try vlan1+ SIXXSTUNNELIP="${TUNNELPREFIX}1"
- DEV=vlan1+
- EXTIP=`/usr/sbin/ip -4 addr show dev ${DEV} | grep inet | awk '{print $2}' | cut -d/ -f1`+ # Get our external IPv4 (in case the IP isn't available, because we don't have a connection yet, retry 3 times or until we succeed)
- fi+ RETRIES=3
- if [ -z ${EXTIP} ]; then+ while [ -z ${EXTIP} ]; do
- logger -st sixxs -- "- No external IP found; trying again in 10 secs..."+ # PPPoE devices are on ppp0, all others are on vlan1 or eth1; we try all
- sleep 10+ for DEV in "ppp0" "vlan1" "eth1"; do
- fi+ EXTIP=`/usr/sbin/ip -4 addr show dev ${DEV} | grep inet | awk '{print $2}' | cut -d/ -f1`
- done+ if [ -n "$EXTIP" ]; then
- logger -st sixxs -- "- External IP ${EXTIP} found on device ${DEV}"+ logger -st sixxs -- "- External IP ${EXTIP} found on device ${DEV}"
- + break 2
- # Create tunnel+ fi
- logger -st sixxs -- "- Creating SixXS tunnel ${EXTIP} <--> ${SIXXS4}"+ done
- /usr/sbin/ip tunnel add sixxs mode sit local ${EXTIP} remote ${SIXXS4}+ let RETRIES-=1
- + if [ "$RETRIES" -gt 0 ]; then
- # Bring tunnel interface up explicitly+ logger -st sixxs -- "- No external IP found; trying again in 10 secs..."
- logger -st sixxs -- "- Bringing sixxs device up"+ sleep 10
- /usr/sbin/ip link set sixxs up+ else
- + logger -st sixxs -- "- No external IP found after 30 seconds; quitting"
- # Fix MTU and TTL+ exit 1
- logger -st sixxs -- "- Fixing MTU and TTL of sixxs device"+ fi
- /usr/sbin/ip link set mtu ${MTU} dev sixxs+ done
- /usr/sbin/ip tunnel change sixxs ttl 64+
- + # Create tunnel
- # Check for optimal MTU+ logger -st sixxs -- "- Creating SixXS tunnel ${EXTIP} <--> ${SIXXS4}"
- # Max MTU is device's MTU minus 20 (IPv6 headers are 20 bytes bigger than IPv4)+ /usr/sbin/ip tunnel add sixxs mode sit local ${EXTIP} remote ${SIXXS4}
- RECMTU=`ip addr show dev $DEV | grep mtu | awk '{print $5}'`+
- RECMTU=`expr ${RECMTU} - 20`+ # Bring tunnel interface up explicitly
- if [ ${MTU} -lt ${RECMTU} ]; then+ logger -st sixxs -- "- Bringing sixxs device up"
- logger -st sixxs -- "- Note: You could increase your MTU setting from ${MTU} to ${RECMTU} for improved performance. Change it in ${0}, radvd.conf and in the SixXS tunnel config."+ /usr/sbin/ip link set sixxs up
- elif [ ${MTU} -gt ${RECMTU} ]; then+
- ### TODO: What happens if MTU is too high?+ # Fix MTU and TTL
- logger -st sixxs -- "- WARNING: Your MTU ${MTU} is too high - it should be ${RECMTU}. Change it in ${0}, radvd.conf and in the SixXS tunnel config."+ logger -st sixxs -- "- Fixing MTU and TTL of sixxs device"
- fi+ /usr/sbin/ip link set mtu ${MTU} dev sixxs
- + /usr/sbin/ip tunnel change sixxs ttl 64
- # Add extra IPs if any+
- if [ ! -z ${ADDITIONALIP6} ]; then+ # Check for optimal MTU
- for IP in ${ADDITIONALIP6}; do+ # Max MTU is device's MTU minus 20 (IPv6 headers are 20 bytes bigger than IPv4)
- logger -st sixxs -- "- Adding fixed IP ${IP}"+ RECMTU=`ip addr show dev $DEV | grep mtu | awk '{print $5}'`
- /usr/sbin/ip -6 addr add ${IP} dev br0+ RECMTU=`expr ${RECMTU} - 20`
- done+ if [ ${MTU} -lt ${RECMTU} ]; then
- fi+ logger -st sixxs -- "- Note: You could increase your MTU setting from ${MTU} to ${RECMTU} for improved performance. Change it in ${0}, radvd.conf and in the SixXS tunnel config."
- + elif [ ${MTU} -gt ${RECMTU} ]; then
- # Configure IPv6 endpoint on the tunnel+ ### TODO: What happens if MTU is too high?
- logger -st sixxs -- "- Configuring local IPv6 tunnel endpoint ${MYTUNNELIP}"+ logger -st sixxs -- "- WARNING: Your MTU ${MTU} is too high - it should be ${RECMTU}. Change it in ${0}, radvd.conf and in the SixXS tunnel config."
- /usr/sbin/ip -6 addr add ${MYTUNNELIP}/64 dev sixxs+ fi
- +
- # Add default route+ # Add extra IPs if any
- logger -st sixxs -- "- Adding default route through SixXS ${SIXXSTUNNELIP}"+ if [ ! -z ${ADDITIONALIP6} ]; then
- /usr/sbin/ip -6 ro add default via ${SIXXSTUNNELIP} dev sixxs+ for IP in ${ADDITIONALIP6}; do
- + logger -st sixxs -- "- Adding fixed IP ${IP}"
- if [ ! -z ${SUBNET} ]; then+ /usr/sbin/ip -6 addr add ${IP} dev br0
- # Add a network from the /48 subnet to br0+ done
- logger -st sixxs -- "- Setting up subnet ${SUBNET}"+ fi
- /usr/sbin/ip -6 addr add ${SUBNET} dev br0+
- + # Configure IPv6 endpoint on the tunnel
- ## # Start router advertisement daemon+ logger -st sixxs -- "- Configuring local IPv6 tunnel endpoint ${MYTUNNELIP}"
- ## # No need to do this here; just use the setup in the web interface+ /usr/sbin/ip -6 addr add ${MYTUNNELIP}/64 dev sixxs
- ## logger -st sixxs -- "- Starting radvd..."+
- ## /sbin/radvd -C /tmp/smbshare/etc/radvd.conf+ # Add default route
- else+ logger -st sixxs -- "- Adding default route through SixXS ${SIXXSTUNNELIP}"
- logger -st sixxs -- "- Note: No subnet configured yet - apply for one when you've kept the tunnel up for a week and earned enough credits"+ /usr/sbin/ip -6 ro add default via ${SIXXSTUNNELIP} dev sixxs
- fi+
- + if [ ! -z ${SUBNET} ]; then
- logger -st sixxs -- "SixXS IPv6 setup done" + # Add a network from the /48 subnet to br0
 + logger -st sixxs -- "- Setting up subnet ${SUBNET}"
 + /usr/sbin/ip -6 addr add ${SUBNET} dev br0
 +
 + ## # Start router advertisement daemon
 + ## # No need to do this here; just use the setup in the web interface
 + ## logger -st sixxs -- "- Starting radvd..."
 + ## /usr/sbin/radvd -C /tmp/radvd.conf
 + else
 + logger -st sixxs -- "- Note: No subnet configured yet - apply for one when you've kept the tunnel up for a week and earned enough credits"
 + fi
 +
 + logger -st sixxs -- "SixXS IPv6 setup done"
== radvd configuration == == radvd configuration ==

Revision as of 10:04, 22 April 2010

Instructions

Use this script once you have been assigned a SixXS tunnel to connect that tunnel. Once your tunnel has been up for a week, you earn enough credits to request a subnet (/48 IPv6 allocation) which you can then use for hosts on your network. See the instructions in the SETUP VALUES section for more info.

See http://www.sixxs.net/main/ for info on how to request tunnels and subnets.

Any feedback on the script welcome in this forum topic.

Instructions

Use this script once you have been assigned a SixXS tunnel to connect that tunnel. Once your tunnel has been up for a week, you earn enough credits to request a subnet (/48 IPv6 allocation) which you can then use for hosts on your network. See the instructions in the SETUP VALUES section for more info.

See http://www.sixxs.net/main/ for info on how to request tunnels and subnets.

Any feedback on the script welcome in this forum topic.

#!/bin/sh
#
# SIXXS IPv6 startup script for WRT54G
# From http://www.dd-wrt.com/wiki/index.php/IPv6_startup_script

##################################
###        SETUP VALUES        ###
### Change these before running ##
##################################

# The IPv6 prefix (/64) of the tunnel initially assigned to you by SixXS (including the ::).
# Only the ::1 and ::2 are used from this range, for the PoP and your router, respectively.
# You need to keep the tunnel up for a week in order earn enough credits to request a /48 subnet
# (see below) which can then be used by hosts on your network.
TUNNELPREFIX="2001:db8:1111:1111::"

# The IPv4 address of the SixXS PoP you're using
SIXXS4="1.1.1.1"

# MTU - must match your SixXS tunnel settings and radvd's "AdvLinkMTU" value; 1280 is the default but it can be increased.
# This script will give you a recommendation when you run it, but it should be 20 less than your IPv4 MTU.
MTU=1280

# A /64 from your /48 subnet prefix assigned by SixXS, INCLUDING the /64
## This should match what you announce to the network with radvd (set in Administration -> Management in the web interface)
# If you have not yet been assigned this (you need to keep the tunnel up for a week to earn enough credits), leave blank/commented out
##SUBNET="2001:db8:2222::/64"

# Space-separated list of extra IPs you want for your router, such as:
# * Local (RFC 4193, currently draft) address e.g. fdxx:xxxx:xxxx:yyyy::1/64; or
# * site-local (as per RFC 1918, but obseleted by RFC 3879) address e.g. fec0::1/64
# * Any other local or global fixed address you want (note: we already assign the above SUBNET address)
# This is optional, leave blank/commented out if not wanted.
###ADDITIONALIP6="fec0::1/64"

##################################
###     END OF SETUP VALUES     ##
##################################

logger -st sixxs -- "Starting IPv6 setup"

# Get the tunnel endpoint addresses
MYTUNNELIP="${TUNNELPREFIX}2"
SIXXSTUNNELIP="${TUNNELPREFIX}1"

# Get our external IPv4 (in case the IP isn't available, because we don't have a connection yet, retry 3 times or until we succeed)
RETRIES=3
while [ -z ${EXTIP} ]; do
    # PPPoE devices are on ppp0, all others are on vlan1 or eth1; we try all
    for DEV in "ppp0" "vlan1" "eth1"; do
        EXTIP=`/usr/sbin/ip -4 addr show dev ${DEV} | grep inet | awk '{print $2}' | cut -d/ -f1`
        if [ -n "$EXTIP" ]; then
            logger -st sixxs -- "- External IP ${EXTIP} found on device ${DEV}"
            break 2
        fi
    done
    let RETRIES-=1
    if [ "$RETRIES" -gt 0 ]; then
      logger -st sixxs -- "- No external IP found; trying again in 10 secs..."
      sleep 10
    else
      logger -st sixxs -- "- No external IP found after 30 seconds; quitting"
      exit 1
    fi
done

# Create tunnel
logger -st sixxs -- "- Creating SixXS tunnel ${EXTIP} <--> ${SIXXS4}"
/usr/sbin/ip tunnel add sixxs mode sit local ${EXTIP} remote ${SIXXS4}

# Bring tunnel interface up explicitly
logger -st sixxs -- "- Bringing sixxs device up"
/usr/sbin/ip link set sixxs up

# Fix MTU and TTL
logger -st sixxs -- "- Fixing MTU and TTL of sixxs device"
/usr/sbin/ip link set mtu ${MTU} dev sixxs
/usr/sbin/ip tunnel change sixxs ttl 64

# Check for optimal MTU
# Max MTU is device's MTU minus 20 (IPv6 headers are 20 bytes bigger than IPv4)
RECMTU=`ip addr show dev $DEV | grep mtu | awk '{print $5}'`
RECMTU=`expr ${RECMTU} - 20`
if [ ${MTU} -lt ${RECMTU} ]; then
    logger -st sixxs -- "- Note: You could increase your MTU setting from ${MTU} to ${RECMTU} for improved performance. Change it in ${0}, radvd.conf and in the SixXS tunnel config."
elif [ ${MTU} -gt ${RECMTU} ]; then
    ### TODO: What happens if MTU is too high?
    logger -st sixxs -- "- WARNING: Your MTU ${MTU} is too high - it should be ${RECMTU}. Change it in ${0}, radvd.conf and in the SixXS tunnel config."
fi

# Add extra IPs if any
if [ ! -z ${ADDITIONALIP6} ]; then
    for IP in ${ADDITIONALIP6}; do
   logger -st sixxs -- "- Adding fixed IP ${IP}"
   /usr/sbin/ip -6 addr add ${IP} dev br0
    done
fi

# Configure IPv6 endpoint on the tunnel
logger -st sixxs -- "- Configuring local IPv6 tunnel endpoint ${MYTUNNELIP}"
/usr/sbin/ip -6 addr add ${MYTUNNELIP}/64 dev sixxs

# Add default route
logger -st sixxs -- "- Adding default route through SixXS ${SIXXSTUNNELIP}"
/usr/sbin/ip -6 ro add default via ${SIXXSTUNNELIP} dev sixxs

if [ ! -z  ${SUBNET} ]; then
    # Add a network from the /48 subnet to br0
    logger -st sixxs -- "- Setting up subnet ${SUBNET}"
    /usr/sbin/ip -6 addr add ${SUBNET} dev br0

    ## # Start router advertisement daemon
    ## # No need to do this here; just use the setup in the web interface
    ## logger -st sixxs -- "- Starting radvd..."
    ## /usr/sbin/radvd -C /tmp/radvd.conf
else
    logger -st sixxs -- "- Note: No subnet configured yet - apply for one when you've kept the tunnel up for a week and earned enough credits"
fi

logger -st sixxs -- "SixXS IPv6 setup done"

radvd configuration

An example radvd.conf, to be used once you have been assigned a /48 subnet (see Administration -> Management in your router's web interface):

 interface br0 {
     AdvSendAdvert on;
     AdvHomeAgentFlag on;
     AdvLinkMTU 1280;
     MinRtrAdvInterval 3;
     MaxRtrAdvInterval 10;
     prefix [REPLACE WITH SUBNET]/64 {
         AdvOnLink on;
         AdvAutonomous on;
         AdvRouterAddr on;
     };
 };