docker網絡學習-macvlan

主要參考天天5分鐘玩轉docker容器技術博客。
記錄下本身的實驗過程。
若是想學習,請直接參考該博客http://www.cnblogs.com/CloudMan6/

實驗環境準備

咱們使用host2與host3上單獨的網卡enp0s8建立macvlan。
爲保證多個 MAC 地址的網絡包均可以從 enp0s9 經過,咱們須要打開網卡的混雜模式。
混雜模式簡介
clipboard.pngdocker

首先在/etc/network/interfaces文件中添加以下內容網絡

auto enp0s8
iface enp0s8 inet dhcp

確認網卡PROMISC已經生效,且網卡up學習

root@host2:~# ip link set enp0s8 promisc on
root@host2:~# /etc/init.d/networking restart
[ ok ] Restarting networking (via systemctl): networking.service.
root@host2:~# ip a |grep -A3 enp0s8
3: enp0s8: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether 08:00:27:43:fd:30 brd ff:ff:ff:ff:ff:ff
    inet 192.168.56.101/24 brd 192.168.56.255 scope global enp0s8
       valid_lft forever preferred_lft forever
    inet6 fe80::a00:27ff:fe43:fd30/64 scope link 
       valid_lft forever preferred_lft forever

建立macvlan網絡

在host2host3上執行下面的語句spa

root@host2:~# docker network create -d macvlan \
>                    --subnet=172.16.86.0/24   \
>                    --gateway=172.16.86.1     \
>                    -o parent=enp0s8 mac_net1
9e831209515c38d091f7fc10265fed7f995f49ec6acd9cb22c7b2c83c5819d97

在host2運行容器bbox1 並鏈接至mac_net13d

root@host2:~# docker run -itd --name bbox1 --ip=172.16.86.10 --network mac_net1 busybox
06d1244098d1d0a8eac41cdc8505d6f145b86b55161603014c2247bd84cae939

在host3中運行bbox2, 並鏈接至mac_net2rest

root@host3:~# docker run -itd --name bbox2 --ip=172.16.86.11 --network mac_net1 busybox
b033f3ad107eeb18e93f130bd1add171874b9ad54325f5d24ff58ac79cac183d

爲了不自動分配形成ip衝突,建立時最好指定ipcode

驗證連通性

root@host2:~# docker exec -it bbox1 ping -c 2 172.16.86.10
PING 172.16.86.10 (172.16.86.10): 56 data bytes
64 bytes from 172.16.86.10: seq=0 ttl=64 time=0.108 ms
^C
--- 172.16.86.10 ping statistics ---
1 packets transmitted, 1 packets received, 0% packet loss
round-trip min/avg/max = 0.108/0.108/0.108 ms
root@host2:~# docker exec -it bbox1 ping -c 2 172.16.86.11
PING 172.16.86.11 (172.16.86.11): 56 data bytes
64 bytes from 172.16.86.11: seq=0 ttl=64 time=1.345 ms
64 bytes from 172.16.86.11: seq=1 ttl=64 time=1.116 ms

--- 172.16.86.11 ping statistics ---
2 packets transmitted, 2 packets received, 0% packet loss
round-trip min/avg/max = 1.116/1.230/1.345 ms

可是沒法解析主機名blog

相關文章
相關標籤/搜索