VirtualBox安裝CentOS的網絡配置

VirtualBox安裝CentOS的網絡配置

$ 前言

  • 鏡像:CentOS-6.4-i386-minimal.iso

$ 配置目標

  • 虛擬機裡的CentOS既可以和主機互聯,同時也可以連上外網

$ 碰到的錯誤

<code>使用ping時,錯誤:
network is unreachable
service network restart時,錯誤:
Device eth0 does not seem to be present.
/<code>

1.先配置好Host-only和Nat

VirtualBox安裝CentOS的網絡配置

VirtualBox安裝CentOS的網絡配置

2.查看文件cat /etc/udev/rules.d/70-persistent-net.rules

查看配置的上圖的mac地址 是否與 文件中的ATTR[address]對應上.

如果不對應可以選擇刪除該文件重啟,也可以直接修改該文件

<code>[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"
/<code>

3.進入 cd /etc/sysconfig/network-scripts目錄

3.1 修改目錄下的ifcfg-eth0 文件

該文件的DEVICE,HWADDR 應該與/etc/udev/rule.d/70-persistent-net.rules中的eth1一致. 我的ifcfg-eth0 文件,修改後為:

<code>[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
/<code>

3.2 修改目錄下的ifcfg-eth1 文件(沒有則創建)

該文件的DEVICE,HWADDR 應該與/etc/udev/rule.d/70-persistent-net.rules中的eth2一致. 我的ifcfg-eth1 文件,修改後為:

<code>[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
/<code>

4.重啟服務, service network restart

執行ifconfig命令,輸出

<code>[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)/<code>


分享到:


相關文章: