I.T. Security and Linux Administration

Dec 31 2012   2:24PM GMT

IPv6 Startup Script

Eric Hansen Eric Hansen Profile: Eric Hansen

After writing this article: http://itknowledgeexchange.techtarget.com/security-admin/ipv6-and-linux/ I decided to write a simple script that will allow you to start and stop the IPv6 functionality pretty easily. The script is pretty well commented and easy to use:

#!/bin/bash

# This script is modified from the one found here: https://wiki.archlinux.org/index.php/IPv6_-_Tunnel_Broker_Setup
# Noticably this script now runs like this:
# $0
#
# So if you want IPv6 traffic to be routed through wlan0, you would do:
# $0 start wlan0

if [ "$EUID" -ne 0 ]; then
echo "You must run this as root"
exit 1
fi

# Edit these
if_name=he6in4
server_ipv4='' # HE Server Endpoint IP
client_ipv6='' # Your HE-assigned client IP

# Don't edit below this line
client_ipv4=''
link_mtu=1480
tunnel_ttl=255

if [ -n "$2" ]; then
client_ipv4=$(ifconfig eth0 | grep netmask | awk '{print $2}')
fi

if [ -z "$client_ipv4" ]; then
echo "Usage: $0 "
exit 1
fi

echo "Tunneling data from IPv6 to $2 (IP: $client_ipv4)"

daemon_name=6in4-tunnel

# . /etc/rc.conf
# . /etc/rc.d/functions

case "$1" in
start)
# stat_busy "Starting $daemon_name daemon"

ifconfig $if_name &>/dev/null
if [ $? -eq 0 ]; then
stat_busy "Interface $if_name already exists"
stat_fail
exit 1
fi

ip tunnel add $if_name mode sit remote $server_ipv4 local $client_ipv4 ttl $tunnel_ttl
ip link set $if_name up mtu $link_mtu
ip addr add $client_ipv6 dev $if_name
ip route add ::/0 dev $if_name
# Here is how you would add additional ips....which should be on the eth0 interface
# ip addr add 2001:XXXX:XXXX:beef:beef:beef:beef:1/64 dev eth0
# ip addr add 2001:XXXX:XXXX:beef:beef:beef:beef:2/64 dev eth0
# ip addr add 2001:XXXX:XXXX:beef:beef:beef:beef:3/64 dev eth0

add_daemon $daemon_name
stat_done
;;

stop)
stat_busy "Stopping $daemon_name daemon"

ifconfig $if_name &>/dev/null
if [ $? -ne 0 ]; then
stat_busy "Interface $if_name does not exist"
stat_fail
exit 1
fi

ip link set $if_name down
ip tunnel del $if_name

rm_daemon $daemon_name
stat_done
;;

*)
echo "usage: $0 {start|stop}"
esac
exit 0

The download link for this script can be found here: https://gist.github.com/4422119

 Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: