LoginSignup
6
7

More than 5 years have passed since last update.

Linuxでdummy net driverを使った仮想ブリッジを複数作る方法

Posted at

dummy net driverを使った仮想ブリッジを複数作る方法のメモ。
Linuxで物理NICを使わずに仮想ブリッジを作る方法の続きです。


※以下はGentoo Linuxでの方法なので各ディストリビューションに合わせた読み替えが必要です。

前回(Linuxで物理NICを使わずに仮想ブリッジを作る方法)のように、CONFIG_DUMMYが有効なカーネルで、

[root@TALISKER] # zgrep CONFIG_DUMMY\= /proc/config.gz
CONFIG_DUMMY=m
[root@TALISKER] # modprobe dummy
[root@TALISKER] # lsmod | grep -i dummy
dummy                   1997  0 

こんなsymlinkを張って、

[root@TALISKER] # ls -al /etc/init.d/net.[dummy,br]*
lrwxrwxrwx 1 root root 6 Feb 16 13:05 /etc/init.d/net.br0forLXC -> net.lo*
lrwxrwxrwx 1 root root 6 Feb 16 13:10 /etc/init.d/net.br1forVPN -> net.lo*
lrwxrwxrwx 1 root root 6 Feb 16 13:18 /etc/init.d/net.dummy0 -> net.lo*
lrwxrwxrwx 1 root root 6 Feb 16 13:18 /etc/init.d/net.dummy1 -> net.lo*

こんなネットワーク設定を書けば、

[root@TALISKER] # grep -E '(dummy|br[0-9]for)' /etc/conf.d/net
config_dummy0=(null)
bridge_br0forLXC="dummy0"
config_br0forLXC="172.30.0.1/23"
config_dummy1=(null)
bridge_br1forVPN="dummy1"
config_br1forVPN="172.30.2.1/23"

物理NICを節約しつつ仮想ブリッジが作れます。

[root@TALISKER] # /etc/init.d/net.br0forLXC start
 * Bringing up interface br0forLXC
 *   Destroying bridge br0forLXC ...                                      [ ok ]
 *   Creating bridge br0forLXC ...
 *   Adding ports to br0forLXC
 *     dummy0 ...                                                         [ ok ]
 *   172.30.0.1/23 ...                                                    [ ok ]

が、しかし、2つ目以降の仮想ブリッジでエラーになってしまいます。

[root@TALISKER] # /etc/init.d/net.br1forVPN start
 * Bringing up interface br1forVPN
 *   Creating bridge br1forVPN ...
 *   Adding ports to br1forVPN
 *     dummy1 ...
 *     Cannot add non-existent interface dummy1 to br1forVPN
 * ERROR: net.br1forVPN failed to start

そんなときは、モジュールを一回unloadして、 numdummies=<num> というオプションを指定してloadしてあげればいいらしいです。

[root@TALISKER] # modprobe -r dummy
[root@TALISKER] # modprobe dummy numdummies=2
[root@TALISKER] # /etc/init.d/net.br1forVPN start
 * Bringing up interface br1forVPN
 *   Destroying bridge br1forVPN ...                                      [ ok ]
 *   Creating bridge br1forVPN ...
 *   Adding ports to br1forVPN
 *     dummy1 ...                                                         [ ok ]
 *   172.30.2.1/23 ...                                                    [ ok ]

で、その設定は /etc/conf.d/modules に書いとけば次回起動から適用されるらしいです。
(Gentoo Linuxの場合)

[root@TALISKER] # tail -3 /etc/conf.d/modules
# Dummy NICs
modules="dummy"
module_dummy_args="numdummies=8"
6
7
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
7