转载:CoreELEC Docker OpenWRT 配置
https://post.smzdm.com/p/a99v7vp5/
开启网卡混杂模式
ip link set eth0 promisc on
创建Macvlan复用网卡
用于虚拟主机接入局域网,这里的gateway和subnet根据自己的网段设置
docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=eth0 macnet
创建容器
创建名为openwrt的OpenWRT容器
docker run --name openwrt --restart always -d --network macnet --privileged itvro/openwrt-aarch64:latest /sbin/init
修改容器网络参数
创建成功后,启动容器的bash进行设置
CoreELEC:~ # docker exec -it openwrt /bin/bash
bash-5.1# vi /etc/config/network
将lan口网络参数按自己网络结构来设置
config interface 'loopback'
option ifname 'lo'
option proto 'static'
option ipaddr '127.0.0.1'
option netmask '255.0.0.0'
config globals 'globals'
option ula_prefix 'fdf7:b573:bfcc::/48'
config interface 'lan'
option ifname 'eth0'
option proto 'static'
option ipaddr '192.168.50.2'
option netmask '255.255.255.0'
option gateway '192.168.50.1'
option broadcast '192.168.50.255'
option dns '192.168.50.1'
option ip6assign '60'
option delegate '0'
config interface 'vpn0'
option ifname 'tun0'
option proto 'none'
停用防火墙
bash-5.1# /etc/init.d/firewall disable&&/etc/init.d/firewall stop
Warning: Section @defaults[0] requires unavailable target extension FLOWOFFLOAD, disabling
Warning: Section @zone[1] (wan) cannot resolve device of network 'wan'
Warning: Section @zone[1] (wan) cannot resolve device of network 'wan6'
Warning: Section @defaults[0] requires unavailable target extension FLOWOFFLOAD, disabling
Warning: Section @zone[1] (wan) has no device, network, subnet or extra options
* Flushing IPv4 filter table
* Flushing IPv4 nat table
* Flushing IPv4 mangle table
重启网络
bash-5.1# /etc/init.d/network restart
退出到CoreELEC环境
bash-5.1# exit
重启OpenWRT容器
CoreELEC:~ # docker restart openwrt
现在可以像正常硬路由一样,通过刚才配置的容器网络ip地址 192.168.50.2 访问并配置Docker中的OpenWRT了。
另外注:做旁路由的话还要添加自定义防火墙规则(网络->防火墙->自定义规则):
iptables -t nat -I POSTROUTING -o eth0 -j MASQUERADE
也可以尝试(有桥接存在的情况下)
iptables -t nat -I POSTROUTING -o br-lan -j MASQUERADE
一个文件搞掂互通和固定IP方法
https://www.right.com.cn/forum/thread-1253259-1-1.html
恩山 ltuxer
vi ~/.config/autostart.sh
#!/bin/sh
ifconfig eth0 promisc
/opt/sbin/ip addr flush dev eth0
/opt/sbin/ip link add macvlan link eth0 type macvlan mode bridge
/opt/sbin/ip link set macvlan up
/opt/sbin/ip route del 192.168.1.0/24 dev eth0
/opt/sbin/ip route del default
/opt/sbin/ip route add 192.168.1.0/24 dev macvlan
/opt/sbin/ip route add default via 192.168.31.X dev macvlan #自行替换网关
connmanctl services | grep -i $(ifconfig macvlan|grep HW|awk -F: '{print $7}')|awk '{system("connmanctl config "$3" --ipv4 manual #IP地址# 255.255.255.0 #网关# --nameservers #DNS地址#")}'#自行替换CE的IP
然后按esc键 输入:wq
chmod a+x ~/.config/autostart.sh
其他参考:https://leeyr.com/326.html
版权声明:
作者:Jays
链接:https://ijays.com/2021/09/coreelec-9-2-2-docker-openwrt.html
来源:颓废的美
文章版权归作者所有,未经允许请勿转载。
THE END
二维码
共有 0 条评论