tomo_stoneのメモ帳

ついったーに収まらないやつはこちら

Raspberry Piにブリッジインタフェースの設定をする

ラズパイにLinux Containers(LXC)を導入して遊び倒したい!

やったこと

  • ブリッジインタフェースの設定
  • ついでにGigabit Ethernet化(USB2.0に変換)

3B+だったら2つ目は不要とか言ってはいけない

LXCでブリッジインタフェースを使いたかったので、その準備をします。

調べた感じ、Debianも同じ手順でできそうです。

環境

インタフェースの切り替え

  • ついでといいつつ、先にUSBに接続したeth1インタフェースに切り替える作業
    • /etc/dhcpcd.conf
...
# eth0の設定をコメントアウトします
interface eth1
static ip_address=192.168.116.1/24 # IPアドレスの設定は適宜読み替えてください
static routers=192.168.116.254
static domain_name_servers=192.168.116.254 1.1.1.1
  • サービスの再起動
    • # systemctl restart networking

これで、eth1インタフェースで接続できることを確認できればOK。

ブリッジインタフェースの設定

  • bridge-utilsをインストールする

    • # apt install bridge-utils

  • /etc/network/interfaces

auto br0
iface br0 inet manual
        bridge_ports eth1
  • /etc/dhcpcd.conf
# 先ほどの設定をコメントアウトします
interface br0
denyinterfaces eth0 eth1
static ip_address=192.168.116.1/24
static routers=192.168.116.254
static domain_name_servers=192.168.116.254 1.1.1.1
  • サービスの再起動

    • # systemctl restart networking

  • br0インタフェースが有効になっているか確認

    • # brctl show
user@raspberrypi:~$ sudo brctl show
bridge name     bridge id               STP enabled     interfaces
br0             8000.1cc03501ac96       no              eth1

おまけ: スループット計測してみる

今回はiperfを使用しました(ノートPCをクライアントとして使用しています)。

user@raspberrypi:~$ iperf -c 192.168.116.1 -u -b 100M -t 10 -i 2
------------------------------------------------------------
Client connecting to 192.168.116.1, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  208 KByte (default)
------------------------------------------------------------
[  3] local 192.168.116.66 port 57261 connected with 192.168.116.1 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 2.0 sec  24.0 MBytes   101 Mbits/sec
[  3]  2.0- 4.0 sec  24.0 MBytes   101 Mbits/sec
[  3]  4.0- 6.0 sec  24.0 MBytes   101 Mbits/sec
[  3]  6.0- 8.0 sec  24.0 MBytes   101 Mbits/sec
[  3]  8.0-10.0 sec  24.0 MBytes   101 Mbits/sec
[  3]  0.0-10.0 sec   120 MBytes   101 Mbits/sec
[  3] Sent 85470 datagrams
[  3] Server Report:
[  3]  0.0-10.0 sec   114 MBytes  95.6 Mbits/sec   0.017 ms 4079/85469 (4.8%)
[  3]  0.0-10.0 sec  1 datagrams received out-of-order
user@raspberrypi:~$ iperf -c 192.168.116.1 -u -b 340M -t 10 -i 2
------------------------------------------------------------
lient connecting to 192.168.116.1, UDP port 5001
Sending 1470 byte datagrams
UDP buffer size:  208 KByte (default)
------------------------------------------------------------
[  3] local 192.168.116.66 port 39948 connected with 192.168.116.1 port 5001
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0- 2.0 sec  82.4 MBytes   345 Mbits/sec
[  3]  2.0- 4.0 sec  82.4 MBytes   346 Mbits/sec
[  3]  4.0- 6.0 sec  82.3 MBytes   345 Mbits/sec
[  3]  6.0- 8.0 sec  82.3 MBytes   345 Mbits/sec
[  3]  8.0-10.0 sec  82.4 MBytes   346 Mbits/sec
[  3]  0.0-10.0 sec   412 MBytes   345 Mbits/sec
[  3] Sent 293741 datagrams
[  3] Server Report:
[  3]  0.0-10.0 sec   391 MBytes   328 Mbits/sec   0.045 ms 15100/293740 (5.1%)
[  3]  0.0-10.0 sec  1 datagrams received out-of-order

結果は95.6Mbps → 328Mbps。 こちら(3B+)よりもいい結果がでました。

参考にしたページ

https://blog.ymyzk.com/2018/05/raspbian-9-stretch-bridge-interface/ https://www.jeffgeerling.com/blog/2018/raspberry-pi-3-b-review-and-performance-comparison