备忘录:x86双网口小主机安装ubuntu在docker中运行openwrt当作主路由

该文详细介绍了如何在Ubuntu系统中安装和配置SSH服务器,以及如何利用Docker安装OpenWrt,并创建MACVLAN虚拟网卡来模拟LAN和WAN接口,实现多网络环境。同时,文章提到了在后续配置中可能遇到的联网问题及解决方案。
摘要由CSDN通过智能技术生成

Ubuntu篇

安装ubuntu

对,就是安装ubuntu,不会有人不会吧
更新下软件,配置一下root
更新:sudo apt-get update
root:sudo passwd root

安装并配置ssh-server(可以不配置,因为方便,所以我配置了)

命令

安装ssh-server:sudo apt-get install openssh-server
查看运行状况:sudo ps -e |grep ssh
启动ssh:sudo service ssh start
停止ssh:sudo service ssh stop
重启ssh:sudo /etc/init.d/ssh restart
修改配置文件:sudo nano /etc/ssh/sshd_config

按需修改

端口:取消注释Port 22
root登录:取消注释PermitRootLogin yes

详见:https://www.jianshu.com/p/6e8d70c4d820

安装net-tools

ifconfig下,按照提示装,装好了之后再ifconfig就能看到ipl

docker+openwrt篇

安装docker

https://www.starx.ink/archives/docker%e8%bf%90%e8%a1%8copenwrt%e5%b9%b6%e4%bd%9c%e4%b8%ba%e4%b8%bb%e8%b7%af%e7%94%b1/

将对应的网卡启动混淆模式
ip link set 物理网卡 promisc on

#!/bin/sh
ip link set enp4s0 promisc on
ip link set enp3s0 promisc on

https://blog.csdn.net/superdangbo/article/details/78688904

创建虚拟网卡

docker文档:https://docs.docker.com/network/drivers/macvlan/
删除:docker network rm -f ID

创建lan虚拟网卡

docker network create -d macvlan --subnet=192.168.2.0/24 --gateway=192.168.2.1 -o parent=enp3s0 virtual-lan

创建wan虚拟网卡

docker network create -d macvlan -o parent=enp4s0 virtual-wan

导入openwrt镜像

导入镜像:docker import https://archive.openwrt.org/releases/21.02.0/targets/x86/64/openwrt-21.02.0-x86-64-rootfs.tar.gz openwrt-x86-64-rootfs
查看镜像列表:docker image ls
查看运行中的镜像:docker ps

关联lan口启动容器:docker run --name openwrt --restart always -d --network virtual-lan --privileged openwrt-x86-64-rootfs /sbin/init
添加wan口:docker network connect virtual-wan openwrt
进入容器:docker exec -it openwrt sh
查看网络情况::ifconfig
修改网卡配置: vi /etc/config/network

config interface 'loopback'
        option device 'lo'
        option proto 'static'
        option ipaddr '127.0.0.1'
        option netmask '255.0.0.0'

config globals 'globals'
        option ula_prefix 'fdf0:6fa6:e2e9::/48'

config device
        option name 'br-lan'
        option type 'bridge'
        list ports 'eth0'

config interface 'lan'
        option device 'br-lan'
        option proto 'static'
        option ipaddr '192.168.1.1'
        option netmask '255.255.255.0'
        option ip6assign '60'

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

重启网卡:/etc/init.d/network restart
添加防火墙策略:iptables -t nat -I POSTROUTING -s 192.168.22.0/24 -j MASQUERADE

详见:https://www.treesir.pub/post/openwrt-docker-multi-net/

尾记:

在后续配置过程中出现了无法联网的情况,后续打算将docker中网卡wan口的工作模式改为桥接,使用inux主机进行网络认证处理。
  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值