> For the complete documentation index, see [llms.txt](https://kawsing.gitbook.io/opensystem/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://kawsing.gitbook.io/opensystem/docker-cong-an-zhuang-dao-ying-yong-ru-men-pian/macvlan.md).

# Macvlan

docker network create -d macvlan --subnet 192.168.43.0/24 --gateway 192.168.43.1 -o parent=enp3s0 -o macvlan\_mode=bridge macnet

```
docker network ls
NETWORK ID          NAME                DRIVER              SCOPE
1c6d5e747213        bridge              bridge              local
6328f6098a1e        host                host                local
f50c8d5017f4        macnet              macvlan             local
4d16bce25ff7        none                null                local
677c13cd8d77        xoops_vpcbr         bridge              local
```

MACVLAN 有以下特點：

* 可讓使用者在同一張實體網卡上設定多個 Layer 2 address (一般就是 MAC address)
* 承上，帶有上述設定的 MAC address 的網卡稱為 sub interface，而實體網卡則稱為 parent interface
* 可在 parent/sub interface 上設定的不只是 MAC address，IP address 同樣也是可以被設定
* sub interface 無法直接與 parent interface 通訊 (帶有 sub interface 的 VM or container 無法與 host 直接通訊)
* 若 VM or container 需要與 host 通訊，那就必須額外建立一個 sub interface 給 host 用
