在windows7系统中,我们有时候会使用vmware player来跑虚拟机。当要想实现端口转发功能的话,就需要做些手动配置。
vmware nat的配置文件在 C:\ProgramData\VMware\vmnetnat.conf。
这个文件里面有一些注释,可以参考来配置自己想要的端口映射。
如:
[incomingtcp]
# Use these with care - anyone can enter into your virtual machine through these...
# FTP (both active and passive FTP is always enabled)
# ftp localhost 8887
#8887 = 192.168.27.128:21
# WEB (make sure that if you are using named webhosting, names point to
# your host, not to guest... And if you are forwarding port other
# than 80 make sure that your server copes with mismatched port
# number in Host: header)
# lynx http://localhost:8888
#8888 = 192.168.27.128:80
# SSH
# ssh -p 8889 root@localhost
#8889 = 192.168.27.128:22
[incomingudp]
# UDP port forwarding example
#6000 = 192.168.27.128:6001
5025 = 192.168.229.128:5025
5045 = 192.168.229.128:5045
这次,我是想实现5045和5025端口从宿主机到虚拟主机的跳转,虚拟机的IP为192.168.229.128,所以添加以下配置:
5025 = 192.168.229.128:5025
5045 = 192.168.229.128:5045
注意:vmnetnat.conf文件在宿主机上,所以上面的操作是将宿主机的端口与虚拟机的端口绑定,在等号前面的宿主机的端口,等号后面的为虚拟机的IP和端口。
添加并保持配置文件后,需要重启下vmware nat service的服务才能生效。
在“控制面板”-->“管理工具”->“服务”中找到 VMware NAT Service,将其停止后再启动即可。