• このエントリーをはてなブックマークに追加


参考

ポイントは,次の 2点になるでしょうか:

  • Pipework でブリッジを追加する & ゲストへの IP アドレスを割り当てる
  • ホストのブリッジに IP アドレスを割り当てる

ホスト OS の環境

さくらの VPS,Ubuntu 12.04.

インタフェイス eth0 はこんな感じ:

$ ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether **:**:**:**:**:** brd ff:ff:ff:ff:ff:ff
    inet ***.***.***.***/23 brd ***.***.***.255 scope global eth0
    inet6 ****::****:***:***1:****/64 scope link
       valid_lft forever preferred_lft forever

参考サイトのとおりに進めてみる

Pipework を入れる

$ cd /usr/local/src
$ sudo git clone https://github.com/jpetazzo/pipework.git
Cloning into 'pipework'...
remote: Reusing existing pack: 134, done.
remote: Total 134 (delta 0), reused 0 (delta 0)
Receiving objects: 100% (134/134), 36.66 KiB, done.
Resolving deltas: 100% (68/68), done.
$ sduo ln -sv /usr/local/src/pipework/pipework /usr/local/bin/
`/usr/local/bin/pipework' -> `/usr/local/src/pipework/pipework'
$ sudo pipework
Syntax:
pipework <hostinterface> [-i containerinterface] <guest> <ipaddr>/<subnet>[@default_gateway] [macaddr]
pipework <hostinterface> [-i containerinterface] <guest> dhcp [macaddr]
pipework --wait

Pipework 実行時にエラー?

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
0c563183d391        base:latest         /bin/bash           7 minutes ago       Up 7 minutes                            backstabbing_kowalevski
$ sudo pipework br1 0c563183d391 192.168.1.10/24
/usr/local/bin/pipework: line 152: brctl: command not found

brctl というものがないらしい.

bridge-utils パッケージを入れればよいらしい.

$ sudo apt-get -y install bridge-utils
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  python-central libvncserver0 libgsoap1
Use 'apt-get autoremove' to remove them.
The following NEW packages will be installed:
  bridge-utils
0 upgraded, 1 newly installed, 0 to remove and 0 not upgraded.
Need to get 32.0 kB of archives.
After this operation, 142 kB of additional disk space will be used.
Get:1 http://jp.archive.ubuntu.com/ubuntu/ precise-updates/main bridge-utils amd64 1.5-2ubuntu7 [32.0 kB]
Fetched 32.0 kB in 0s (141 kB/s)
Selecting previously unselected package bridge-utils.
(Reading database ... 106135 files and directories currently installed.)
Unpacking bridge-utils (from .../bridge-utils_1.5-2ubuntu7_amd64.deb) ...
Processing triggers for man-db ...
Setting up bridge-utils (1.5-2ubuntu7) ...
$ sudo pipework br1 0c563183d391 192.168.1.10/24
Warning: arping not found; interface may not be immediately reachable

さらに 「arping がない」と言われるので,これも入れる.

$ sudo apt-get -y install arping
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages were automatically installed and are no longer required:
  python-central libvncserver0 libgsoap1
Use 'apt-get autoremove' to remove them.
The following extra packages will be installed:
  libnet1
The following NEW packages will be installed:
  arping libnet1
0 upgraded, 2 newly installed, 0 to remove and 0 not upgraded.
Need to get 75.3 kB of archives.
After this operation, 267 kB of additional disk space will be used.
Get:1 http://jp.archive.ubuntu.com/ubuntu/ precise/main libnet1 amd64 1.1.4-2.1 [49.4 kB]
Get:2 http://jp.archive.ubuntu.com/ubuntu/ precise/universe arping amd64 2.09-2 [25.9 kB]
Fetched 75.3 kB in 0s (164 kB/s)
Selecting previously unselected package libnet1.
(Reading database ... 106160 files and directories currently installed.)
Unpacking libnet1 (from .../libnet1_1.1.4-2.1_amd64.deb) ...
Selecting previously unselected package arping.
Unpacking arping (from .../arping_2.09-2_amd64.deb) ...
Processing triggers for man-db ...
Setting up libnet1 (1.1.4-2.1) ...
Setting up arping (2.09-2) ...
Processing triggers for libc-bin ...
ldconfig deferred processing now taking place

気を取り直して

$ sudo docker ps
CONTAINER ID        IMAGE               COMMAND             CREATED             STATUS              PORTS               NAMES
2aa3698efed5        base:latest         /bin/bash           7 seconds ago       Up 6 seconds                            silly_fermat
$ sudo pipework br1 2aa3698efed5 192.168.1.21/24

エラー・警告がなくなりました.

割り当て前後におけるコンテナの ifconfig を比較してみる

before:

root@2aa3698efed5:/# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 96:6e:8c:76:0e:ef
          inet addr:172.17.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::946e:8cff:fe76:eef/64 Scope:Link
          UP BROADCAST RUNNING  MTU:1500  Metric:1
          RX packets:5 errors:0 dropped:2 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:378 (378.0 B)  TX bytes:468 (468.0 B)
 
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

after:

root@2aa3698efed5:/# ifconfig -a
eth0      Link encap:Ethernet  HWaddr 96:6e:8c:76:0e:ef
          inet addr:172.17.0.2  Bcast:0.0.0.0  Mask:255.255.0.0
          inet6 addr: fe80::946e:8cff:fe76:eef/64 Scope:Link
          UP BROADCAST RUNNING  MTU:1500  Metric:1
          RX packets:5 errors:0 dropped:2 overruns:0 frame:0
          TX packets:6 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:378 (378.0 B)  TX bytes:468 (468.0 B)
 
eth1      Link encap:Ethernet  HWaddr 7a:46:04:45:de:a9
          inet addr:192.168.1.21  Bcast:0.0.0.0  Mask:255.255.255.0
          inet6 addr: fe80::7846:4ff:fe45:dea9/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:6 errors:0 dropped:0 overruns:0 frame:0
          TX packets:7 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:468 (468.0 B)  TX bytes:510 (510.0 B)
 
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

インタフェイス eth1 が追加され,その IP アドレスが指定したものになりました.

ホスト側のブリッジに IP アドレスを割りてる

$ sudo ip addr add 192.168.1.254/24 dev br1

これは特に問題なく.

しかし,ping 192.168.1.21 してもうまくいかず,原因を調べられるほどネットワークの知識もなく,いったん中断.

とりあえずつながった

いくらか試行錯誤?して,割り当てる IP アドレスを 192.168.1.* でないものにしたところ,とりあえず ping が通ったので,そのあたりを記録しておきます.

先の 192.168.1.21 に代わり,192.168.10.21 を割り当ててみます:

$ sudo pipework br1 ... 192.168.10.21/24
$ sudo ip addr add 192.168.10.1/24 dev br1

こうしたら ping が通りました...

コンテナをもうひとつ立ち上げて,192.168.10.22 を割り当ててみます:

$ sudo pipework br1 ... 192.168.10.22/24

ホスト → 2台目ゲスト,1台目ゲスト・2台目ゲスト間,いずれも ping が通りました.