1.首先聲明,我是在虛擬機器下配置上網:
在VMWare的網卡設定裡面,配置如下:
進入系統之後,預設IP地址是一個很奇怪的IP: 192.168.48.1
現在開始我們的工作:
1.[root@localhost /]# cd /etc/sysconfig/network-scripts/
2.[root@localhost network-scripts]# ls
ifcfg-eth0 ifdown-ipv6 ifup ifup-ipx ifup-sit
ifcfg-lo ifdown-isdn ifup-aliases ifup-isdn ifup-tunnel
ifdown ifdown-post ifup-bnep ifup-plip ifup-wireless
ifdown-bnep ifdown-ppp ifup-eth ifup-plusb init.ipv6-global
ifdown-eth ifdown-routes ifup-ippp ifup-post net.hotplug
ifdown-ippp ifdown-sit ifup-ipsec ifup-ppp network-functions
ifdown-ipsec ifdown-tunnel ifup-ipv6 ifup-routes network-functions-ipv6
3.[root@localhost network-scripts]# gedit ifcfg-eth0
4.輸入一些配置資訊,我的設定檔最終如下:
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]DEVICE=eth0HWADDR=00:0C:29:67:A2:13IPADDR=192.168.1.157NETMASK=255.255.255.0GATEWAY=192.168.1.1DNS=192.168.1.1BOOTPROTO=staticONBOOT=yesTYPE=EthernetPREFIX=24DEFROUTE=yesIPV4_FAILURE_FATAL=yesIPV6INIT=noNAME="System eth0"UUID=5fb06bd0-0bb0-7ffb-45f1-d6edd65f3e03
基本上都看的懂吧, 看不懂的話 就自己去找理解吧。
5.[root@localhost network-scripts]# /etc/init.d/network restart
基本的步驟就是上面一些,其實我配置的時候遇到了很多問題的,下面一一道來,如果你們也遇到的話,希望你們能參考一下我的解決方案。
1. 首先,我在ifconifg的時候,居然出現在我眼前的是 eth4, 不是eth0, 而在系統的/etc/sysconfig/network-scripts/目錄下居然是ifcfg-eth0 , 當時我就傻眼了。
解決方案:
A. rm /etc/udev/rules.d/70-persistent-net.rules (在刪除之前,你們最好能備份一下,我是膽子大,什麼都敢乾的..)
B. reboot
C.重啟動之後, 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 0x1022:0x2000 (vmxnet)SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="00:0c:29:67:a2:13", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"
其中"00:0c:29:67:a2:13"就是我們要得到的具體資訊了,==>> MAC地址。
D.cd /etc/sysconfig/network-scripts/
E.gedit ifcfg-eth0
F.將"HWADDR“參數修改為: 00:0c:29:67:a2:13
G. /etc/init.d/network restart
H. ping 測試一下:
[root@localhost /]# ping www.baidu.comPING www.a.shifen.com (115.239.210.27) 56(84) bytes of data.64 bytes from 115.239.210.27: icmp_seq=2 ttl=55 time=48.0 ms64 bytes from 115.239.210.27: icmp_seq=3 ttl=55 time=49.5 ms64 bytes from 115.239.210.27: icmp_seq=4 ttl=55 time=52.8 ms64 bytes from 115.239.210.27: icmp_seq=5 ttl=55 time=48.4 ms64 bytes from 115.239.210.27: icmp_seq=6 ttl=55 time=48.1 ms64 bytes from 115.239.210.27: icmp_seq=7 ttl=55 time=48.8 ms^C--- www.a.shifen.com ping statistics ---7 packets transmitted, 6 received, 14% packet loss, time 6682msrtt min/avg/max/mdev = 48.073/49.296/52.858/1.676 ms[root@localhost /]#