有 Docker 真的是啥都能折腾。(仔细看,不要直接复制,照着自己的环境改)
我选用的 Docker 镜像是 sulinggg/openwrt 的 ImmortalWrt。
准备
首先拉取镜像,根据自己的平台架构拉取,我的是 X86_64 的。
docker pull sulinggg/openwrt:x86_64
部署
查看网卡名称。
┌─[root@localhost] - [~] - [Fri Sep 30, 08:46]
└─[$] <> ifconfig
docker0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.17.0.1 netmask 255.255.0.0 broadcast 172.17.255.255
inet6 fe80::42:78ff:fe46:263f prefixlen 64 scopeid 0x20<link>
ether 02:42:78:46:26:3f txqueuelen 0 (Ethernet)
RX packets 2212 bytes 4100392 (3.9 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 1758 bytes 829257 (809.8 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
enp1s0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.123.198 netmask 255.255.255.0 broadcast 192.168.123.255
inet6 fe80::34ae:47fd:f56c:36aa prefixlen 64 scopeid 0x20<link>
ether 00:30:18:3a:8f:ac txqueuelen 1000 (Ethernet)
RX packets 19636534 bytes 19112505605 (17.7 GiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 18636903 bytes 16436142391 (15.3 GiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 6568 bytes 3475043 (3.3 MiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 6568 bytes 3475043 (3.3 MiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
我的网卡名称是 enp1s0,每个人的可能不一样,你的可能是eth0。
根据你的主路由网段和网卡名称,创建 Macvlan 网络。我的网段是 192.168.123.0/24 ,网关是 192.168.123.1 ,网卡名称是 enp1s0。
docker network create -d macvlan --subnet=192.168.XXX.0/24 --gateway=192.168.XXX.1 -o parent=网卡名称 macnet
创建完成网卡后就可以启动容器了
docker run --restart always --name openwrt -d --network macnet --privileged sulinggg/openwrt:x86_64 /sbin/init
进入容器控制终端
docker exec -it openwrt bash
修改openwrt网络
vim /etc/config/network
其中 option ipaddr '改成192.168.XXX.2'
option gateway '改成192.168.XXX.1'
option dns '改成192.168.XXX.1'
重启网卡
/etc/init.d/network restart
然后就可以访问 openwrt 了
如果无法上网,关闭主路由的offload TCP/UDP for WLAN