Note-52242-25

Token ID: 1

ERC-721 1 Transfers

Metadata

{
  "type": "note",
  "title": "docker安装openwrt作网关",
  "tags": [
    "post",
    "tech"
  ],
  "summary": "前期准备 开启网卡混合模式\n\nCopy\nsudo ip link set enx00e04c6800fa promisc on\n\n\n创建macvlan网络\n\nCopy\ndocker network create -d macvlan --subnet=192.168.50.0/24 --g…",
  "sources": [
    "xlog"
  ],
  "external_urls": [
    "https://blog.huisui.me/openwrt-dockermd"
  ],
  "date_published": "2022-03-10T00:00:00.000Z",
  "content": "\n## 前期准备\n\n开启网卡混合模式\n\n```bash\nsudo ip link set enx00e04c6800fa promisc on\n```\n\n创建macvlan网络\n\n```bash\ndocker network create -d macvlan --subnet=192.168.50.0/24 --gateway=192.168.50.1 -o parent=enx00e04c6800fa macnet\n```\n\npull docker\n\n```bash\ndocker pull registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64\n```\n\n## 配置docker\n\n运行docker\n\n```bash\ndocker run --restart always --name openwrt -d --network macnet --privileged registry.cn-shanghai.aliyuncs.com/suling/openwrt:x86_64 /sbin/init\n```\n\n进入docker设置网络\n\n```bash\ndocker exec -it openwrt bash\nvim /etc/config/network\n```\n\n更改 Lan 口设置:\n\n```bash\nconfig interface 'lan'\n        option type 'bridge'\n        option ifname 'eth0'\n        option proto 'static'\n        option ipaddr '192.168.50.100'\n        option netmask '255.255.255.0'\n        option ip6assign '60'\n        option gateway '192.168.50.1'\n        option broadcast '192.168.50.255'\n        option dns '192.168.50.1'\n```\n\n重启网络\n\n```shell\n/etc/init.d/network restart\n```\n\n## 进行设置\n\n地址`option ipaddr`\n\n用户名:`root`\n\n密码:`password`\n\n\n\n## 宿主机网络恢复\n\nOpenwrt容器运行后,宿主机内可能无法正常连接外部网络,需要修改宿主机的 `/etc/network/interfaces` 文件\n\n```bash\ncp /etc/network/interfaces /etc/network/interfaces.bak \nvim /etc/network/interfaces \n```\n\n向文件末尾添加:\n\n```bash\nauto eth0\niface eth0 inet manual\n\nauto macvlan\niface macvlan inet static\n  address 192.168.50.200\n  netmask 255.255.255.0\n  gateway 192.168.50.1\n  dns-nameservers 192.168.50.1\n  pre-up ip link add macvlan link eth0 type macvlan mode bridge\n  post-down ip link del macvlan link eth0 type macvlan mode bridge\n```\n\n\n\n## 参考\n\n[在Docker 中运行 OpenWrt 旁路网关](https://mlapp.cn/376.html)\n",
  "attributes": [
    {
      "value": "openwrt-dockermd",
      "trait_type": "xlog_slug"
    }
  ]
}