vmware workstation中安装配置openwrt

背景:

平时在vmware中做实验时候,经常需要在不同的机器上下载一些github上的项目进行调试,之前解决方案是在路由器层小米ac2100上装openwrt,试用一番发现太卡了。放弃,这次在vmware中安装作为小米ac2100的旁路由

规划:

网卡规划

两块网卡 顺序不能颠倒
第一块网卡:
vmnet8
vmware workstation自带vmnet网卡模式 对应openwrt中的lan口

vmnet5 自定义桥接到宿主机有线网卡 对应openwrt中的wan口

网络规划

小米ac2100路由器网段是192.168.6.0/24

vmnet5网段也是192.168.6.0/24
vmnet8 网段和虚拟机中的vmnet8保持一致即可

实施

vmware中的客户机操作系统类型
在这里插入图片描述
网卡配置
在这里插入图片描述

在这里插入图片描述

下载img镜像

https://downloads.openwrt.org/releases/22.03.0-rc6/targets/x86/64/generic-ext4-combined-efi.img.gz

使用qemu-img工具将img转换为vmdk虚拟磁盘文件直接挂载

root@kktb:kktb#sudo apt update
root@kktb:kktb#sudo apt install qemu-utils
root@kktb:kktb#qemu-img convert -f raw -O vmdk openwrt-22.03.0-rc6-x86-64-generic-ext4-combined-efi.img openwrt-22.03.0-rc6-x86-64-generic-ext4-combined-efi.img.vmdk

开机
刚装好,不能ssh连接的话,可能是防火墙的问题

关闭防火墙

root@OpenWrt:~# /etc/init.d/firewall stop
root@OpenWrt:~# /etc/init.d/firewall status
inactive
# 永久禁用防火墙
root@OpenWrt:~# /etc/init.d/firewall disable

配置网络

root@OpenWrt:~# cat /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 'fd99:ce59:984a::/48'

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

config interface 'lan'
	option device 'br-lan'
	option proto 'static'
	option ip6assign '60'
	option netmask '255.255.0.0'
	option ipaddr '10.0.0.3'

config interface 'wan'
	option device 'eth1'
	option proto 'static'
	option ipaddr '192.168.6.66'
	option netmask '255.255.255.0'
	option gateway '192.168.6.1'
	list dns '223.5.5.5'
	list dns '8.8.8.8'

config interface 'wan6'
	option device 'eth1'
	option proto 'dhcpv6'
	option auto '0'
	option reqaddress 'try'
	option reqprefix 'auto'

调整终端提示符prompt的颜色和格式

root@OpenWrt:~# cat /etc/profile
[ -e /tmp/.failsafe ] && export FAILSAFE=1

[ -f /etc/banner ] && cat /etc/banner
[ -n "$FAILSAFE" ] && cat /etc/banner.failsafe

grep -Fsq '/ overlay ro,' /proc/mounts && {
	echo 'Your JFFS2-partition seems full and overlayfs is mounted read-only.'
	echo 'Please try to remove files from /overlay/upper/... and reboot!'
}

export PATH="/usr/sbin:/usr/bin:/sbin:/bin"
export HOME=$(grep -e "^${USER:-root}:" /etc/passwd | cut -d ":" -f 6)
export HOME=${HOME:-/root}
export PS1='\u@\h:\w\$ \[\e[m\]' # 这里也要更改
export ENV=/etc/shinit

case "$TERM" in
	xterm*|rxvt*)
		export PS1='\[\e[32;1m\]\[\e]0;\u@\h: \w\a\]'$PS1 # 将终端提示符颜色设置为绿色
		;;
esac

[ -n "$FAILSAFE" ] || {
	for FILE in /etc/profile.d/*.sh; do
		[ -e "$FILE" ] && . "$FILE"
	done
	unset FILE
}

if ( grep -qs '^root::' /etc/shadow && \
     [ -z "$FAILSAFE" ] )
then
cat << EOF
=== WARNING! =====================================
There is no root password defined on this device!
Use the "passwd" command to set up a new password
in order to prevent unauthorized SSH logins.
--------------------------------------------------
EOF
fi

效果
在这里插入图片描述

这样vmware中其他的虚机想要通过代理上网,可以将虚机的网关地址改为openwrt的lan口地址,即10.0.0.3。同样的,如果局域网内的其他设备想要访问虚拟机中的服务也可以将网关地址改成192.168.6.66即可。比如在手机上访问虚拟机中的harbor服务,访问nfs服务。

剩下的配置就不放出来了

根分区扩容

原生的openwrt只有128MB,后期想要下载一些包空间就略显不足。

步骤

  1. 关闭openwrt,在磁盘里面点击扩展
  2. 开机,安装磁盘管理工具,查看磁盘
  3. 分区,查看挂载点,
  4. 通过web界面设置为根挂载点,执行生成的命令

关机状态下这里是可以扩展的,如果不行,删除快照再试试。
在这里插入图片描述
安装分区工具和luci界面的挂载点工具

root@OpenWrt:~# opkg install cfdisk block-mount

分区

root@OpenWrt:~# cfdisk

将free space分区

root@OpenWrt:~# fdisk -l
Disk /dev/sda: 2 GiB, 2147483648 bytes, 4194304 sectors
Disk model: VMware Virtual S
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 5A758C35-A6C1-E37D-B819-777F56E24300

Device       Start     End Sectors  Size Type
/dev/sda1      512   33279   32768   16M Linux filesystem
/dev/sda2    33280  246271  212992  104M Linux filesystem
/dev/sda3   247808 4194270 3946463  1.9G Linux filesystem
/dev/sda128     34     511     478  239K BIOS boot

Partition table entries are not in disk order.

写入文件系统

root@OpenWrt:~# mkfs.ext4 /dev/sda3
mke2fs 1.46.5 (30-Dec-2021)
Creating filesystem with 493307 4k blocks and 123392 inodes
Filesystem UUID: 9184ab75-135c-4463-80db-71bdb97b6c1b
Superblock backups stored on blocks: 
	32768, 98304, 163840, 229376, 294912

Allocating group tables: done                            
Writing inode tables: done                            
Creating journal (8192 blocks): done
Writing superblocks and filesystem accounting information: done 

web-luci界面点击生成配置
在这里插入图片描述
在这里插入图片描述
将生成的命令复制备用,web界面记得点保存,要点两次保存,再执行如下命令才会生效。

# 创建临时挂载点
mkdir -p /tmp/introot
mkdir -p /tmp/extroot
# 将现有的根分区挂载至initroot目录
mount --bind / /tmp/introot
# 将要被新建的分区挂载到extroot目录
mount /dev/sda3 /tmp/extroot # 这里的sda3是再cfdisk中新建的分区,也就是要被挂载为根分区的
# 将现有的根分区的所有文件压缩打包并解压到新分区的挂载点中
tar -C /tmp/introot -cvf - . | tar -C /tmp/extroot -xf -
# 卸载挂载点
umount /tmp/introot
umount /tmp/extroot

重启

reboot

扩容后

root@OpenWrt:~# df -Th
Filesystem           Type            Size      Used Available Use% Mounted on
/dev/root            ext4          102.3M     59.2M     41.1M  59% /rom
tmpfs                tmpfs         982.6M      3.5M    979.2M   0% /tmp
/dev/sda3            ext4            1.8G     59.2M      1.6G   3% /
/dev/sda1            vfat           16.0M      5.7M     10.2M  36% /boot
/dev/sda1            vfat           16.0M      5.7M     10.2M  36% /boot
tmpfs                tmpfs         512.0K         0    512.0K   0% /dev

路由问题

现在vmware网络环境中有两个DHCP服务器,所以有时候会导致从宿主机连接到虚拟机连不上。

电脑睡眠之后,连接虚机时候vmnet8只有发包,没有收包,如果重启一下网卡就正常了。

一些路由问题记录

C:\WINDOWS\system32>route print

IPv4 路由表
===========================================================================
活动路由:
网络目标        网络掩码          网关       接口   跃点数
          0.0.0.0          0.0.0.0     192.168.6.66    192.168.6.103    281
         10.0.0.0      255.255.0.0         10.0.0.2    192.168.6.103     26
         10.0.0.0      255.255.0.0            在链路上          10.0.0.1    291
         10.0.0.1  255.255.255.255            在链路上          10.0.0.1    291
     10.0.255.255  255.255.255.255            在链路上          10.0.0.1    291
        127.0.0.0        255.0.0.0            在链路上         127.0.0.1    331

C:\WINDOWS\system32>route print
IPv4 路由表
===========================================================================
活动路由:
网络目标        网络掩码          网关       接口   跃点数
          0.0.0.0          0.0.0.0     192.168.6.66    192.168.6.103    281
         10.0.0.0      255.255.0.0            在链路上          10.0.0.1    291
         10.0.0.1  255.255.255.255            在链路上          10.0.0.1    291
     10.0.255.255  255.255.255.255            在链路上          10.0.0.1    291
        127.0.0.0        255.0.0.0            在链路上         127.0.0.1    331

软件包

mii-tool查看网卡当前速率

root@OpenWrt:~# opkg install ethtool mii-tool
  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值