docker_network
Xplorist Lv6

docker_network

reference site

command line

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
ip link add link enp6s0 name enp6s0.100 type vlan id 100
ip link add link enp6s0 name enp6s0.200 type vlan id 200

ip link add link enp6s0 name enp6s0.300 type macvlan id 300 mode bridge
ip addr add 192.168.1.0/24 brd + dev enp6s0.300

ip link set enp6s0.100 up
ip link set enp6s0.200 up
ip link set enp6s0.300 up

docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=enp0s8.100 -o macvlan_mode=bridge openwrt-LAN
docker network create -d macvlan --subnet=192.168.1.0/24 --gateway=192.168.1.1 -o parent=enp0s8.200 -o macvlan_mode=bridge openwrt-WAN

ip route del default
ip route add default via 172.16.60.1 dev vLAN
ip route add 10.10.3.0/24 via 192.168.1.6 dev enp6s0.300


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 link set ens33 promisc on
ip link set ens34 promisc on

modprobe pppoe

docker network create -d macvlan --subnet=172.16.60.0/24 --gateway=172.16.60.254 --ipv6 --subnet=fe80::/16 --gateway=fe80::1 -o parent=ens33 -o macvlan_mode=bridge openwrt-LAN

docker network create -d macvlan --subnet=192.168.0.0/24 --gateway=192.168.0.254 --ipv6 --subnet=fe81::/16 --gateway=fe81::1 -o parent=ens34 -o macvlan_mode=bridge openwrt-WAN

docker import openwrt-x86-64-generic-rootfs.tar.gz lean_openwrt

docker run -it -d --restart always --network openwrt-LAN --privileged --name openwrt lean_openwrt /sbin/init

docker network connect openwrt-WAN openwrt

docker exec -it openwrt /bin/sh

vi /etc/config/network

config interface 'lan'
option type 'bridge'
option ifname 'eth0'
option proto 'static'
option ipaddr '172.16.60.1'
option netmask '255.255.255.0'
option ip6assign '64'

config interface 'wan'
option ifname 'eth1'
option proto 'dhcp'
option ip6assign '64'

/etc/init.d/network restart

ip link add link ens33 vLAN type macvlan mode bridge
ip addr add 172.16.60.253/24 brd + dev vLAN
ip link set vLAN up
ip route del default
ip route add default via 172.16.60.1 dev vLAN

#设置宿主机的dns服务器为OpenWRT
echo "nameserver 172.16.60.1" > /etc/resolv.conf

test

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
60
# 下载镜像
$ docker pull crazygit/lean-openwrt-x86-64

# 查看镜像信息
$ docker run --rm crazygit/lean-openwrt-x86-64 cat /etc/banner
_______ ________ __
| |.-----.-----.-----.| | | |.----.| |_
| - || _ | -__| || | | || _|| _|
|_______|| __|_____|__|__||________||__| |____|
|__| W I R E L E S S F R E E D O M
-----------------------------------------------------
OpenWrt 19.07.2, r10947-65030d81f3
-----------------------------------------------------

$ ifconfig

$ docker network create -d macvlan --subnet=192.168.2.0/24 --gateway=192.168.2.1 -o parent=enp6s0 openwrt-LAN

# 查看创建的虚拟网络
$ docker network ls |grep openwrt-LAN
21dcddacc389 openwrt-LAN macvlan local

# --network使用第4步创建的虚拟网络
$ docker run --restart always --name openwrt -d --network openwrt-LAN --privileged crazygit/lean-openwrt-x86-64

# 查看启动的容器
$ docker ps -a

$ docker exec -it openwrt /bin/sh
$ vi /etc/config/network

config interface 'lan'
option type 'bridge'
option ifname 'eth0'
option proto 'static'
option ipaddr '192.168.2.6'
option netmask '255.255.255.0'
option gateway '192.168.2.1'
option dns '192.168.2.1'
option broadcast '192.168.2.255'
option ip6assign '60'

$ /etc/init.d/network restart

ip link add link enp6s0 vLAN type macvlan mode bridge
ip addr add 192.168.2.7/24 brd + dev vLAN
ip link set vLAN up

ip route replace default via 192.168.2.6 dev vLAN

ip route del default
ip route add default via 192.168.2.6 dev vLAN

ip route replace default via 192.168.2.1 dev enp6s0

default via 192.168.2.1 dev enp6s0 onlink

#设置宿主机的dns服务器为OpenWRT
echo "nameserver 192.168.1.6" > /etc/resolv.conf

 评论