VirtualBox安裝CentOS的網(wǎng)絡配置
$ 前言
- 鏡像:CentOS-6.4-i386-minimal.iso
$ 配置目標
- 虛擬機里的CentOS既可以和主機互聯(lián),同時也可以連上外網(wǎng)
$ 碰到的錯誤
使用ping時,錯誤:
network is unreachable
service network restart時,錯誤:
Device eth0 does not seem to be present.
1.先配置好Host-only和Nat
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 文件(沒有則創(chuàng)建)
該文件的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
執(zhí)行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)