LoginSignup
0
0

More than 3 years have passed since last update.

Tinc VPNで作る簡易的なVirtual Private Network 2/5 (構築編(1) ルートノードの構築 - Linux編)

Last updated at Posted at 2020-06-05

概要

『Tinc VPNで作る簡易的なVirtual Private Network』の分割記事

1/5 構築編(1) ルートノードの構築 - Linux編

各記事

構築

構築(0)トポロジー (共通記載)

以下のトポロジーで記載を行う。

  • ネットワーク名 - myvpn #設定ファイル群を置くフォルダ名になる
  • VPNのIPセグメント - 192.168.15.0/24
Node Name OS Architecture Mode Global IP
port
Domain
VPN IP
root server CentOS 7 x68_64 router available
10655
mydomain.org
192.168.15.1
child client1 Windows 10 x64 router 192.168.15.2
child client2 CentOS 7 armv7
(Raspberry Pi3)
router 192.168.15.3
child client3 Android arm router 192.168.15.4

構築(1) ルートノードの構築 - Linux ★本稿

手順(0) ファイル構成

[etc]
  ├ [tinc]
  │   └ [myvpn]
  │       ├ [hosts]
  │       │   ├ server
  │       │   ├ client1 ※(別紙) 子ノードとの鍵交換で今後増えます
  │       │   ├ client2 ※(別紙) 子ノードとの鍵交換で今後増えます
  │       │   └ client3 ※(別紙) 子ノードとの鍵交換で今後増えます
  │       ├ rsa_key.priv
  │       ├ tinc.conf
  │       ├ tinc-down
  │       └ tinc-up
  │
  ├ [systemd]
  │   ├ [system]
  │   │   ├ tincd.seervice

手順(1) TincVPNのインストール

yum install epel-release.noarch
vi /etc/yum.repos.d/epel.repo
/etc/yum.repos.d/epel.repo
# EPELはデフォルト無効にしておく
[epel]
-------------------------------------------
enabled=0 # enabled=1
-------------------------------------------
[epel-debuginfo]
-------------------------------------------
enabled=0 # enabled=1
-------------------------------------------
[epel-source]
-------------------------------------------
enabled=0 # enabled=1
-------------------------------------------
yum --enablerepo=epel install tinc

手順(2) tinc.conf作成

mkdir -p /etc/tinc/myvpn
touch /etc/tinc/myvpn/tinc.conf
tinc.conf
#tinc.conf
Name = server
AutoConnect = yes
Mode = router

手順(3) 自身のホストファイルを作成

hostsフォルダ内に、
tinc.confのNameで指定した名前と同じ名前でファイルを作成する。

mkdir -p /etc/tinc/myvpn/hosts
touch /etc/tinc/myvpn/hosts/server
vi /etc/tinc/myvpn/hosts/server
/etc/tinc/myvpn/hosts/server
Subnet = 192.168.15.1/32
# 外部からのアクセス用アドレス。
# グローバルIPでも可
Address = mydomain.org
# 一応任意のポートで運用してみる
Port = 10655

手順(4) キーの作成

tincd -n myvpn -K4096

# 秘密鍵が生成されているのを確認する。
less /etc/tinc/myvpn/rsa_key.priv

# 公開鍵が追記されているのを確認する。
less /etc/tinc/myvpn/hosts/server

※公開鍵が追記された自身のホスト ファイルは後で他のノードに配布する。

手順(5) 起動スクリプトの作成

実行権限も忘れずに。

touch /etc/tinc/myvpn/tinc-up
chmod +100 /etc/tinc/myvpn/tinc-up
vi /etc/tinc/myvpn/tinc-up
/etc/tinc/myvpn/tinc-up
#!/bin/sh


# VPN上でのIP
ifconfig $INTERFACE 192.168.15.1 netmask 255.255.255.0

手順(6) 終了スクリプトの作成

実行権限も忘れずに。

touch /etc/tinc/myvpn/tinc-down
chmod +100 /etc/tinc/myvpn/tinc-down
vi /etc/tinc/myvpn/tinc-down
/etc/tinc/myvpn/tinc-down
#!/bin/sh


ifconfig $INTERFACE down

手順(7) 起動テスト

tincd -n myvpn -d3 -D

手順(8) サービス作成・登録・実行

touch /etc/systemd/system/tincd.service
vi /etc/systemd/system/tincd.service
/etc/systemd/system/tincd.service
[Unit]
Description=tinc myvpn
After=network.target

[Service]
Type=simple
ExecStart=/usr/sbin/tincd -n myvpn -d3 -D
Restart=always
RestartSec=10

[Install]
WantedBy=multi-user.target
systemctl enable tincd.service
systemctl start tincd.service

# 確認
systemctl status tincd.service

# ログをリアルタイムに確認
journalctl -f -u tincd.service

構築(2) 子ノードの構築 - Windows

Tinc VPNで作る簡易的なVirtual Private Network 3/5 (構築編(2) 子ノードの構築 - Windows編)

構築(3) 子ノードの構築 - Linux]

Tinc VPNで作る簡易的なVirtual Private Network 4/5 (構築編(3) 子ノードの構築 - Linux編)

構築(4) 子ノードの構築 - Android

Tinc VPNで作る簡易的なVirtual Private Network 5/5 (構築編(4) 子ノードの構築 - Android編)

謝辞

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0