Ubuntu环境在Virtualbox虚拟机运行OpenWrt

一、OpenWrt镜像下载(x86 64位)

1、在https://downloads.openwrt.org/releases/19.07.7/targets/x86/64 下载镜像文件

二、将原始镜像文件转换为Virtualbox格式

1、解压下载的gz文件

gzip -d openwrt-19.07.7-x86-64-combined-ext4.img.gz

2、转换原始镜像为Virtualbox格式文件(VDI)

Vboxmanage convertfromraw --format VDI openwrt-19.07.7-x86-64-combined-ext4.img openwrt-19.07.7-x86-64-combined-ext4.vdi

三、Virtualbox新建虚拟机

1、新建虚拟机

2、设置虚拟机名称,选择类型及版本

3、设置虚拟机内存使用

4、选择“使用已有的虚拟硬盘文件”,点击“文件”图标,选择注册使用通过Vboxmanage转换过的VDI文件。点击“创建”即可完成创建。

(注意: VDI文件之后不能移动位置,否则VirtualBox启动时无法找到,建议将VDI文件先放到新建虚拟机目录中。如:VirtualBox VMs/OpenWrt

四、Virtualbox虚拟机网络设置

1、背景环境

给新的虚拟机分配3个网络接口:

Eth0作为管理接口,在Virtualbox中使用“仅主机网络”连接方式,连接到Virtualbox默认的vboxnet0网络(该网络宿主机地址为192.168.56.1),在OpenWrt虚拟机中设置该接口为静态IP 192.168.56.2

Eth1作为Wan接口,在Virtualbox中使用“网络地址转换(NAT)”连接方式,在OpenWrt虚拟机中设置该接口为DHCP

Eth2作为Lan接口,在Virtualbox中使用“桥接网卡”连接方式,连接到Virtualbox指定的宿主机真实网卡,在OpenWrt中设置该接口为静态IP 192.168.1.1

2、Virtualbox虚拟机网络设备

五、虚拟机OpenWrt网络配置

1、配置管理接口

uci set network.mng.type='bridge'

uci set network.mng.proto='static'

uci set network.mng.ifname='eth0'

uci set network.mng.ipaddr='192.168.56.2'

uci set network.mng.netmask='255.255.255.0'

2、配置Wan接口

uci set network.wan.proto='dhcp'

uci set network.wan.ifname='eth1'

3、配置Lan接口

uci set network.lan.proto='static'

uci set network.lan.ifname='eth2'

uci set network.lan.ipaddr='192.168.1.1'

uci set network.lan.netmask='255.255.255.0'

4、配置生效

uci commit

5、查看当前网络配置

uci show network

--------------------------------------------

network.lan=interface

network.lan.type='bridge'

network.lan.proto='static'

network.lan.netmask='255.255.255.0'

network.lan.ip6assign='60'

network.lan.ifname='eth2'

network.lan.ipaddr='192.168.1.1'

network.wan=interface

network.wan.ifname='eth1'

network.wan.proto='dhcp'

network.mng=interface

network.mng.type='bridge'

network.mng.proto='static'

network.mng.ifname='eth0'

network.mng.ipaddr='192.168.56.2'

network.mng.netmask='255.255.255.0'

6、网络管理生效

/etc/init.d/network restart

六、宿主机通过SSH客户端连接到虚拟机(当前使用SecureCRT客户端

SSH配置:

Host: 192.168.56.2

Username: root

Password: 空

 

 

 

  • 3
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值