不知道为什么最近一段时间网络特别的慢,还老是断,断的时候,局域网都连不上,当我手动设置一下ip后就可以了,搞得我很无语。下面是2种设置网络连接的方法,在说怎么设置前,一定要做好备份工作,特别是对于新手来说,如果修改的地方多了,你也会搞晕的,所以修改一个文件前一定要备份
一,修改文件来设置网络连接
1,自动获取IP的方法自动获取根4个文件有关系a),/etc/sysconfig/network-scripts/ifcfg-eth0[zhangy@localhostnetwork-scripts]$catifcfg-eth0#MarvellTechnologyGroupLtd.88E8039PCI-EFastEthernetControllerDEVICE=eth0//由eth0来启动BOOTPROTO=dhcp//获取IP的方式是自动获取,static是固定IP,none是手动HWADDR=00:16:D3:A2:F6:09//网卡的物理地址IPV6INIT=yes//是否支持IP6IPV6_AUTOCONF=yes//IP6是否自动配置ONBOOT=yes//启动时网络接口是否有效b),/etc/sysconfig/network[zhangy@localhostnetwork-scripts]$cat/etc/sysconfig/networkNETWORKING=yes//网络是否可用NETWORKING_IPV6=yesHOSTNAME=localhost.localdomain//主机名,主机名在/etc/hosts里面配置c),/etc/hosts[zhangy@localhostnetwork-scripts]$cat/etc/hosts#Donotremovethefollowingline,orvariousprograms#thatrequirenetworkfunctionalitywillfail.127.0.0.1localhost.localdomainlocalhost//根/etc/resolv.conf中search要对应,localhost.localdomain::1localhost6.localdomain6localhost6d),/etc/resolv.conf[zhangy@localhostnetwork-scripts]$cat/etc/resolv.conf;generatedby/sbin/dhclient-scriptnameserver192.168.1.1//DNS服务器对应的IPsearchlocaldomain//搜索要找的域名,在/etc/hosts里面设定的有2,手动设定手动设定只要修改三个文件就可以了a),/etc/sysconfig/network[zhangy@localhostnetwork-scripts]$cat/etc/sysconfig/networkNETWORKING=yesNETWORKING_IPV6=yes#HOSTNAME=localhost.localdomain//为什么要把主机名注释掉,一般先解析主机名或者域名,再解析DNSGATEWAY=192.168.1.1//加上网关b),/etc/sysconfig/network-scripts/ifcfg-eth0[zhangy@localhostnetwork-scripts]$catifcfg-eth0#MarvellTechnologyGroupLtd.88E8039PCI-EFastEthernetControllerDEVICE=eth0BOOTPROTO=none//启动为手动BROADCAST=192.168.1.255HWADDR=00:16:D3:A2:F6:09IPADDR=192.168.1.108//设置的IPNETMASK=255.255.255.0//子网掩码NETWORK=192.168.1.0IPV6INIT=yesIPV6_AUTOCONF=yesONBOOT=yesTYPE=Ethernet//网络类型c),/etc/resolv.conf[zhangy@localhostnetwork-scripts]$cat/etc/resolv.conf#;generatedby/sbin/dhclient-script#nameserver192.168.1.1#searchlocaldomainnameserver116.228.111.118//加上主DNSnameserver180.168.255.18//加上次DNS二,命令方法
netconfig是网络管理工具,RH装完机后,系统中就会有netconfig。虽然centos也是由RH演化来的,但是没有啊。不过没关系我们可能自己来装。[zhangy@localhostdownload]$wgetftp://ftp.nluug.nl/pub/os/Linux/distr/CentOS/5.0/os/i386/CentOS/netconfig-0.8.24-1.2.2.1.i386.rpm[zhangy@localhostdownload]$rpm-ivhnetconfig-0.8.24-1.2.2.1.i386.rpmerror:can'tcreatetransactionlockon/var/lib/rpm/__db.000[zhangy@localhostdownload]$suroot//别忘了要用root账户,不然就会报上面的错误口令:[root@localhostdownload]#rpm-ivhnetconfig-0.8.24-1.2.2.1.i386.rpmPreparing...###########################################[100%]1:netconfig###########################################[100%][root@localhostdownload]#whereisnetconfig//查看一下netconfig在什么地方netconfig:/usr/sbin/netconfig
复制代码