需求是本地啟動了oralce數(shù)據(jù)庫和一個服務,連接的工具應用在pd的win7虛擬機中運行坚俗,如果訪問127.0.0.1的話酗钞,只能訪問虛擬機內(nèi)部,如果想訪問mac主機藤树,在有網(wǎng)的情況下浴滴,NAT模式可以訪問本機的外網(wǎng)IP拓萌。
但是這樣有兩個問題:
- 第一個隨著網(wǎng)絡的變化岁钓,要不停的修改連接地址。
- 如果沒有網(wǎng)絡連接微王,就不可連接屡限。
初步查看了一下NAT的實現(xiàn)模式,實際上也是在本地建立了虛擬網(wǎng)絡炕倘,然后對外訪問的時候钧大,屏蔽了內(nèi)網(wǎng)的情況。
因此一般情況下虛擬機可以公共物理機的對外訪問網(wǎng)絡罩旋,但是外部無法訪問虛擬機啊央。但是網(wǎng)上有方法,就是配置NAT的端口映射涨醋,那么實際上瓜饥,其實相當于和路由器相同的功能。
對于macOS來說浴骂,ParallelsDesktop(PD)虛擬機乓土,并不像vmware在windows那樣,就vmnet8這種虛擬網(wǎng)卡可以改溯警。但是連接虛擬機的時候趣苏,如果是NAT模式,右上角就會顯示虛擬機的IP梯轻,截圖如下:
可見內(nèi)部虛擬網(wǎng)絡中食磕,虛擬的IP是10.211.55.5
然后在mac的term中執(zhí)行ifconfig
/Users/suitm>ifconfig
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=1203<RXCSUM,TXCSUM,TXSTATUS,SW_TIMESTAMP>
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
nd6 options=201<PERFORMNUD,DAD>
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en5: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether ac:de:48:00:11:22
inet6 fe80::aede:48ff:fe00:1122%en5 prefixlen 64 scopeid 0x4
nd6 options=281<PERFORMNUD,INSECURE,DAD>
media: autoselect
status: active
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether 78:4f:43:75:21:0a
inet6 fe80::1848:803:28e7:badf%en0 prefixlen 64 secured scopeid 0x5
inet 192.168.31.203 netmask 0xffffff00 broadcast 192.168.31.255
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
en2: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
options=60<TSO4,TSO6>
ether 92:00:c8:8a:b7:04
media: autoselect <full-duplex>
status: inactive
en4: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
options=60<TSO4,TSO6>
ether 92:00:c8:8a:b7:05
media: autoselect <full-duplex>
status: inactive
en1: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
options=60<TSO4,TSO6>
ether 92:00:c8:8a:b7:00
media: autoselect <full-duplex>
status: inactive
en3: flags=963<UP,BROADCAST,SMART,RUNNING,PROMISC,SIMPLEX> mtu 1500
options=60<TSO4,TSO6>
ether 92:00:c8:8a:b7:01
media: autoselect <full-duplex>
status: inactive
bridge0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=63<RXCSUM,TXCSUM,TSO4,TSO6>
ether 92:00:c8:8a:b7:00
Configuration:
id 0:0:0:0:0:0 priority 0 hellotime 0 fwddelay 0
maxage 0 holdcnt 0 proto stp maxaddr 100 timeout 1200
root id 0:0:0:0:0:0 priority 0 ifcost 0 port 0
ipfilter disabled flags 0x2
member: en1 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 8 priority 0 path cost 0
member: en2 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 6 priority 0 path cost 0
member: en3 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 9 priority 0 path cost 0
member: en4 flags=3<LEARNING,DISCOVER>
ifmaxaddr 0 port 7 priority 0 path cost 0
nd6 options=201<PERFORMNUD,DAD>
media: <unknown type>
status: inactive
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
ether 0a:4f:43:75:21:0a
media: autoselect
status: inactive
awdl0: flags=8943<UP,BROADCAST,RUNNING,PROMISC,SIMPLEX,MULTICAST> mtu 1484
ether 6a:10:9a:47:06:01
inet6 fe80::6810:9aff:fe47:601%awdl0 prefixlen 64 scopeid 0xc
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
utun0: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 2000
inet6 fe80::8db7:12c6:559f:211f%utun0 prefixlen 64 scopeid 0xd
nd6 options=201<PERFORMNUD,DAD>
utun1: flags=8051<UP,POINTOPOINT,RUNNING,MULTICAST> mtu 1380
inet6 fe80::ce4d:225c:38e2:af20%utun1 prefixlen 64 scopeid 0xe
nd6 options=201<PERFORMNUD,DAD>
vnic0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=3<RXCSUM,TXCSUM>
ether 00:1c:42:00:00:08
inet 10.211.55.2 netmask 0xffffff00 broadcast 10.211.55.255
media: autoselect
status: active
vnic1: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=3<RXCSUM,TXCSUM>
ether 00:1c:42:00:00:09
inet 10.37.129.2 netmask 0xffffff00 broadcast 10.37.129.255
media: autoselect
status: active
/Users/suitm>
直接用網(wǎng)絡編輯器并不能看到,可以看喳挑,其中vnic0就是PD給NAT模式虛擬網(wǎng)絡分配的本機IP彬伦。
因此萄金,在NAT模式下,無論是否有網(wǎng)媚朦,都可以連接10.211.55.2
查出的這個地址氧敢,進行訪問。