1、宿主机开启混杂模式 1 ip link set eth0 promisc on
2、创建macvlan 开启ipv6 1 2 3 4 5 6 7 8 docker network create -d macvlan \ --subnet=192.168.2.0/24 \ --gateway=192.168.2.199 \ --subnet=2409:8a5c:492:f704::/64 \ --gateway=2409:8a5c:492:f704::1 \ -o parent=eth0 \ openwrt
3、 使用 nmcli 创建macvlan子接口 nmcli 是 NetworkManager 的命令行工具,可以用来创建和管理网络接口。以下是创建 macvlan 子接口的步骤:
1 2 3 4 5 6 7 8 9 nmcli connection add type macvlan con-name mymacvlan ifname mymacvlan dev eth0 mode bridge nmcli connection up mymacvlan nmcli connection modify mymacvlan ipv4.addresses 192.168.2.251/24 nmcli connection modify mymacvlan ipv4.method manual
验证 macvlan 子接口
使用 nmcli 命令为 mymacvlan 连接添加静态路由 其中,192.168.2.250是容器的IP地址
1 nmcli connection modify mymacvlan +ipv4.routes "192.168.2.250/32"
重新启动连接:如果已经启用了连接,需要重新启动该连接以使路由生效:
1 2 nmcli connection down mymacvlan nmcli connection up mymacvlan
验证路由 你可以使用以下命令来验证路由是否已成功添加:
测试通信
4、导入openwrt的docker镜像 1 docker import openwrt-x86-64-generic-rootfs.tar.gz openwrt
5、查看docker镜像
6、启动openwrt 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 version: '3.3' # 你可以根据需要选择合适的版本 services: openwrt: image: openwrt:latest container_name: openwrt networks: openwrt: ipv4_address: 192.168.2.250 privileged: true restart: unless-stopped command: /sbin/init networks: openwrt: external: true # 确保 openwrt 网络是外部网络,如果是内部网络则改为 false
armbian最新配置IP 1、创建macvlan
1 2 3 4 5 docker network create -d macvlan \ --subnet=192.168.1.0/24 \ --gateway=192.168.1.1 \ -o parent=eth0 \ openwrt
2、 nano /etc/rc.local
1 2 3 4 5 6 ip link set eth0 promisc on > /dev/null 2>&1 ip link add macvlan0 link eth0 type macvlan mode bridge ip addr add 192.168.1.252 dev macvlan0 ip link set macvlan0 up ip route add 192.168.1.250 dev macvlan0 route add default gw 192.168.1.250 macvlan0
3、
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 cat > /etc/systemd/system/rc-local.service <<EOF [Unit] Description=/etc/rc.local Compatibility ConditionPathExists=/etc/rc.local After=network.target [Service] Type=forking ExecStart=/etc/rc.local start TimeoutSec=0 StandardOutput=tty RemainAfterExit=yes SysVStartPriority=99 [Install] WantedBy=multi-user.target EOF systemctl daemon-reload systemctl enable --now rc-local.service