Preparation
Enable promiscuous mode for the network card
sudo ip link set enx00e04c6800fa promisc on
Create a macvlan network
docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=enx00e04c6800fa macnet
Pull the docker image
docker pull registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64
Configure docker
Run the docker container
docker run --restart always --name openwrt -d --network macnet --privileged registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64 /sbin/init
Enter the docker container to configure the network
docker exec -it openwrt bash
vim /etc/config/network
Change the settings for the LAN interface:
config interface 'lan'
option type 'bridge'
option ifname 'eth0'
option proto 'static'
option ipaddr '192.168.50.100'
option netmask '255.255.255.0'
option ip6assign '60'
option gateway '192.168.50.1'
option broadcast '192.168.50.255'
option dns '192.168.50.1'
Restart the network
/etc/init.d/network restart
Perform the setup
Address option ipaddr
Username: root
Password: password
Restore the host machine network
After running the Openwrt container, the host machine may not be able to connect to the external network. You need to modify the /etc/network/interfaces
file on the host machine.
cp /etc/network/interfaces /etc/network/interfaces.bak
vim /etc/network/interfaces
Add the following to the end of the file:
auto eth0
iface eth0 inet manual
auto macvlan
iface macvlan inet static
address 192.168.50.200
netmask 255.255.255.0
gateway 192.168.50.1
dns-nameservers 192.168.50.1
pre-up ip link add macvlan link eth0 type macvlan mode bridge
post-down ip link del macvlan link eth0 type macvlan mode bridge
References