RouteOs安装容器+端口转发与回流
RouteOs安装容器
查看当前Device-Mode
/system/device-mode/ print
当在enterprise模式下,启用container模式
/system/device-mode/update container=yes
重启设备(这步要非常注意)
创建网络
为容器添加veth接口:
/interface/veth/add name=veth1 address=172.17.0.2/24 gateway=172.17.0.1
为容器创建一个桥并向其中添加 veth:
/interface/bridge/add name=containers
/ip/address/add address=172.17.0.1/24 interface=containers
/interface/bridge/port add bridge=containers interface=veth1
为传出流量设置 NAT:
/ip/firewall/nat/add chain=srcnat action=masquerade src-address=172.17.0.0/24
添加环境变量和挂载(可选)
为容器创建环境变量(可选):
/container/envs/add name=pihole_envs key=TZ value="Europe/Riga"
/container/envs/add name=pihole_envs key=WEBPASSWORD value="mysecurepassword"
/container/envs/add name=pihole_envs key=DNSMASQ_USER value="root"
定义安装(可选):
/container/mounts/add name=etc_pihole src=disk1/etc dst=/etc/pihole
/container/mounts/add name=dnsmasq_pihole src=disk1/etc-dnsmasq.d dst=/etc/dnsmasq.d
a) 从外部库获取图像
/container/config/set registry-url=https://registry-1.docker.io tmpdir=disk1/pull
拉取图像:
/container/add remote-image=pihole/pihole:latest interface=veth1 root-dir=disk1/pihole mounts=dnsmasq_pihole,etc_pihole envlist=pihole_envs
镜像会自动拉取并解压到根目录,可以使用以下命令查看状态
/container/print
b) 从PC导入图像:安装ddns-go
创建映射文件
/container/mounts/add name=ddns_dir src=/docker/ddns-go dst=/root
映射端口
/container/envs/add name=ddns_ev key=PORT value=9876
创建容器
/container/add file=ddns-go_x86_64.tar interface=veth1 envlist=ddns_ev root-dir=docker/images/ddns-go mounts=ddns_dir start-on-boot=yes logging=no
nat转发(重要)
/ip firewall nat add action=dst-nat chain=dstnat dst-address=10.10.9.253 dst-port=9876 protocol=tcp to-addresses=172.17.0.2 to-ports=9876
创建好启动容器 web输入http://10.10.9.253:9876
设置:
Token:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
设置:
Domains:xxx.xxx.xxx
安装docker仓库最新ddns-go
/container/add remote-image=jeessy/ddns-go:latest interface=veth1 envlist=ddns_ev root-dir=docker/images/ddns-go mounts=ddns_dir start-on-boot=yes logging=no
官网帮助地址:
https://help.mikrotik.com/docs/display/ROS/Container
RouteOs端口转发与回流
设置nat
外网映射:
/ip firewall nat add action=dst-nat chain=dstnat dst-port=9999 in-interface=pppoe-out3 protocol=tcp to-addresses=10.10.9.241 to-ports=5000
/ip firewall address-list add address=xxx.xxx.xxx list=ddns
内网映射:
/ip firewall nat add action=dst-nat chain=dstnat dst-address-list=ddns dst-port=9999 in-interface=LAN protocol=tcp to-addresses=10.10.9.241 to-ports=5000
回流:
/ip firewall nat add action=masquerade chain=srcnat src-address=10.10.9.0/24 dst-port=5000 out-interface=LAN protocol=tcp