banner
绘素

绘素的Blog

twitter
github
email

dockerを使用してopenwrtをゲートウェイとしてインストールする

前期準備#

ネットワークカードのプロミスキャスモードを有効にする

sudo ip link set enx00e04c6800fa promisc on

macvlan ネットワークを作成する

docker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=enx00e04c6800fa macnet

Docker をプルする

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

Docker の設定#

Docker を実行する

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

Docker にネットワークを設定する

docker exec -it openwrt bash
vim /etc/config/network

Lan ポートの設定を変更する:

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'

ネットワークを再起動する

/etc/init.d/network restart

設定を行う#

アドレス option ipaddr

ユーザー名:root

パスワード:password

ホストマシンのネットワークを復元する#

Openwrt コンテナを実行すると、ホストマシン内で外部ネットワークに正常に接続できなくなる場合があります。ホストマシンの /etc/network/interfaces ファイルを変更する必要があります。

cp /etc/network/interfaces /etc/network/interfaces.bak 
vim /etc/network/interfaces 

ファイルの末尾に追加する:

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

参考#

Docker で OpenWrt のサイドゲートウェイを実行する

読み込み中...
文章は、創作者によって署名され、ブロックチェーンに安全に保存されています。