Linux에서 가상으로 IP 주소 중복 환경 구축

소개



Linux에서 brctlnetns를 사용하여 IP 주소가 중복된 호스트가 있는 환경을 가상으로 구축합니다.


필요한 것


  • 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가 올 경우 성공합니다.

    좋은 웹페이지 즐겨찾기