LXCのネットワーク設定の不具合を解決
前回作成したLXC(Linux Container)でしたがネットワーク設定がいまいちだったので見直してみた。これで良いのかは微妙なのですが、うまく行ってるっぽいので報告までLXCのインストールは前のネタを参照して下さい
まず、ホスト側の設定ファイルのネットワークの設定と、sysfsの設定値をいじくってこんな感じでコメントアウトされている2行を有効にする
karky7 ~ # diff /opt/lxc-gentoo/gentoo2.conf /opt/lxc-gentoo/gentoo2.conf.ORG 16c16 < lxc.network.link = br0 --- > #lxc.network.link = br0 26c26 < lxc.mount.entry=sys /opt/lxc-gentoo/gentoo2/sys sysfs defaults 0 0 --- > #lxc.mount.entry=sys /opt/lxc-gentoo/gentoo2/sys sysfs defaults 0 0で起動してみる
karky7 ~ # lxc-start -f /opt/lxc-gentoo/gentoo2.conf -n gentoo2 INIT: version 2.88 booting OpenRC 0.11.8 is starting up Gentoo Linux (x86_64) [LXC] * /proc is already mounted * /run/openrc: creating directory * /run/lock: creating directory * /run/lock: correcting owner * Creating user login records ... [ ok ] * Cleaning /var/run ... [ ok ] * Wiping /tmp directory ... [ ok ] * Updating /etc/mtab ... [ ok ] * Bringing up interface lo * 127.0.0.1/8 ... [ ok ] * Adding routes * 127.0.0.0/8 via 127.0.0.1 ... [ ok ] * setting up tmpfiles.d entries ... [ ok ] INIT: Entering runlevel: 3 * Starting local [ ok ] gentoo2 login: root (automatic login) gentoo2 ~ #
無事コンテナにログインできる
net.eth0を作成する
この設定をやらないと、「sshdとかがnetが無い!」としかられて起動しませんでした
gentoo2 ~ # cd /etc/init.d/ gentoo2 init.d # ln -s net.lo net.eth0 ... ... gentoo2 ~ # /etc/init.d/sshd start * Starting sshd ... [ ok ] gentoo2 ~ #
LXCにおけるゲスト側のIP、Gatewayなどの設定
Gentooでネットワークの設定は/etc/conf.d/netで設定するのが普通ですが、コンテナのネットワーク設定は基本的にホスト側のgentoo2.confへ書かれているので、得にコンテナ内の/etc/conf.d/netは編集しなくてもい良いらしいです
/opt/lxc-gentoo/gentoo2.conf抜粋
# set arch lxc.arch = x86_64 # set the hostname lxc.utsname = gentoo2 # network interface lxc.network.type = veth lxc.network.flags = up # - name in host (max 15 chars; defaults to 'tun'+random) lxc.network.veth.pair = gentoo2 # - name in guest lxc.network.name = eth0 # enable for bridging # (eg. 'brctl addbr br0; brctl setfd br0 0; brctl addif br0 eth0') lxc.network.link = br0 lxc.network.ipv4 = 192.168.11.125/24 lxc.network.ipv4.gateway = 192.168.11.1 ... ...
ホスト側に、コンテナのIPの設定が記載されています
- lxc.network.ipv4
- コンテナのIPアドレス
- lxc.network.ipv4.gateway
- コンテナのGateway
gentoo2 ~ # cat /etc/conf.d/net config_eth0="null"
となっていて、得に設定は必要無いようです、最後にresolv.confの設定を忘れないように...
まぁ適当にやる前に、しっかりドキュメント読めって言われそうだが....
0 件のコメント:
コメントを投稿