2016년 11월 5일 토요일

랜 선으로 두 대의 RPi 연결

랜 선 하나만으로 두 대의 라즈베리 파이를 연결할 수 있는지 실험해보았다. 결과는 성공이다.



랜 케이블로 연결된 두 대의 라즈베리 파이의 호스트명은 각각 rpi1과 rpi3이다. rpi1에는 HDMI와 키보드, 마우스를 연결하고 micro USB 전원을 연결했다. rpi3은 헤드레스로, USB-TTL 케이블을 통해 노트북의 USB 포트에서 전원을 공급받으며, 노트북에서 콘솔을 띄웠다.

rpi3에서 ifconfig로 IP 주소를 확인한 후,
pi@rpi3:~$ ifconfig eth0
eth0      Link encap:Ethernet  HWaddr b8:27:eb:74:7d:c9
          inet addr:169.254.218.16  Bcast:169.254.255.255  Mask:255.255.0.0
          inet6 addr: fe80::bbe0:b9f7:d1f3:1222/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:88 errors:0 dropped:0 overruns:0 frame:0
          TX packets:133 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:21761 (21.2 KiB)  TX bytes:34334 (33.5 KiB)

rpi1에서 rpi3으로 ping 테스트를 해보니 잘 된다.
pi@rpi1 ~ $ ping -c 3 169.254.218.16
PING 169.254.218.16 (169.254.218.16) 56(84) bytes of data.
64 bytes from 169.254.218.16: icmp_req=1 ttl=64 time=0.578 ms
64 bytes from 169.254.218.16: icmp_req=2 ttl=64 time=0.483 ms
64 bytes from 169.254.218.16: icmp_req=3 ttl=64 time=0.544 ms

--- 169.254.218.16 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2000ms
rtt min/avg/max/mdev = 0.483/0.535/0.578/0.039 ms

SSH 접속도 잘 된다.
pi@rpi1:~$ ssh pi@169.254.218.16
The authenticity of host '169.254.218.16 (169.254.218.16)' can't be established.
ECDSA key fingerprint is 78:7a:83:49:ae:18:91:45:91:37:03:ca:fa:d3:14:f5.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '169.254.218.16' (ECDSA) to the list of known hosts.
pi@169.254.218.16's password:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Nov  5 13:10:27 2016 from rpi1.local
pi@rpi3:~$

IP 주소를 입력하는 대신 호스트명을 사용하기 위해, rpi1에 있는 /etc/hosts 파일의 끝에 rpi3의 IP 주소를 추가했다.
pi@rpi1 ~ $ tail -1 /etc/hosts
169.254.218.16  rpi3

그리고, SSH 접속을 할 때마다 패스워드를 입력하지 않기 위해 다음과 같이 키를 생성 및 복사했다.
$ ssh-keygen
$ ssh-copy-id pi@rpi3
$ ssh-add

지금까지 한 일은 아래의 영상과 같은 것을 만들어 보기 위한 준비 과정이었다. 소스 코드는 여기에 있다.

댓글 없음:

댓글 쓰기