Projecte

General

Perfil

Connect ipv6 » Historial » Versió 2

Pau Escrich, 29-05-2013 10:35

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 2 Pau Escrich
Then each router connected to our colision domain, will reply the ICMP request with its own IPv6 link-local address.
12
<pre>
13
p4u@nomada:~$ $ ping6 ff02::2%eth1 -c2
14
PING ff02::2%eth1(ff02::2) 56 data bytes
15
64 bytes from fe80::a2f3:c1ff:fe39:7cea: icmp_seq=1 ttl=64 time=0.956 ms
16
64 bytes from fe80::a2f3:c1ff:fe39:7cea: icmp_seq=2 ttl=64 time=0.949 ms
17
18
--- ff02::2%eth1 ping statistics ---
19
2 packets transmitted, 2 received, 0% packet loss, time 1000ms
20
rtt min/avg/max/mdev = 0.949/0.952/0.956/0.031 ms
21
</pre>
22
23
We can use connect to it using ssh:
24 1 Pau Escrich
25
<pre>
26
ssh fe80::a2f3:c1ff:fe39:1cea%eth1
27
</pre>
28
29
Or copy files using scp:
30
31
<pre>
32
scp QMP.bin [fe80::a2f3:c1ff:fe39:1cea%eth1]:/tmp/
33
</pre>
34
35
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.
36
37
<pre>
38
#!/bin/sh
39
INT=${1:-eth0}
40
MYIP="$(ip addr show dev $INT | grep -e "inet6.*scope link" | awk '{print $2}' | cut -d/ -f1)"
41
NEIGH="$(ping6 ff02::2%$INT -n -c3 2>/dev/null | grep fe80 2>/dev/null | awk '{print $4}' | sed 's/\(.*\)./\1/' | sort -u)"
42
RNEIGH="$(echo -e "$NEIGH" | grep -v $MYIP | grep -v "^$" | sort -u)"
43
if [ $(echo -e "$RNEIGH" | wc -l) -eq 1 -a $(echo -e "$RNEIGH" | wc -c) -gt 4 ]; then
44
	echo "Host found, connecting with it!"
45
	ssh $RNEIGH%$INT
46
elif [ -z "$RNEIGH" ]; then
47
	echo -n "."
48
	exec $0 $@
49
else
50
	echo "Several Hosts found:"
51
	echo -e "$RNEIGH"
52
fi
53
</pre>
54
55
56
An example of execution:
57
58
<pre>
59
p4u@nomada:~$ $ disc6 eth1
60
..................................Host found, connecting with it!
61
62
Warning: Permanently added 'fe80::a2f3:c1ff:fe39:7cea%eth1' (RSA) to the list of known hosts.
63
root@fe80::a2f3:c1ff:fe39:7cea%eth1's password: 
64
</pre>