Projecte

General

Perfil

Connect ipv6 » Historial » Versió 1

Pau Escrich, 29-05-2013 10:29

1 1 Pau Escrich
h1. Connect ipv6 link-local
2
3
Each working network interface in your Linux system have a special IPv6 address configured automatically by the Kernel. These are named IPv6 link-local and are inside the special prefix fe80::/10
4
The scope of these IPs is to communicate computers which are in the same colision domain (for example our LAN network). But, how to know the IPv6 link-local address of the host we want to achieve?
5
Using ICMPv6 we can discover machines in our network thanks to the special Multicast address "ff02::". So to discover routers (group 2) we can use the next command:
6
7
<pre>
8
ping6 ff02::2%eth0
9
</pre>
10
11
Then each router connected to our colision domain, will reply the ICMP request with its own IPv6 link-local address. We can use connect to it using ssh:
12
13
<pre>
14
ssh fe80::a2f3:c1ff:fe39:1cea%eth1
15
</pre>
16
17
Or copy files using scp:
18
19
<pre>
20
scp QMP.bin [fe80::a2f3:c1ff:fe39:1cea%eth1]:/tmp/
21
</pre>
22
23
This is a small script which check if there is some router attached to your network device and in case, try to connect to it. If there are not routers it waits until some appears.
24
25
<pre>
26
#!/bin/sh
27
INT=${1:-eth0}
28
MYIP="$(ip addr show dev $INT | grep -e "inet6.*scope link" | awk '{print $2}' | cut -d/ -f1)"
29
NEIGH="$(ping6 ff02::2%$INT -n -c3 2>/dev/null | grep fe80 2>/dev/null | awk '{print $4}' | sed 's/\(.*\)./\1/' | sort -u)"
30
RNEIGH="$(echo -e "$NEIGH" | grep -v $MYIP | grep -v "^$" | sort -u)"
31
if [ $(echo -e "$RNEIGH" | wc -l) -eq 1 -a $(echo -e "$RNEIGH" | wc -c) -gt 4 ]; then
32
	echo "Host found, connecting with it!"
33
	ssh $RNEIGH%$INT
34
elif [ -z "$RNEIGH" ]; then
35
	echo -n "."
36
	exec $0 $@
37
else
38
	echo "Several Hosts found:"
39
	echo -e "$RNEIGH"
40
fi
41
</pre>
42
43
44
An example of execution:
45
46
<pre>
47
p4u@nomada:~$ $ disc6 eth1
48
..................................Host found, connecting with it!
49
50
Warning: Permanently added 'fe80::a2f3:c1ff:fe39:7cea%eth1' (RSA) to the list of known hosts.
51
root@fe80::a2f3:c1ff:fe39:7cea%eth1's password: 
52
</pre>