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=eth0 HWADDR=00:0C:29:67:A2:13 IPADDR=192.168.1.157 NETMASK=255.255.255.0 GATEWAY=192.168.1.1 DNS=192.168.1.1 BOOTPROTO=static ONBOOT=yes TYPE=Ethernet PREFIX=24 DEFROUTE=yes IPV4_FAILURE_FATAL=yes IPV6INIT=no NAME="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.com PING 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 ms 64 bytes from 115.239.210.27: icmp_seq=3 ttl=55 time=49.5 ms 64 bytes from 115.239.210.27: icmp_seq=4 ttl=55 time=52.8 ms 64 bytes from 115.239.210.27: icmp_seq=5 ttl=55 time=48.4 ms 64 bytes from 115.239.210.27: icmp_seq=6 ttl=55 time=48.1 ms 64 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 6682ms rtt min/avg/max/mdev = 48.073/49.296/52.858/1.676 ms [root@localhost /]#