SecureCRT 连接本地linux虚拟机(二)

上篇讲述了通过SecureCRT SSH连接本地虚拟机中关于虚拟机安装openssh-client和启用相关服务。本篇介绍关于如何配置虚拟机网络连接方式。

一、在VirtualBox中将网络连接配置为桥接网卡方式。SecureCRT能远端到虚拟服务器,同时虚拟服务器能够访问外网。

wKiom1W0ofexp4W5AAHDFp6d8Ug544.jpg

本机通过无线网卡连接外网。所以界面名称选择的桥接网卡为无线网卡。

在虚拟终端查看网络信息,通过ifconfig命令

huanr@huanr-VBox:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:86:d2:30  
          inet addr:192.168.1.111  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe86:d230/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:23954 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9961 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:29500490 (29.5 MB)  TX bytes:784452 (784.4 KB)
...
huanr@huanr-VBox:~$

可以看到虚拟机地址为192.168.1.111,在客户机ping该地址,可以ping通,说明能客户机到虚拟机可通讯。


在虚拟机ping客户机地址,ping外网,如baidu

huanr@huanr-VBox:~$ ping 192.168.1.106
PING 192.168.1.106 (192.168.1.106) 56(84) bytes of data.
64 bytes from 192.168.1.106: icmp_seq=1 ttl=64 time=0.668 ms
64 bytes from 192.168.1.106: icmp_seq=2 ttl=64 time=0.426 ms
64 bytes from 192.168.1.106: icmp_seq=3 ttl=64 time=0.579 ms


huanr@huanr-VBox:~$ ping www.baidu.com
PING www.a.shifen.com (119.75.217.109) 56(84) bytes of data.
64 bytes from 119.75.217.109: icmp_seq=1 ttl=56 time=56.9 ms
64 bytes from 119.75.217.109: icmp_seq=2 ttl=56 time=10.4 ms
64 bytes from 119.75.217.109: icmp_seq=3 ttl=56 time=11.8 ms
64 bytes from 119.75.217.109: icmp_seq=4 ttl=56 time=14.6 ms

都能通讯,说明虚拟机能访问外网。


二、NAT网络地址转换。(虚机能访问Internet,而SecureCRT无法连接到虚拟机)


wKiom1W0pYnSj5KvAAGflydc5Ms450.jpg

虚拟机ping主机和外网:

huanr@huanr-VBox:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:86:d2:30  
          inet addr:10.0.2.15  Bcast:10.0.2.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe86:d230/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:23954 errors:0 dropped:0 overruns:0 frame:0
          TX packets:9961 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:29500490 (29.5 MB)  TX bytes:784452 (784.4 KB)
huanr@huanr-VBox:~$ ping 192.168.1.106
PING 192.168.1.106 (192.168.1.106) 56(84) bytes of data.
64 bytes from 192.168.1.106: icmp_seq=1 ttl=63 time=2.35 ms
64 bytes from 192.168.1.106: icmp_seq=2 ttl=63 time=1.38 ms
64 bytes from 192.168.1.106: icmp_seq=3 ttl=63 time=2.04 ms


huanr@huanr-VBox:~$ ping www.baidu.com
PING www.a.shifen.com (119.75.217.109) 56(84) bytes of data.
64 bytes from 119.75.217.109: icmp_seq=1 ttl=55 time=12.9 ms
64 bytes from 119.75.217.109: icmp_seq=2 ttl=55 time=10.9 ms
64 bytes from 119.75.217.109: icmp_seq=3 ttl=55 time=10.3 ms

说明虚拟机到主机能通讯,可访问外网。



主机ping虚拟机地址

C:\>ping 10.0.2.15

正在 Ping 10.0.2.15 具有 32 字节的数据:
请求超时。
请求超时。
请求超时。
请求超时。

10.0.2.15 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 0,丢失 = 4 (100% 丢失),

通讯超时,无法通过SecureCRT连接到虚拟机。



三、仅主机(Host-Only)适配器连接方式。可通过SecureCRT连接到虚拟机,但虚机无法与外界通讯

wKioL1W0q1jAXDuYAAG6W6ZKXXs837.jpg


自动获取virtualBox网卡地址

wKiom1W0qpCDCU9uAAGrBnTBD4M148.jpg

huanr@huanr-VBox:~$ ifconfig
eth0      Link encap:Ethernet  HWaddr 08:00:27:86:d2:30  
          inet addr:192.168.56.101  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fe86:d230/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:24495 errors:0 dropped:0 overruns:0 frame:0
          TX packets:10842 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:29561758 (29.5 MB)  TX bytes:890494 (890.4 KB)

ping客户机,无法到达

huanr@huanr-VBox:~$ ping 192.168.1.106
connect: Network is unreachable



客户机ping虚机可以通讯

C:\>ping 192.168.56.101

正在 Ping 192.168.56.101 具有 32 字节的数据:
来自 192.168.56.101 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.101 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.101 的回复: 字节=32 时间<1ms TTL=64
来自 192.168.56.101 的回复: 字节=32 时间<1ms TTL=64

192.168.56.101 的 Ping 统计信息:
    数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
    最短 = 0ms,最长 = 0ms,平均 = 0ms