在VirtualBox虚拟机里面搭建了数据库,想在虚拟机外面的主机操作系统中通过数据库客户端工具连接到虚拟机里面的数据库。
在"设置"里面配置"网络"选项
在"网络"里面增加一块网卡2,使用"Host-Only"连接方式
在虚拟机里面配置网络
[root@localhost ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
GATEWAY= 192.168.56.1
DEVICE=eth1
BOOTPROTO=none
NETMASK=255.255.255.0
TYPE=Ethernet
HWADDR=08:00:27:1d:31:c1
IPADDR= 192.168.56.200
IPV6INIT=no
ONBOOT=yes
USERCTL=no
虚拟机eth1网卡的ip地址要和虚拟机外面主机里面虚拟机的网络IP要处于同一网段
C:\Users\jijia>ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection* 9:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : gemalto.com
IPv4 Address. . . . . . . . . . . : 10.162.104.198
Subnet Mask . . . . . . . . . . . : 255.255.254.0
Default Gateway . . . . . . . . . : 10.162.104.1
Ethernet adapter VirtualBox Host-Only Network:
Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 192.168.56.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
重启虚拟机网络
[root@localhost ~]# service network restart
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:27:57:C8
inet6 addr: fe80::a00:27ff:fe27:57c8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:258 (258.0 b)
eth1 Link encap:Ethernet HWaddr 08:00:27:1D:31:C1
inet addr:192.168.56.200 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe1d:31c1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:22 errors:0 dropped:0 overruns:0 frame:0
TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2403 (2.3 KiB) TX bytes:1802 (1.7 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:112 errors:0 dropped:0 overruns:0 frame:0
TX packets:112 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8748 (8.5 KiB) TX bytes:8748 (8.5 KiB)
这样,虚拟机外面的主机就可以通过网络访问虚拟机里面的网络了
C:\Users\jijia>ping 192.168.56.200
Pinging 192.168.56.200 with 32 bytes of data:
Reply from 192.168.56.200: bytes=32 time=1ms TTL=64
Reply from 192.168.56.200: bytes=32 time<1ms TTL=64
Reply from 192.168.56.200: bytes=32 time<1ms TTL=64
Reply from 192.168.56.200: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.56.200:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms
在"设置"里面配置"网络"选项
![](http://img.blog.itpub.net/blog/attachment/201607/28/26506993_1469692779ficl.png?x-oss-process=style/bb)
在"网络"里面增加一块网卡2,使用"Host-Only"连接方式
![](http://img.blog.itpub.net/blog/attachment/201607/28/26506993_1469692813iHM8.png?x-oss-process=style/bb)
在虚拟机里面配置网络
[root@localhost ~]# vim /etc/sysconfig/network
NETWORKING=yes
NETWORKING_IPV6=no
HOSTNAME=localhost.localdomain
[root@localhost ~]# vim /etc/sysconfig/network-scripts/ifcfg-eth1
# Please read /usr/share/doc/initscripts-*/sysconfig.txt
# for the documentation of these parameters.
GATEWAY= 192.168.56.1
DEVICE=eth1
BOOTPROTO=none
NETMASK=255.255.255.0
TYPE=Ethernet
HWADDR=08:00:27:1d:31:c1
IPADDR= 192.168.56.200
IPV6INIT=no
ONBOOT=yes
USERCTL=no
虚拟机eth1网卡的ip地址要和虚拟机外面主机里面虚拟机的网络IP要处于同一网段
C:\Users\jijia>ipconfig
Windows IP Configuration
Ethernet adapter Local Area Connection* 9:
Media State . . . . . . . . . . . : Media disconnected
Connection-specific DNS Suffix . :
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . : gemalto.com
IPv4 Address. . . . . . . . . . . : 10.162.104.198
Subnet Mask . . . . . . . . . . . : 255.255.254.0
Default Gateway . . . . . . . . . : 10.162.104.1
Ethernet adapter VirtualBox Host-Only Network:
Connection-specific DNS Suffix . :
IPv4 Address. . . . . . . . . . . : 192.168.56.1
Subnet Mask . . . . . . . . . . . : 255.255.255.0
Default Gateway . . . . . . . . . :
重启虚拟机网络
[root@localhost ~]# service network restart
[root@localhost ~]# ifconfig
eth0 Link encap:Ethernet HWaddr 08:00:27:27:57:C8
inet6 addr: fe80::a00:27ff:fe27:57c8/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:0 errors:0 dropped:0 overruns:0 frame:0
TX packets:3 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:0 (0.0 b) TX bytes:258 (258.0 b)
eth1 Link encap:Ethernet HWaddr 08:00:27:1D:31:C1
inet addr:192.168.56.200 Bcast:192.168.56.255 Mask:255.255.255.0
inet6 addr: fe80::a00:27ff:fe1d:31c1/64 Scope:Link
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:22 errors:0 dropped:0 overruns:0 frame:0
TX packets:27 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:2403 (2.3 KiB) TX bytes:1802 (1.7 KiB)
lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
inet6 addr: ::1/128 Scope:Host
UP LOOPBACK RUNNING MTU:65536 Metric:1
RX packets:112 errors:0 dropped:0 overruns:0 frame:0
TX packets:112 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:8748 (8.5 KiB) TX bytes:8748 (8.5 KiB)
这样,虚拟机外面的主机就可以通过网络访问虚拟机里面的网络了
C:\Users\jijia>ping 192.168.56.200
Pinging 192.168.56.200 with 32 bytes of data:
Reply from 192.168.56.200: bytes=32 time=1ms TTL=64
Reply from 192.168.56.200: bytes=32 time<1ms TTL=64
Reply from 192.168.56.200: bytes=32 time<1ms TTL=64
Reply from 192.168.56.200: bytes=32 time<1ms TTL=64
Ping statistics for 192.168.56.200:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 1ms, Average = 0ms
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/26506993/viewspace-2122695/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/26506993/viewspace-2122695/