服务器之家:专注于VPS、云服务器配置技术及软件下载分享
分类导航

云服务器|WEB服务器|FTP服务器|邮件服务器|虚拟主机|服务器安全|DNS服务器|服务器知识|Nginx|IIS|Tomcat|

服务器之家 - 服务器技术 - 服务器知识 - 虚拟机VirtualBox中centos6.5网络设置图文详解

虚拟机VirtualBox中centos6.5网络设置图文详解

2020-12-14 21:56飞鸿影~ 服务器知识

这篇文章主要介绍了虚拟机VirtualBox中centos6.5网络设置图文详解,具有一定的参考价值,有需要的朋友可以了解一下。

最近一些日子在学习有关于虚拟机virtualbox,现在分享给大家参考一下。

一、虚拟机网络配置

默认只是设置了网卡1:方式nat(对应ifcfg-eth0)

虚拟机VirtualBox中centos6.5网络设置图文详解

我们还可以设置网卡2,网卡3。可以在系统安装完成后设置。

网卡2设置回环网卡,实现虚拟机与宿主机组成局域网(对应ifcfg-eth1),这样即使没有路由器也可以组成局域网,可以进行ssh连接。

虚拟机VirtualBox中centos6.5网络设置图文详解

需要宿主机安装microsoftloopbackadapter。参加附录。

网卡3设置连接到互联网,并与宿主机组成局域网(对应ifcfg-eth2)。需要依赖网络,且有真实路由器。

虚拟机VirtualBox中centos6.5网络设置图文详解

二、centos里eth设置

进入/etc/sysconfig/network-scripts目录,默认只有ifcfg-eth0。

复制ifcfg-eth0为ifcfg-eth1,修改为:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
device=eth1
 
#hwaddr=08:00:27:31:f1:dc
 
type=ethernet
 
#uuid=b8f8e76e-1f8b-4cf5-9261-493bfc6b04ef
 
onboot=yes
 
nm_controlled=yes
 
bootproto=static
 
ipaddr="192.168.12.10"
 
gateway="192.168.12.1"

复制ifcfg-eth0为ifcfg-eth2,修改为:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
device=eth2
 
#hwaddr=08:00:27:31:f1:dc
 
type=ethernet
 
#uuid=b8f8e76e-1f8b-4cf5-9261-493bfc6b04ef
 
onboot=yes
 
nm_controlled=yes
 
bootproto=dhcp

保存好后,使用命令:servicenetworkrestart重启网络服务,如果ifcfg-eth1和ifcfg-eth2显示为绿色,说明二者设置成功。

网卡文件内容示例说明:

?
1
2
3
4
5
6
7
8
9
10
device=eth0         //指出设备名称
bootprot=static       //启动类型 dhcp|static
broadcast=192.168.1.203   //广播地址
hwaddr=00:06:5b:fe:df:7c  //硬件mac地址
ipaddr=192.168.0.2     //ip地址
netmask=255.255.255.0    //子网掩码
network=192.168.0.0     //网络地址
gateway=192.168.0.1     //网关地址
onboot=yes         //是否启动应用
type=ethernet        //网络类型

为验证结果,可以输入ifconfig进行验证:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
[root@localhost network-scripts]# ifconfig
 
eth1   link encap:ethernet hwaddr 08:00:27:e9:68:b0
 
     inet addr:192.168.12.10 bcast:192.168.12.255 mask:255.255.255.0
 
     inet6 addr: fe80::a00:27ff:fee9:68b0/64 scope:link
 
     up broadcast running multicast mtu:1500 metric:1
 
     rx packets:1682 errors:0 dropped:0 overruns:0 frame:0
 
     tx packets:775 errors:0 dropped:0 overruns:0 carrier:0
 
     collisions:0 txqueuelen:1000
 
     rx bytes:134511 (131.3 kib) tx bytes:109027 (106.4 kib)
 
 
 
eth2   link encap:ethernet hwaddr 08:00:27:2e:18:7a
 
     inet addr:192.168.36.85 bcast:192.168.36.255 mask:255.255.255.0
 
     inet6 addr: fe80::a00:27ff:fe2e:187a/64 scope:link
 
     up broadcast running multicast mtu:1500 metric:1
 
     rx packets:885 errors:0 dropped:0 overruns:0 frame:0
 
     tx packets:42 errors:0 dropped:0 overruns:0 carrier:0
 
     collisions:0 txqueuelen:1000
 
     rx bytes:72712 (71.0 kib) tx bytes:4156 (4.0 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:16436 metric:1
 
     rx packets:12 errors:0 dropped:0 overruns:0 frame:0
 
     tx packets:12 errors:0 dropped:0 overruns:0 carrier:0
 
     collisions:0 txqueuelen:0
 
     rx bytes:1028 (1.0 kib) tx bytes:1028 (1.0 kib)

能显示出eth1和eth2说明成功了。

附录:

windows7上安装微软microsoftloopbackadapter(回环网卡)的方法

1.单击开始图标,在搜索中输入hdwwiz,在搜索结果中鼠标右键单击该程序,使用“以管理员身份运行”方式来启动。

2.根据操作系统向导,选择“安装我手动从列表选择的硬件(高级)”。

3.在硬件列表中,选择“网络适配器”。

4.选择“microsoft”厂商,并在右边网络适配器列表中选中“microsoftloopbackadapter”,下一步按照向导完成安装。

虚拟机VirtualBox中centos6.5网络设置图文详解

5.安装完成后,查看硬件管理器,会多出一个新网卡,这就是虚拟网卡。

虚拟机VirtualBox中centos6.5网络设置图文详解

接下来,需要进行些配置:

打开网络和共享中心->更改适配器设置,找到标识有microsoftloopbackadapter的那个网络,右键属性,选中internet协议版本4(tcp/ipv4),点击下方属性,编辑为:

虚拟机VirtualBox中centos6.5网络设置图文详解

这里的网关是我自己定义的,为192.168.12.1,当然可以改成其他的,比如192.168.13.1。这里宿主机的ip是192.168.12.2,虚拟机里就不能设置为这个了。这里与虚拟机eth1是对应的,eth1的ip也源自这里。修改后保存即可。

注意回环网卡最好在设置虚拟机网络之前就设置好。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

延伸 · 阅读

精彩推荐