vmware中安装配置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中的客户机操作系统类型
vmware中安装配置openwrt_第1张图片
网卡配置
vmware中安装配置openwrt_第2张图片

vmware中安装配置openwrt_第3张图片

下载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_第4张图片

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

剩下的配置就不放出来了

一些路由问题记录

C:\WINDOWS\system32>route print
===========================================================================
接口列表
  5...........................Wintun Userspace Tunnel
 22...04 d9 f5 1b e9 c8 ......Intel(R) Ethernet Connection (7) I219-V
 12...00 ff 60 71 5c 0c ......TAP-Windows Adapter V9
 13...38 00 25 61 54 2c ......Intel(R) Wireless-AC 9560 160MHz
 24...38 00 25 61 54 2d ......Microsoft Wi-Fi Direct Virtual Adapter
  8...3a 00 25 61 54 2c ......Microsoft Wi-Fi Direct Virtual Adapter #2
 25...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1
 11...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8
  7...38 00 25 61 54 30 ......Bluetooth Device (Personal Area Network)
  1...........................Software Loopback Interface 1
===========================================================================

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
        127.0.0.1  255.255.255.255            在链路上         127.0.0.1    331
  127.255.255.255  255.255.255.255            在链路上         127.0.0.1    331
      192.168.6.0    255.255.255.0            在链路上     192.168.6.103    281
    192.168.6.103  255.255.255.255            在链路上     192.168.6.103    281
    192.168.6.255  255.255.255.255            在链路上     192.168.6.103    281
     192.168.10.0    255.255.255.0            在链路上      192.168.10.1    291
     192.168.10.1  255.255.255.255            在链路上      192.168.10.1    291
   192.168.10.255  255.255.255.255            在链路上      192.168.10.1    291
        224.0.0.0        240.0.0.0            在链路上         127.0.0.1    331
        224.0.0.0        240.0.0.0            在链路上     192.168.6.103    281
        224.0.0.0        240.0.0.0            在链路上      192.168.10.1    291
        224.0.0.0        240.0.0.0            在链路上          10.0.0.1    291
  255.255.255.255  255.255.255.255            在链路上         127.0.0.1    331
  255.255.255.255  255.255.255.255            在链路上     192.168.6.103    281
  255.255.255.255  255.255.255.255            在链路上      192.168.10.1    291
  255.255.255.255  255.255.255.255            在链路上          10.0.0.1    291
===========================================================================
永久路由:
  网络地址          网络掩码  网关地址  跃点数
          0.0.0.0          0.0.0.0     192.168.6.66     默认
===========================================================================

IPv6 路由表
===========================================================================
活动路由:
 接口跃点数网络目标                网关
  1    331 ::1/128                  在链路上
 22    281 fe80::/64                在链路上
 25    291 fe80::/64                在链路上
 11    291 fe80::/64                在链路上
 25    291 fe80::128:4e5e:a777:21ed/128
                                    在链路上
 11    291 fe80::9086:6967:3aa:bf93/128
                                    在链路上
 22    281 fe80::b184:1b68:9b7b:116/128
                                    在链路上
  1    331 ff00::/8                 在链路上
 22    281 ff00::/8                 在链路上
 25    291 ff00::/8                 在链路上
 11    291 ff00::/8                 在链路上
===========================================================================
永久路由:
  无
C:\WINDOWS\system32>route print
===========================================================================
接口列表
  5...........................Wintun Userspace Tunnel
 22...04 d9 f5 1b e9 c8 ......Intel(R) Ethernet Connection (7) I219-V
 12...00 ff 60 71 5c 0c ......TAP-Windows Adapter V9
 13...38 00 25 61 54 2c ......Intel(R) Wireless-AC 9560 160MHz
 24...38 00 25 61 54 2d ......Microsoft Wi-Fi Direct Virtual Adapter
  8...3a 00 25 61 54 2c ......Microsoft Wi-Fi Direct Virtual Adapter #2
 25...00 50 56 c0 00 01 ......VMware Virtual Ethernet Adapter for VMnet1
 11...00 50 56 c0 00 08 ......VMware Virtual Ethernet Adapter for VMnet8
  7...38 00 25 61 54 30 ......Bluetooth Device (Personal Area Network)
  1...........................Software Loopback Interface 1
===========================================================================

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
        127.0.0.1  255.255.255.255            在链路上         127.0.0.1    331
  127.255.255.255  255.255.255.255            在链路上         127.0.0.1    331
      192.168.6.0    255.255.255.0            在链路上     192.168.6.103    281
    192.168.6.103  255.255.255.255            在链路上     192.168.6.103    281
    192.168.6.255  255.255.255.255            在链路上     192.168.6.103    281
     192.168.10.0    255.255.255.0            在链路上      192.168.10.1    291
     192.168.10.1  255.255.255.255            在链路上      192.168.10.1    291
   192.168.10.255  255.255.255.255            在链路上      192.168.10.1    291
        224.0.0.0        240.0.0.0            在链路上         127.0.0.1    331
        224.0.0.0        240.0.0.0            在链路上      192.168.10.1    291
        224.0.0.0        240.0.0.0            在链路上          10.0.0.1    291
        224.0.0.0        240.0.0.0            在链路上     192.168.6.103    281
  255.255.255.255  255.255.255.255            在链路上         127.0.0.1    331
  255.255.255.255  255.255.255.255            在链路上      192.168.10.1    291
  255.255.255.255  255.255.255.255            在链路上          10.0.0.1    291
  255.255.255.255  255.255.255.255            在链路上     192.168.6.103    281
===========================================================================
永久路由:
  网络地址          网络掩码  网关地址  跃点数
          0.0.0.0          0.0.0.0     192.168.6.66     默认
===========================================================================

IPv6 路由表
===========================================================================
活动路由:
 接口跃点数网络目标                网关
  1    331 ::1/128                  在链路上
 25    291 fe80::/64                在链路上
 11    291 fe80::/64                在链路上
 22    281 fe80::/64                在链路上
 25    291 fe80::128:4e5e:a777:21ed/128
                                    在链路上
 11    291 fe80::9086:6967:3aa:bf93/128
                                    在链路上
 22    281 fe80::b184:1b68:9b7b:116/128
                                    在链路上
  1    331 ff00::/8                 在链路上
 25    291 ff00::/8                 在链路上
 11    291 ff00::/8                 在链路上
 22    281 ff00::/8                 在链路上
===========================================================================
永久路由:
  无

你可能感兴趣的:(Network,Windows,microsoft,openwrt,vmware)