软路由

docker + openwrt

docker 设置

1
2
3
docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=enp0s31f6 macnet

docker run --restart=always --name openwrt -d --network macnet --privileged sulinggg/openwrt:amd64 /sbin/init

docker container 配置

进入 docker container openwrt

1
docker exec -it openwrt bash

修改 container 网络配置

1
vim /etc/config/network

新配置内容

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
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 packet_steering '1'

config interface 'lan'
        option type 'bridge'
        option ifname 'eth0'
        option proto 'static'
        option netmask '255.255.255.0'
        option ip6assign '60'
        option ipaddr '192.168.1.214' #改掉部分
        option gateway '192.168.1.1'  #改掉部分
        option dns '192.168.1.1'      #改掉部分

config interface 'vpn0'
        option ifname 'tun0'
        option proto 'none'

重启 container 网络服务

1
/etc/init.d/network restart

openwrt 软件配置(openwrt container 内部)

访问: http://192.168.1.214 进入控制面板

用户:root 密码:password 参考教程说明

  1. 关闭 dhcp 服务

    在 “网络 - 接口 - Lan - 修改” 界面中,勾选下方的 “忽略此接口(不在此接口提供 DHCP 服务)”,并“保存&应用”。
    

    注: dhcp 由主路由提供

主路由设置(可选)

配置主路由的 dhcp 服务

好处:自动分配 ip 或 连接软路由

  1. gateway: 192.168.1.214
  2. dns: 192.168.1.214
手动配置

在确实需要连接的机器

手动配置连接网络:

  1. gateway: 同上
  2. dns: 同上