3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Linux で仮想的に IP アドレス重複環境を構築する

Last updated at Posted at 2018-03-17

はじめに

Linux で brctlnetns を用いて、IPアドレスが重複したホストが存在する環境を仮想的に構築します。
dup.svg.png

必要なもの

  • brctl コマンド
    • Arch Linux なら pacman -S bridge-utils で入ります。

構築

仮想スイッチの作成

brctl addbr yabai

ip link set dev yabai up
ip a a 192.168.100.10/24 dev yabai

veth(仮想 LAN ケーブル)の作成

ip link add y-to-ns1 type veth peer name ns1-to-y
ip link add y-to-ns2 type veth peer name ns2-to-y

仮想ホストの作成

ip netns add ns1
ip netns add ns2

仮想配線

ip link set ns1-to-y netns ns1
ip link set ns2-to-y netns ns2

brctl addif yabai y-to-ns1
brctl addif yabai y-to-ns2

リンクアップ + IP アドレスの割当

ip link set dev y-to-ns1 up
ip link set dev y-to-ns2 up

ip netns exec ns1 ip link set dev ns1-to-y up
ip netns exec ns1 ip addr add 192.168.100.4/24 dev ns1-to-y

ip netns exec ns2 ip link set dev ns2-to-y up
ip netns exec ns2 ip addr add 192.168.100.4/24 dev ns2-to-y # dup!

コマンドまとめたやつ

brctl addbr yabai

ip link set dev yabai up
ip a a 192.168.100.10/24 dev yabai

ip link add y-to-ns1 type veth peer name ns1-to-y
ip link add y-to-ns2 type veth peer name ns2-to-y

ip netns add ns1
ip netns add ns2

ip link set ns1-to-y netns ns1
ip link set ns2-to-y netns ns2

brctl addif yabai y-to-ns1
brctl addif yabai y-to-ns2
ip link set dev y-to-ns1 up
ip link set dev y-to-ns2 up

ip netns exec ns1 ip link set dev ns1-to-y up
ip netns exec ns1 ip addr add 192.168.100.4/24 dev ns1-to-y

ip netns exec ns2 ip link set dev ns2-to-y up
ip netns exec ns2 ip addr add 192.168.100.4/24 dev ns2-to-y # dup!

検証

$ sudo arping -I yabai 192.168.100.4 -c 1
ARPING 192.168.100.4 from 192.168.100.10 yabai
Unicast reply from 192.168.100.4 [B2:37:33:07:94:33]  0.562ms
Unicast reply from 192.168.100.4 [A2:7E:B4:EC:B1:9D]  0.581ms
Sent 1 probes (1 broadcast(s))
Received 2 response(s)

異なる MAC アドレスのホストから Reply が来れば成功です。

3
2
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
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?