LoginSignup
6
6

More than 3 years have passed since last update.

Ubuntu14.04でlxc debianコンテナ環境を構築

Last updated at Posted at 2014-07-27

ホスト環境構築

lxcのインストール

apt-get install lxc

コンテナの作成

lxc-create -t debian -n test

作成したコンテナを起動、端末へ入る

lxc-start -n test

ログイン情報はコンテナを作成した際の最後にコンソールへ表示されている

DHCPのIPアドレスの割り当て範囲を変更

emacs /etc/default/lxc-net
lxc-net
#LXC_DHCP_RANGE="10.0.3.2,10.0.3.254"
LXC_DHCP_RANGE="10.0.3.100,10.0.3.254"

一旦reboot
bash
ps ax | grep lxc-dnsmasq

を実行して、変更が反映されていることを確認

lxc環境構築

rootパスワードの変更

passwd root

ユーザの作成

adduser test

必要なパッケージのインストール

apt-get install apt-utils emacs ssh

コンテナのIPアドレスを固定

emacs /etc/network/interfaces

interfaces
#auto eth0
#iface eth0 inet dhcp
iface eth0 inet static
  address   10.0.3.2
  network   10.0.3.0
  netmask   255.255.255.0
  broadcast 10.0.3.255
  gateway   10.0.3.1
  dns-nameservers 10.0.3.1

ネットワークを再起動
/etc/init.d/networking restart

再度ホストから設定

ホスト側から変更後のIPアドレスにPINGが通るのか確認
ping 10.0.3.2

IP_forwardの設定

echo 1 > /proc/sys/net/ipv4/ip_forward
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf

続きは後ほど加筆

6
6
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
6
6