0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【2024年08月版】Linux 1台でブリッジ体験メモ【初学者向け、教育資料、namespace】

Last updated at Posted at 2024-08-31

はじめに

Linux の namespace機能を使ってブリッジを体験するメモ

初学者向け

Linux 1台でできるので、お手軽にブリッジの基礎を学べます

環境準備

  • Ubuntu22.04などのLinuxを1台準備します

手順

  • 3つのPCを同一のセグメント(10.11.12.0/24)に配置します
  • 3つのPC間でブリッジを経由してPingのやり取りができることを確認します
sudo ip --all netns delete

sudo ip netns add testns01
sudo ip netns add testns02
sudo ip netns add testns03
sudo ip netns add testbr01
sudo ip netns list
sudo ip link add testns01-veth0 type veth peer name testbr01-veth0
sudo ip link add testns02-veth0 type veth peer name testbr01-veth1
sudo ip link add testns03-veth0 type veth peer name testbr01-veth2
sudo ip link
sudo ip link set testns01-veth0 netns testns01
sudo ip link set testns02-veth0 netns testns02
sudo ip link set testns03-veth0 netns testns03
sudo ip link set testbr01-veth0 netns testbr01
sudo ip link set testbr01-veth1 netns testbr01
sudo ip link set testbr01-veth2 netns testbr01
sudo ip netns exec testns01 ip link
sudo ip netns exec testns02 ip link
sudo ip netns exec testns03 ip link
sudo ip netns exec testbr01 ip link
sudo ip netns exec testns01 ip a add 10.11.12.1/24 dev testns01-veth0
sudo ip netns exec testns02 ip a add 10.11.12.2/24 dev testns02-veth0
sudo ip netns exec testns03 ip a add 10.11.12.3/24 dev testns03-veth0
sudo ip netns exec testns01 ip link set testns01-veth0 up
sudo ip netns exec testns02 ip link set testns02-veth0 up
sudo ip netns exec testns03 ip link set testns03-veth0 up
sudo ip netns exec testbr01 ip link set testbr01-veth0 up
sudo ip netns exec testbr01 ip link set testbr01-veth1 up
sudo ip netns exec testbr01 ip link set testbr01-veth2 up
sudo ip netns exec testns01 ip link set lo up
sudo ip netns exec testns02 ip link set lo up
sudo ip netns exec testns03 ip link set lo up
sudo ip netns exec testbr01 ip link add dev br0 type bridge
sudo ip netns exec testbr01 ip link set br0 up
sudo ip netns exec testbr01 ip link set testbr01-veth0 master br0
sudo ip netns exec testbr01 ip link set testbr01-veth1 master br0
sudo ip netns exec testbr01 ip link set testbr01-veth2 master br0
sudo ip netns exec testns01 ping 10.11.12.2
sudo ip netns exec testns01 ping 10.11.12.3
sudo ip netns exec testns02 ping 10.11.12.1
sudo ip netns exec testns02 ping 10.11.12.3
sudo ip netns exec testns03 ping 10.11.12.1
sudo ip netns exec testns03 ping 10.11.12.2

さいごに

かんたんでしたね

関連リンク

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?