ユーザ用ツール

サイト用ツール


mae3xx_tips:setup_openvpn:setup_server:start

以前のリビジョンの文書です


サーバ側の設定

Ubuntu が楽なので、ベース部分に Ubuntu Linux 14.04LTS を導入済みの環境を前提とします。

# cat /etc/os-release 
NAME="Ubuntu"
VERSION="14.04.1 LTS, Trusty Tahr"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 14.04.1 LTS"
VERSION_ID="14.04"
HOME_URL="http://www.ubuntu.com/"
SUPPORT_URL="http://help.ubuntu.com/"
BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"


Docker を使用する場合は、CoreOS を使うのもよいかもしれません。

参考: CoreOS 入門 - Qiita


LXC を使用する

LXC を使用するために、パッケージから

  • lxc
  • lxc-templates (lxc と一緒にインストールされます)

をインストールしておきます。

root@macaron:~# apt-get install lxc
Reading package lists... Done
Building dependency tree       
Reading state information... Done
The following extra packages will be installed:
  lxc-templates
…


コンテナの作成

“lxc-create” コマンドで、コンテナを作成します。テンプレートは、ホスト OS と同じ Ubuntu Linux を使用します。

root@macaron:~# lxc-create -n ubuntu -t ubuntu 
Checking cache download in /var/cache/lxc/trusty/rootfs-amd64 ... 
Installing packages in template: ssh,vim,language-pack-en
Downloading ubuntu trusty minimal ...
I: Retrieving Release 
I: Retrieving Release.gpg 
I: Checking Release signature
I: Valid Release signature (key id 790BC7277767219C42C86F933B4FE6ACC0B21F32)
〜〜〜 中略 〜〜〜
Generating locales...
  en_US.UTF-8... up-to-date
Generation complete.
Creating SSH2 RSA key; this may take some time ...
Creating SSH2 DSA key; this may take some time ...
Creating SSH2 ECDSA key; this may take some time ...
Creating SSH2 ED25519 key; this may take some time ...
update-rc.d: warning: default stop runlevel arguments (0 1 6) do not match ssh Default-Stop values (none)
invoke-rc.d: policy-rc.d denied execution of start.

Current default time zone: 'Asia/Tokyo'
Local time is now:      Tue Sep  9 12:09:56 JST 2014.
Universal Time is now:  Tue Sep  9 03:09:56 UTC 2014.


##
# The default user is 'ubuntu' with password 'ubuntu'!
# Use the 'sudo' command to run tasks as root in the container.
##

root@macaron:~# 

作成されました。
デフォルトで、ユーザ “ubuntu” が作成されます。

ネットワークは、デフォルトではこのように構成されます。

LXC network

root@macaron:~# ip addr show lxcbr0
9: lxcbr0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UNKNOWN group default 
    link/ether 72:f5:1b:d1:75:8d brd ff:ff:ff:ff:ff:ff
    inet 10.0.3.1/24 brd 10.0.3.255 scope global lxcbr0
       valid_lft forever preferred_lft forever
    inet6 fe80::70f5:1bff:fed1:758d/64 scope link 
       valid_lft forever preferred_lft forever


コンテナの起動

コンテナは作成されましたが、

  • ユーザアカウント
  • ネットワーク

など、設定する必要があります。最初はネットワークの設定が DHCP に設定されていて割り当てられるアドレスがわからないため、フォアグランドで起動します。

root@macaron:~# lxc-start -n ubuntu
<4>init: plymouth-upstart-bridge main process (5) terminated with status 1
<4>init: plymouth-upstart-bridge main process ended, respawning
<4>init: hwclock main process (7) terminated with status 77
<4>init: ureadahead main process (8) terminated with status 5
<4>init: plymouth-upstart-bridge main process (15) terminated with status 1
<4>init: plymouth-upstart-bridge main process ended, respawning
<4>init: plymouth-upstart-bridge main process (20) terminated with status 1
<4>init: plymouth-upstart-bridge main process ended, respawning
 * Starting Mount filesystems on boot   ...done.

… 起動メッセージが続きます
Ubuntu 14.04.1 LTS ubuntu console

ubuntu login: <4>init: setvtrgb main process (420) terminated with status 1
 * Stopping save kernel messages   ...done.
<4>init: plymouth-upstart-bridge main process ended, respawning


Ubuntu 14.04.1 LTS ubuntu console

ubuntu login: 


初期設定された、“ubuntu” でログインできます。

Ubuntu 14.04.1 LTS ubuntu console

ubuntu login: ubuntu
Password: 
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-35-generic x86_64)

 * Documentation:  https://help.ubuntu.com/

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

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

ubuntu@ubuntu:~$ 


IP アドレスは、ホスト側 lxcbr0 と同じネットワーク (10.0.3.0/24) のアドレスが割り当てられていることがわかります。

ubuntu@ubuntu:~$ ip addr show eth0
10: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 00:16:3e:99:4f:ac brd ff:ff:ff:ff:ff:ff
    inet 10.0.3.25/24 brd 10.0.3.255 scope global eth0
       valid_lft forever preferred_lft forever
    inet6 fe80::216:3eff:fe99:4fac/64 scope link 
       valid_lft forever preferred_lft forever
ubuntu@ubuntu:~$


外部のホストへのアクセスもできることを確認しておきます。

ubuntu@ubuntu:~$ ping -c 2 www.yahoo.co.jp
PING www.g.yahoo.co.jp (183.79.231.182) 56(84) bytes of data.
64 bytes from f12.top.vip.ogk.yahoo.co.jp (183.79.231.182): icmp_seq=1 ttl=51 time=30.7 ms
64 bytes from f12.top.vip.ogk.yahoo.co.jp (183.79.231.182): icmp_seq=2 ttl=51 time=30.9 ms

--- www.g.yahoo.co.jp ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 30.772/30.843/30.914/0.071 ms
ubuntu@ubuntu:~$ 


コンテナの設定

Ubuntu Template でインストールしたままでは、eth0 の IP アドレスの割り当て方法が DHCP となっていて、
外部からのパケットを転送するには不便なので、固定アドレスを割り当てておきます。
また、ホスト側で dnsmasq1) が動作しているので、DNS をホストの IP アドレスにしてしまいます。

デフォルト状態

interfaces.orig
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
 
# The loopback network interface
auto lo
iface lo inet loopback
 
auto eth0
iface eth0 inet dhcp

変更後

interfaces
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
 
# The loopback network interface
auto lo
iface lo inet loopback
 
auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
	address 10.0.3.100
	netmask 255.255.255.0
	gateway 10.0.3.1
	dns-nameserver 10.0.3.1


実運用に使用する場合、アカウントも変更しておいたほうが良いと思います。
変更できたら、コンテナを停止し、バックグラウンドで起動させます。

ubuntu@ubuntu:~$ sudo halt
[sudo] password for ubuntu: 

Broadcast message from ubuntu@ubuntu
	(/dev/lxc/console) at 17:35 ...

The system is going down for halt NOW!
ubuntu@ubuntu:~$ <4>init: tty4 main process (351) killed by TERM signal
… メッセージが続きます

ホストのプロンプトに戻ったら、バックグラウンドで起動させます。

root@macaron:~# lxc-start -n ubuntu -d
root@macaron:~# lxc-ls --fancy
NAME    STATE    IPV4        IPV6  AUTOSTART  
--------------------------------------------
ubuntu  RUNNING  10.0.3.100  -     NO         


これ以降は、コンソールではなく SSH で接続します。

$ ssh -l ubuntu 10.0.3.100
The authenticity of host '10.0.3.100 (10.0.3.100)' can't be established.
ECDSA key fingerprint is 1a:1a:6b:6c:90:99:7b:72:76:1f:b0:a3:99:92:2d:08.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '10.0.3.100' (ECDSA) to the list of known hosts.
ubuntu@10.0.3.100's password: 
Welcome to Ubuntu 14.04.1 LTS (GNU/Linux 3.13.0-35-generic x86_64)

 * Documentation:  https://help.ubuntu.com/
Last login: Tue Sep  9 17:34:04 2014
ubuntu@ubuntu:~$ 


OpenVPN の導入

1)
DHCP server, DNS cache などを兼ねるスグレモノです
mae3xx_tips/setup_openvpn/setup_server/start.1551073740.txt.gz · 最終更新: 2019/02/25 14:49 by admin