以virtualbox为例, 其实VMware他们俩设置基本上相同,只是virtualbox更轻量级一些,使用起来更方便:
- 虚拟机外部设置
- 使用桥接方式联网
在virtualbox【设置】页面中点击【网络选项】,在【连接方式(A)】中选择“桥接网卡”,混杂模式中选择“全部允许”。
外部设置完成了,若linux虚拟机已经启动,则需要重启才能生效。
- 虚拟机内部(Linux)设置
网络接口配置文件
[root@localhost ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
Intel Corporation 82545EM Gigabit Ethernet Controller (Copper)
TYPE=Ethernet #网卡类型
DEVICE=eth0 #网卡接口名称
ONBOOT=yes #系统启动时是否自动加载(默认为no,改为yes)
BOOTPROTO=dhcp
重新导入ifcfg-eth0网络配置文件
[root@localhost ~]# /etc/init.d/network reload
Shutting down interface eth0: [ OK ]
Shutting down loopback interface: [ OK ]
Bringing up loopback interface: [ OK ]
Bringing up interface eth0: [ OK ]
- 打完收工
网卡接口关闭与激活
[root@localhost ~]# ifdown eth0 #关闭网络
[root@localhost ~]# ifup eth0 #启动网络