Docker 搭建 openwrt

警告
本文最后更新于 2022-11-23,文中内容可能已过时。

通过 Docker 搭建一个可用的 openwrt

安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
ip addr
sudo ip link set eno1 promisc on

sudo docker network create -d macvlan --subnet=192.168.3.0/24 --gateway=192.168.3.1 -o parent=eno1 macnet
docker network inspect  macnet

docker pull registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64

sudo docker run -d --restart always --name openwrt  --network macnet --privileged registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64 /sbin/init

sudo docker exec -it openwrt /bin/bash

vi /etc/config/network

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 'fd7d:334c:6108::/48'
        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.3.101'
        option gateway '192.168.3.1'
        option dns '192.168.3.1'
        option broadcast '192.168.3.255'

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

sudo docker restart openwrt

密码:password

宿主机与 Docker(openwrt) 无法通信

参考:在docker中运行openwrt #4

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
sudo ip link add link eno1 hMACvLAN type macvlan mode bridge
sudo ip addr add 192.168.3.100/24 brd + dev hMACvLAN ## 增加一个网卡
sudo ip link set hMACvLAN up

## 以下可能有错误 =======================
# #sudo ip route del default #删除默认路由
# sudo ip route add default via 192.168.3.105 dev hMACvLAN # 设置静态路由
# sudo echo "nameserver 192.168.3.1" > /etc/resolv.conf # 设置静态 dns 服务器
# ping  192.168.3.105

# # 或者使用 nmcli
# nmcli connection add type macvlan dev eno1 mode bridge ifname hMACvLAN autoconnect yes save yes

docker import https://downloads.openwrt.org/releases/19.07.0/targets/x86/64/openwrt-19.07.0-x86-64-generic-rootfs.tar.gz openwrt:19.07.0 sudo docker run -d
–restart unless-stopped
–network macvLan
–privileged registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64
–name openwrt
/sbin/init

sudo docker run –restart always –name openwrt –network macvLan –privileged registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64 /sbin/init

无法访问国内网址:

  1. dns 选择:pdnsd:208.67.222.222(Open DNS)
  2. https://github.com/coolsnowwolf/lede/issues/5520 关闭 “系统” -> “启动项” -> “19”(firewall 需要禁止)
  3. “网络” -> “接口” -> “防火墙” -> “区域”(需要全部选择接受)
  4. 然后在"自定义规则里面",填写 iptables -t nat -I POSTROUTING -j MASQUERADE
  5. 在 “服务” -> “PassWall” -> “模式” TCP默认模式: GFW 列表 UDP默认模式:GFW 列表 路由器TCP:GFW(这个GFW模式就可以) 路由器UDP:GFW(这个GFW模式就可以)

5.手机连接 a. IP 手动: IP地址:192.168.3.29(自己手机的固定IP) 子网掩码:255.255.255.0 路由器:192.168.3.101(需要和openwrt路由器一样) b. 配置DNS,需要先删除掉原来的 手动:192.168.3.101(需要和openwrt路由器一样)

William-Ubuntu 安装

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
ip add

## 如果原来有网卡,需要删除掉
sudo ifconfig hMACvLAN down
sudo ip link delete hMACvLAN

sudo ip link set enp0s31f6 promisc on

## 如果有,需要删掉
docker network ls
docker network rm macnet

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

docker run -d \
	--restart always \
	--name openwrt  \
	--network macnet \
	--privileged \
	registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64 \
	/sbin/init

docker exec -it openwrt /bin/bash

vi /etc/config/network

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 'fd7d:334c:6108::/48'
        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.101'  ## docker ip,可以打开监控界面
        option gateway '192.168.1.1'
        option dns '192.168.1.1'

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

docker restart openwrt

## 管理界面密码
密码:password

sudo ip link add link enp0s31f6 hMACvLAN type macvlan mode bridge
sudo ip addr add 192.168.1.100/24 brd + dev hMACvLAN ## 增加一个网卡
sudo ip link set hMACvLAN up

相关内容

william 支付宝支付宝
william 微信微信
0%