前言:
macvlan这里就不解释了,自行百度
开始:
首先输入ip addr
查看你网卡名称,群晖首先要去网络里开启openovs
V4创建macvlan
docker network create -d macvlan --subnet=10.10.10.0/24 --gateway=10.10.10.10 -o parent=ovs_eth0 zh
ovs_eth0自行替换自己网卡
V4+V6创建macvlan
docker network create -d macvlan --subnet=10.10.10.0/24 --gateway=10.10.10.10 --ipv6 --subnet=2008::/60 --gateway=2008::1 -o parent=ovs_eth0 macvaln
创建开机启动
nano /usr/local/lib/systemd/system/macvlan.service
[Unit]
Description=Macvlan shim to allow docker to route to host
# After=pkgctl-Docker.service
# BindsTo=pkgctl-Docker.service
ReloadPropagatedFrom=pkgctl-Docker.service
PartOf=pkgctl-Docker.service
[Service]
Type=oneshot
ExecStart=/bin/bash /usr/local/bin/macvlan_start.sh
ExecStop=/bin/bash /usr/local/bin/macvlan_stop.sh
RemainAfterExit=yes
Restart=no
[Install]
WantedBy=pkgctl-Docker.service
检查一下:
cat /usr/local/lib/systemd/system/macvlan.service
确认无误继续下一步
创建start脚本
vi /usr/local/bin/macvlan_start.sh
ip link add macvlan2 link ovs_eth0 type macvlan mode bridge
ip addr add 10.10.10.16 dev macvlan2
ip link set macvlan2 up
ip route add 自定义ip dev macvlan2
ip route add 自定义ip dev macvlan2
ip route add 自定义ip dev macvlan2
自定义ip填写你需要与宿主机通讯的ip.按需填写
创建stop脚本
vi /usr/local/bin/macvlan_stop.sh
ip route del 自定义ip dev macvlan2 || true
ip route del 自定义ip dev macvlan2 || true
ip link set macvlan2 down || true
ip addr del 10.10.10.16 dev macvlan2 || true
ip link del macvlan2 || true
自定义ip同上
然后我们重新加载一下systemd服务,并开机自启动
systemctl daemon-reload
systemctl enable macvlan
如果想取消开机自启动,执行
systemctl disable macvlan
systemctl start macvlan
systemctl stop mtacvlan
systemctl status macvlan
这三个命令,分别为立即启动服务、立即停止服务、查看服务运行状态。
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容