# 確認 docker MACVLAN network 已經被正確建立 $ docker network ls NETWORK ID NAME DRIVER SCOPE a1c7b6f80389 bridge bridge local dc2f51e1056f host host local 8e9ae1c6629d my-macvlan-net macvlan local f28460d3a620 none
# 檢視 IP,跟上面看到的是相同的 $ docker exec -it my-macvlan-alpine ip addr show eth0 25: eth0@if2: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP link/ether 02:42:0a:67:13:02 brd ff:ff:ff:ff:ff:ff inet 10.103.19.2/24 brd 10.103.19.255 scope global eth0 valid_lft forever preferred_lft forever
# 檢視 routing information $ docker exec -it my-macvlan-alpine ip route default via 10.103.19.1 dev eth0 10.103.19.0/24 dev eth0 scope link src 10.103.19.2
# 測試對 gateway 的通訊 $ docker exec -it my-macvlan-alpine ping -c 2 10.103.19.1 PING 10.103.19.1 (10.103.19.1): 56 data bytes 64 bytes from 10.103.19.1: seq=0 ttl=64 time=0.309 ms 64 bytes from 10.103.19.1: seq=1 ttl=64 time=0.317 ms
--- 10.103.19.1 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.309/0.313/0.317 ms
# 測試連外通訊 & DNS resolution $ docker exec -it my-macvlan-alpine ping -c 2 www.google.com PING www.google.com (216.58.200.36): 56 data bytes 64 bytes from 216.58.200.36: seq=0 ttl=54 time=7.995 ms 64 bytes from 216.58.200.36: seq=1 ttl=54 time=7.876 ms
--- www.google.com ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 7.876/7.935/7.995 ms
# 檢視 docker network $ docker network ls NETWORK ID NAME DRIVER SCOPE e9a149acc74d bridge bridge local dc2f51e1056f host host local 3cf96bd7e0d1 my-8021q-1318-macvlan-net macvlan local ef98674855e0 my-macvlan-net macvlan local f28460d3a620 none null local
# 檢視 container IP 資訊,跟上面的詳細資訊相同 $ docker exec my-8021q-1318-macvlan-alpine ip addr show eth0 6: eth0@if5: <BROADCAST,MULTICAST,UP,LOWER_UP,M-DOWN> mtu 1500 qdisc noqueue state UP link/ether 02:42:0a:67:12:02 brd ff:ff:ff:ff:ff:ff inet 10.103.18.2/24 brd 10.103.18.255 scope global eth0 valid_lft forever preferred_lft forever
# 查詢 routing information $ docker exec my-8021q-1318-macvlan-alpine ip route default via 10.103.18.1 dev eth0 10.103.18.0/24 dev eth0 scope link src 10.103.18.2
# 測試與 gateway 的通訊 $ docker exec my-8021q-1318-macvlan-alpine ping -c 2 10.103.18.1 PING 10.103.18.1 (10.103.18.1): 56 data bytes 64 bytes from 10.103.18.1: seq=0 ttl=64 time=0.379 ms 64 bytes from 10.103.18.1: seq=1 ttl=64 time=0.290 ms
--- 10.103.18.1 ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 0.290/0.334/0.379 ms
# 測試對外通訊 & DNS resolution $ docker exec my-8021q-1318-macvlan-alpine ping -c 2 www.google.com PING www.google.com (172.217.160.68): 56 data bytes 64 bytes from 172.217.160.68: seq=0 ttl=54 time=7.284 ms 64 bytes from 172.217.160.68: seq=1 ttl=54 time=7.223 ms
--- www.google.com ping statistics --- 2 packets transmitted, 2 packets received, 0% packet loss round-trip min/avg/max = 7.223/7.253/7.284 ms