0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Linux Network Namespace(その2:VLAN, Trunk Port)

Posted at

Network NamespaceでVLANやTrunk Portを実現

実現したいネットワークは単純なもの、下記である。

image.png

L2Switch間のポートはTrunkポート(タグVLAN)、末端のPCと接続されるL2SwitchのポートはAccessポート。上側はVLAN10ネットワーク、下側がVLAN20ネットワークである。

検証

その1

下記図において、ns1というNamespaceのns1-veth.10は同じns1に属するns1-vethのサブインターフェースであり(正確な言い方かどうか不明)、VLAN10に所属するPCが接続されている。その他も同様の考え方である。また、1st space(ログイン後のシェルが起動している空間)にて、veth1とveth2とはブリッジ化されている。

image.png

$ sudo ip netns add ns1
$ sudo ip link add name veth1 type veth peer name ns1-veth
$ sudo ip link set ns1-veth netns ns1
$ sudo ip link set veth1 up
$ sudo ip netns exec ns1 ip link set ns1-veth up
$ sudo ip netns exec ns1 ip link set lo up
  • Namespaceであるns1作成
  • 仮想ネットワークインターフェースPairであるveth1およびns1-veth作成
  • ns1-vethをns1に配置
  • veth1、ns1:ns1-veth、ns1:loをUp
$ sudo ip netns add ns2
$ sudo ip link add name veth2 type veth peer name ns2-veth
$ sudo ip link set ns2-veth netns ns2
$ sudo ip link set veth2 up
$ sudo ip netns exec ns2 ip link set ns2-veth up
$ sudo ip netns exec ns2 ip link set lo up

ns2にて、先ほどと同様。

sudo ip netns exec ns1 ip link add link ns1-veth name ns1-veth.10 type vlan id 10
sudo ip netns exec ns1 ip link add link ns1-veth name ns1-veth.20 type vlan id 20
sudo ip netns exec ns1 ip link set ns1-veth.10 up
sudo ip netns exec ns1 ip link set ns1-veth.20 up
  • ns1にてサブインターフェース(?)作成およびUp
    • ns1-veth.10:VLAN10
    • ns1-veth.20:VLAN20
sudo ip netns exec ns2 ip link add link ns2-veth name ns2-veth.10 type vlan id 10
sudo ip netns exec ns2 ip link add link ns2-veth name ns2-veth.20 type vlan id 20
sudo ip netns exec ns2 ip link set ns2-veth.10 up
sudo ip netns exec ns2 ip link set ns2-veth.20 up

ns2にて、先ほどと同様。

sudo ip netns exec ns1 ip addr add 10.1.10.1/24 dev ns1-veth.10
sudo ip netns exec ns1 ip addr add 10.1.20.1/24 dev ns1-veth.20
sudo ip netns exec ns2 ip addr add 10.1.10.2/24 dev ns2-veth.10
sudo ip netns exec ns2 ip addr add 10.1.20.2/24 dev ns2-veth.20
  • サブインターフェースにIPアドレスアサイン
sudo ip link add name swbr type bridge vlan_filtering 1
sudo ip link set swbr up
sudo ip link set veth1 master swbr
sudo ip link set veth2 master swbr
sudo bridge vlan add vid 10 dev veth1
sudo bridge vlan add vid 20 dev veth1
sudo bridge vlan add vid 10 dev veth2
sudo bridge vlan add vid 20 dev veth2
  • ブリッジswbr作成およびUp
  • swbrにオリジナルspace(1st space:ログイン後のシェルが動作している空間)のveth1およびveth2追加
  • veth1にVLAN10およびVLAN20を追加(トランクポートになる)
  • veth2にVLAN10およびVLAN20を追加(トランクポートになる)

ここからは、設定状況を確認。ブリッジの状況は下記となる。

$ bridge vlan
port              vlan-id  
veth1             1 PVID Egress Untagged
                  10
                  20
veth2             1 PVID Egress Untagged
                  10
                  20
swbr              1 PVID Egress Untagged

$ brctl show
bridge name	bridge id		STP enabled	interfaces
swbr		8000.d243a61a6a71	no		veth1
										veth2

オリジナルSpaceのインターフェースveth1およびveth2がトランク化されている。次に、作成したNamespaceであるns1の状況確認。

$ sudo ip netns exec ns1 ip -d link show ns1-veth.10
2: ns1-veth.10@ns1-veth: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 8e:47:5c:06:83:6c brd ff:ff:ff:ff:ff:ff promiscuity 0  allmulti 0 minmtu 0 maxmtu 65535 
    vlan protocol 802.1Q id 10 <REORDER_HDR> addrgenmode eui64 numtxqueues 1 numrxqueues 1 gso_max_size 65536 gso_max_segs 65535 tso_max_size 524280 tso_max_segs 65535 gro_max_size 65536

サブインターフェースns1-veth.10では、802.1Qが見えており、トランク化されているかと思った。しかし、ns1からns2へpingを実行してみる(VLAN10内)。

$ sudo ip netns exec ns1 ping 10.1.10.2 -c 1
PING 10.1.10.2 (10.1.10.2) 56(84) bytes of data.
64 bytes from 10.1.10.2: icmp_seq=1 ttl=64 time=0.057 ms

当然、疎通はある。この時のns1-veth.10に対するtcpdumpの結果は下記となる。

$ sudo ip netns exec ns1 tcpdump -nel -i ns1-veth.10

20:24:45.001391 8e:47:5c:06:83:6c > 32:c7:9a:bf:0a:62, ethertype IPv4 (0x0800), length 98: 10.1.10.1 > 10.1.10.2: ICMP echo request, id 2663, seq 1, length 64
20:24:45.001433 32:c7:9a:bf:0a:62 > 8e:47:5c:06:83:6c, ethertype IPv4 (0x0800), length 98: 10.1.10.2 > 10.1.10.1: ICMP echo reply, id 2663, seq 1, length 64

タグ化されていない(802.1Qが見えない)。veth1およびns1-vethの結果は下記なる。

$ sudo tcpdump -nel -i veth1

20:22:23.689505 8e:47:5c:06:83:6c > 32:c7:9a:bf:0a:62, ethertype 802.1Q (0x8100), length 102: vlan 10, p 0, ethertype IPv4 (0x0800), 10.1.10.1 > 10.1.10.2: ICMP echo request, id 2652, seq 1, length 64
20:22:23.689546 32:c7:9a:bf:0a:62 > 8e:47:5c:06:83:6c, ethertype 802.1Q (0x8100), length 102: vlan 10, p 0, ethertype IPv4 (0x0800), 10.1.10.2 > 10.1.10.1: ICMP echo reply, id 2652, seq 1, length 64

$ sudo ip netns exec ns1 tcpdump -nel -i ns1-veth

20:37:43.350497 8e:47:5c:06:83:6c > 32:c7:9a:bf:0a:62, ethertype 802.1Q (0x8100), length 102: vlan 10, p 0, ethertype IPv4 (0x0800), 10.1.10.1 > 10.1.10.2: ICMP echo request, id 2620, seq 1, length 64
20:37:43.350541 32:c7:9a:bf:0a:62 > 8e:47:5c:06:83:6c, ethertype 802.1Q (0x8100), length 102: vlan 10, p 0, ethertype IPv4 (0x0800), 10.1.10.2 > 10.1.10.1: ICMP echo reply, id 2620, seq 1, length 64

こちらは、802.1Qが見えており、タグ化されていることがわかる。先ほどの、ns1-veth.10の詳細状況にて、802.1Qが見えていた理由は不明。

その2

異なるネットワーク構成を試してみた。

image.png

設定状況を説明。

sudo ip netns add ns1
sudo ip link add name veth1 type veth peer name ns1-veth
sudo ip link set ns1-veth netns ns1
sudo ip link set veth1 up
sudo ip netns exec ns1 ip link set ns1-veth up
sudo ip netns exec ns1 ip link set lo up
sudo ip netns exec ns1 ip addr add 10.1.10.1/24 dev ns1-veth
  • Namespaceであるns1作成
  • 仮想ネットワークインターフェースPairであるveth1およびns1-veth作成
  • ns1-vethをns1に配置
  • veth1、ns1:ns1-veth、ns1:loをUp
  • ns1:ns1-vethにIPアドレスアサイン
sudo ip netns add ns2
sudo ip link add name veth2 type veth peer name ns2-veth
sudo ip link set ns2-veth netns ns2
sudo ip link set veth2 up
sudo ip netns exec ns2 ip link set ns2-veth up
sudo ip netns exec ns2 ip link set lo up
sudo ip netns exec ns2 ip addr add 10.1.20.1/24 dev ns2-veth

ns2にて、先ほどと同様。

sudo ip netns add ns3
sudo ip link add name veth3 type veth peer name ns3-veth
sudo ip link set ns3-veth netns ns3
sudo ip link set veth3 up
sudo ip netns exec ns3 ip link set ns3-veth up
sudo ip netns exec ns3 ip link set lo up
sudo ip netns exec ns3 ip addr add 10.1.10.2/24 dev ns3-veth

ns3にて、先ほどと同様。

sudo ip netns add ns4
sudo ip link add name veth4 type veth peer name ns4-veth
sudo ip link set ns4-veth netns ns4
sudo ip link set veth4 up
sudo ip netns exec ns4 ip link set ns4-veth up
sudo ip netns exec ns4 ip link set lo up
sudo ip netns exec ns4 ip addr add 10.1.20.2/24 dev ns4-veth

ns4にて、先ほどと同様。

sudo ip link add name veth00 type veth peer name veth01
sudo ip link set veth00 up
sudo ip link set veth01 up
  • オリジナルSpaceにインターフェースペアveth00およびveth01作成
  • それらをUp
sudo ip link add name br1 type bridge vlan_filtering 1
sudo ip link set br1 up
sudo ip link add name br2 type bridge vlan_filtering 1
sudo ip link set br2 up
  • オリジナルSpaceにブリッジbr1およびbr2作成
sudo ip link set veth1 master br1
sudo ip link set veth2 master br1
sudo ip link set veth00 master br1
sudo bridge vlan add vid 10 dev veth1 pvid untagged
sudo bridge vlan add vid 20 dev veth2 pvid untagged
sudo bridge vlan add vid 10 dev veth00
sudo bridge vlan add vid 20 dev veth00
  • ブリッジbr1にveth1、veth2、veth00を加える
  • veth1をVLAN10アクセスポート化
  • veth2をVLAN20アクセスポート化
  • veth00にVLAN10およびVLAN20を属させトランクポート化
sudo ip link set veth3 master br2
sudo ip link set veth4 master br2
sudo ip link set veth01 master br2
sudo bridge vlan add vid 10 dev veth3 pvid untagged
sudo bridge vlan add vid 20 dev veth4 pvid untagged
sudo bridge vlan add vid 10 dev veth01
sudo bridge vlan add vid 20 dev veth01
  • ブリッジbr2にveth3、veth4、veth01を加える
  • veth3をVLAN10アクセスポート化
  • veth4をVLAN20アクセスポート化
  • veth01にVLAN10およびVLAN20を属させトランクポート化

ここからは、設定状況を確認。ブリッジの状況は下記となる。

$ bridge vlan
port              vlan-id  
veth1             1 Egress Untagged
                  10 PVID Egress Untagged
veth2             1 Egress Untagged
                  20 PVID Egress Untagged
veth3             1 Egress Untagged
                  10 PVID Egress Untagged
veth4             1 Egress Untagged
                  20 PVID Egress Untagged
veth01            1 PVID Egress Untagged
                  10
                  20
veth00            1 PVID Egress Untagged
                  10
                  20
br1               1 PVID Egress Untagged
br2               1 PVID Egress Untagged

$ brctl show
bridge name	bridge id		STP enabled	interfaces
br1		8000.ce9c3a25f04b	no		veth00
							veth1
							veth2
br2		8000.2a91e1a7e127	no		veth01
							veth3
							veth4

こちらの方が、アクセスポートおよびトランクポートの状況がわかりやすい。作成したNamespaceであるns1の状況確認。

$ sudo ip netns exec ns1 ip -d link show ns1-veth
4: ns1-veth@if5: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether 8e:47:5c:06:83:6c brd ff:ff:ff:ff:ff:ff link-netnsid 0 promiscuity 0  allmulti 0 minmtu 68 maxmtu 65535 
    veth addrgenmode eui64 numtxqueues 4 numrxqueues 4 gso_max_size 65536 gso_max_segs 65535 tso_max_size 524280 tso_max_segs 65535 gro_max_size 65536

802.1Qは見えず、トランク化されていない。オリジナルSpaceの状況も確認。

$ ip -d link show dev veth1
5: veth1@if4: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br1 state UP mode DEFAULT group default qlen 1000
    link/ether 2a:26:11:57:7f:ab brd ff:ff:ff:ff:ff:ff link-netns ns1 promiscuity 1  allmulti 1 minmtu 68 maxmtu 65535 
    veth 
    bridge_slave ....
    
$ ip -d link show veth00
13: veth00@veth01: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue master br1 state UP mode DEFAULT group default qlen 1000
    link/ether 56:6f:f1:0f:03:e1 brd ff:ff:ff:ff:ff:ff promiscuity 1  allmulti 1 minmtu 68 maxmtu 65535 
    veth 
    bridge_slave state ...

トランク化されているはずだが、802.1Qが見えない。ブリッジも見てみる。

$ ip -d link show dev br1
14: br1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP mode DEFAULT group default qlen 1000
    link/ether ce:9c:3a:25:f0:4b brd ff:ff:ff:ff:ff:ff promiscuity 0  allmulti 0 minmtu 68 maxmtu 65535 
    bridge forward_delay 1500 hello_time 200 max_age 2000 ageing_time 30000 stp_state 0 priority 32768 vlan_filtering 1 vlan_protocol 802.1Q bridge_id 8000.ce:9c:3a:25:f0:4b  ....

こちらには、802.1Qが見え、トランク化されていることがわかる。

pingを実行。

$ sudo ip netns exec ns1 ping 10.1.10.2 -c 1
PING 10.1.10.2 (10.1.10.2) 56(84) bytes of data.
64 bytes from 10.1.10.2: icmp_seq=1 ttl=64 time=0.062 ms

この時の、ns1のインターフェースns1-vethのtcpdumpの結果は下記となる。

$ sudo ip netns exec ns1 tcpdump -nel -i ns1-veth

20:45:46.902448 8e:47:5c:06:83:6c > f2:4a:62:38:1e:ce, ethertype IPv4 (0x0800), length 98: 10.1.10.1 > 10.1.10.2: ICMP echo request, id 2738, seq 1, length 64
20:45:46.902524 f2:4a:62:38:1e:ce > 8e:47:5c:06:83:6c, ethertype IPv4 (0x0800), length 98: 10.1.10.2 > 10.1.10.1: ICMP echo reply, id 2738, seq 1, length 64

タグ化されていない(アクセスポート)。次に、オリジナルSpaceのインターフェース見てみる。

$ sudo tcpdump -nel -i veth1

20:05:54.109535 8e:47:5c:06:83:6c > f2:4a:62:38:1e:ce, ethertype IPv4 (0x0800), length 98: 10.1.10.1 > 10.1.10.2: ICMP echo request, id 2743, seq 1, length 64
20:05:54.109582 f2:4a:62:38:1e:ce > 8e:47:5c:06:83:6c, ethertype IPv4 (0x0800), length 98: 10.1.10.2 > 10.1.10.1: ICMP echo reply, id 2743, seq 1, length 64

veth1はアクセスポートなので、802.1Qが見えない。

$ sudo tcpdump -nel -i veth00

20:07:42.360702 8e:47:5c:06:83:6c > f2:4a:62:38:1e:ce, ethertype 802.1Q (0x8100), length 102: vlan 10, p 0, ethertype IPv4 (0x0800), 10.1.10.1 > 10.1.10.2: ICMP echo request, id 2752, seq 1, length 64
20:07:42.360729 f2:4a:62:38:1e:ce > 8e:47:5c:06:83:6c, ethertype 802.1Q (0x8100), length 102: vlan 10, p 0, ethertype IPv4 (0x0800), 10.1.10.2 > 10.1.10.1: ICMP echo reply, id 2752, seq 1, length 64

veth00はトランクポートなので、802.1Qが見える。

終わりに

Namespaceの作り方次第と感じた。多少難しさも感じる。しばらく、このネタ続けてみる。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?