一、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: 空