VirtualBox安装CentOS的网络配置.md 3.8 KB
Newer Older
M
monomania 已提交
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 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
#VirtualBox安装CentOS的网络配置

##$ 前言
* 镜像:CentOS-6.4-i386-minimal.iso
  

##$ 配置目标
* 虚拟机里的CentOS既可以和主机互联,同时也可以连上外网


##$ 碰到的错误
~~~
使用ping时,错误:
network is unreachable
service network restart时,错误:
Device eth0 does not seem to be present.
~~~

## 1.先配置好Host-only和Nat
![virtualbox_1.jpg](https://upload-images.jianshu.io/upload_images/3285005-cc541cb072f8b9c4.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

![virtualbox_2.jpg](https://upload-images.jianshu.io/upload_images/3285005-04ab2bd7cd665bdf.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)

## 2.查看文件cat /etc/udev/rules.d/70-persistent-net.rules
查看配置的上图的mac地址 是否与  文件中的ATTR[address]对应上.

如果不对应可以选择删除该文件重启,也可以直接修改该文件

~~~
[root@localhost network-scripts]# cat /etc/udev/rules.d/70-persistent-net.rules
# This file was automatically generated by the /lib/udev/write_net_rules
# program, run by the persistent-net-generator.rules rules file.
#
# You can modify it, as long as you keep each rule on a single
# line, and change only the value of the NAME= key.


# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:e2:c7:25", ATTR{type}=="1", KERNEL=="eth*", NAME="eth1"


# PCI device 0x8086:0x100e (e1000)
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="08:00:27:bb:f0:79", ATTR{type}=="1", KERNEL=="eth*", NAME="eth2"
~~~
##  3.进入  cd /etc/sysconfig/network-scripts目录
### 3.1 修改目录下的ifcfg-eth0 文件
 该文件的DEVICE,HWADDR 应该与/etc/udev/rule.d/70-persistent-net.rules中的eth1一致.
      我的ifcfg-eth0 文件,修改后为:
~~~
[root@localhost network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth1
HWADDR=08:00:27:E2:C7:25
TYPE=Ethernet
UUID=459bb09f-ce67-4276-a510-371dc8b8a12e
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
~~~
### 3.2 修改目录下的ifcfg-eth1 文件(没有则创建)
  该文件的DEVICE,HWADDR 应该与/etc/udev/rule.d/70-persistent-net.rules中的eth2一致.
      我的ifcfg-eth1 文件,修改后为:
~~~
[root@localhost network-scripts]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE=eth2
HWADDR=08:00:27:BB:F0:79
TYPE=Ethernet
UUID=459bb09f-ce67-4276-a510-371dc8b8a12e
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=dhcp
~~~
## 4.重启服务,  service network restart
执行ifconfig命令,输出 
~~~
[root@localhost network-scripts]# ifconfig
eth1      Link encap:Ethernet  HWaddr 08:00:27:E2:C7:25
          inet addr:192.168.56.103  Bcast:192.168.56.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:fee2:c725/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:924 errors:0 dropped:0 overruns:0 frame:0
          TX packets:500 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:90940 (88.8 KiB)  TX bytes:80641 (78.7 KiB)


eth2      Link encap:Ethernet  HWaddr 08:00:27:BB:F0:79
          inet addr:10.0.3.15  Bcast:10.0.3.255  Mask:255.255.255.0
          inet6 addr: fe80::a00:27ff:febb:f079/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:5 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:1066 (1.0 KiB)  TX bytes:1145 (1.1 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:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
~~~