CentOS 5.5(5.x)设置网络、PPPOE、软件源

设置网络

一、设置IP

    1.1) 修改IP地址1.9) 网络命令

修改对应网卡的IP地址的配置文件 
vi /etc/sysconfig/network-scripts/ifcfg-eth0

 修改如下内容
  • DEVICE=eth0     (描述网卡对应的设备别名,例如ifcfg-eth0的文件中它为eth0)
  • BOOTPROTO=static    (设置网卡得到ip地址的方式,可能的选项为static,dhcp或bootp,分别对应静态指定的ip地址,经过dhcp协议得到的ip地址,经过bootp协议得到的ip地址)
  • BROADCAST=192.168.0.255  (对应的子网广播地址)
  • HWADDR=00:07:E9:05:E8:B4 (对应的网卡物理地址)
  • IPADDR=12.168.1.2     (若是设置网卡得到ip地址的方式为静态指定,此字段就指定了网卡对应的ip地址)
  • IPV6INIT=no
  • IPV6_AUTOCONF=no
  • NETMASK=255.255.255.0  (网卡对应的网络掩码)
  • NETWORK=192.168.1.0  (网卡对应的网络地址)
  • ONBOOT=yes      (系统启动时是否设置此网络接口,设置为yes时,系统启动时激活此设备)

    1.2)修改网关

修改对应网卡的网关的配置文件
vi /etc/sysconfig/network

 修改如下内容
  • NETWORKING=yes  (表示系统是否使用网络,通常设置为yes。若是设为no,则不能使用网络,并且不少系统服务程序将没法启动)
  • HOSTNAME=centos  (设置本机的主机名,这里设置的主机名要和/etc/hosts中设置的主机名对应)
  • GATEWAY=192.168.1.1  (设置本机链接的网关的IP地址。例如,网关为10.0.0.2)

    1.3)修改DNS

修改对应网卡的DNS的配置文件
vi /etc/resolv.conf
修改如下内容
nameserver 202.101.224.68  # (域名服务器)
nameserver 202.101.224.69 # (域名服务器)

    
    1.4) 网络重启

service network restart

 或
/etc/init.d/network restart

    

    1.5) 修改ip地址

即时生效:
ifconfig eth0 192.168.0.2 netmask 255.255.255.0

 启动生效:

修改/etc/sysconfig/network-scripts/ifcfg-eth0php

        1.6) 修改网关default gateway

即时生效:
route add default gw 192.168.0.1 dev eth0

 启动生效:

修改/etc/sysconfig/networkweb

        1.7) 修改dns

修改/etc/resolv.conf

修改后可即时生效,启动一样有效shell

        1.8) 修改host name

即时生效:
hostname centos1
启动生效:

修改/etc/sysconfig/networkcentos

        1.9) 网络命令

ifdown eth0         #  关闭网络
ifconfig eth0 down  #  关闭网络
ifup eth0           #  开启网络
ifconfig eth0 up    #  开启网络

service network start     # 启动网络服务
service network stop      # 中止网络服务
service network restart   # 重启网络服务
service network status    # 查看网络服务状态


二、
PPPOE设置

    2.1)安装的前提条件

        确保安装了网卡并工做正常, 使用以下命令查看网卡的状态: 服务器

ifconfig eth0


 在系统中不要设置默认路由(网关), 让ADSL拨号后自动得到。

        若是已经设置了默认路由,使用如下方法删除: 
在文件 /etc/sysconfig/network/ifconfig-eth0 中删除 GATEWAY= 这一行,而后以root执行:网络

service network restart


         若是存在文件 /usr/sbin/pppd,则说明已经安装了pppd; 若是未安装,下载安装这个软件包。

      2.2) 安装PPPOE客户端软件 

      Linux下的PPPOE客户端软件比较多,并且大多使用GNU License,咱们推荐使用rp-pppoe这个软件包。从http://www.roaringpenguin.com/products/pppoe这个网站上,不只能够下载各发布包下的rp-pppoe的二进制软件包,并且能够下载源代码软件包。咱们使用centos下的yum安装方法,来安装rp-pppoe软件包架构

yum install rp-pppoe

 

        2.3) 配置PPPOE客户端软件

     安装完软件包后,必须配置PPPOE的配置文件/etc/ppp/pppoe.conf,从而让ADSL拨号时使用配置文件中的用户名、密码等参数。ide

      
# adsl-setup ← 创建ADSL链接工具

Welcome to the ADSL client setup. First, I will run some checks on
your system to make sure the PPPoE client is installed properly...测试

LOGIN NAME

Enter your Login Name (default root): ← 填入ADSL链接的用户名

INTERFACE

Enter the Ethernet interface connected to the ADSL modem
For Solaris, this is likely to be something like /dev/hme0.
For Linux, it will be ethX, where 'X' is a number.
(default eth0): ← 指定网络接入设备,一块网卡的状况下,通常为默认eth0

Do you want the link to come up on demand, or stay up continuously?
If you want it to come up on demand, enter the idle time in seconds
after which the link should be dropped. If you want the link to
stay up permanently, enter 'no' (two letters, lower-case.)
NOTE: Demand-activated links do not interact well with dynamic IP
addresses. You may have some problems with demand-activated links.
Enter the demand value (default no): ← 直接按回车,接受默认设置

DNS

Please enter the IP address of your ISP's primary DNS server.
If your ISP claims that 'the server will provide dynamic DNS addresses',
enter 'server' (all lower-case) here.
If you just press enter, I will assume you know what you are
doing and not modify your DNS setup.
Enter the DNS information here: ← 若是知道DNS服务器的信息在此填入。不知道的状况按回车跳过

PASSWORD

Please enter your Password: ← 输入ADSL的链接密码
Please re-enter your Password: ← 再次确认输入ADSL的链接密码

USERCTRL

Please enter 'yes' (two letters, lower-case.) if you want to allow
normal user to start or stop DSL connection (default yes): no ← 填入no,不容许通常用户控制PPPoE的链接

FIREWALLING

Please choose the firewall rules to use. Note that these rules are
very basic. You are strongly encouraged to use a more sophisticated
firewall setup; however, these will provide basic security. If you
are running any servers on your machine, you must choose 'NONE' and
set up firewalling yourself. Otherwise, the firewall rules will deny
access to all standard servers like Web, e-mail, ftp, etc. If you
are using SSH, the rules will block outgoing SSH connections which
allocate a privileged source port.

The firewall choices are:
0 - NONE: This script will not set any firewall rules. You are responsible
for ensuring the security of your machine. You are STRONGLY
recommended to use some kind of firewall rules.
1 - STANDALONE: Appropriate for a basic stand-alone web-surfing workstation
2 - MASQUERADE: Appropriate for a machine acting as an Internet gateway
for a LAN
Choose a type of firewall (0-2): 0 ← 输入0,不在这里使用防火墙

Start this connection at boot time

Do you want to start this connection at boot time?
Please enter no or yes (default no): yes ← 填入yes,在系统启动时自动链接ADSL

** Summary of what you entered **

Ethernet Interface: eth0
User name: caun870293@ca.dti.ne.jp
Activate-on-demand: No
DNS: Do not adjust
Firewalling: NONE
User Control: no
Accept these settings and adjust configuration files (y/n)? y ← 配置信息确认无误后,键入y赞成设置
Adjusting /etc/sysconfig/network-scripts/ifcfg-ppp0
Adjusting /etc/ppp/chap-secrets and /etc/ppp/pap-secrets
(But first backing it up to /etc/ppp/chap-secrets.bak)
(But first backing it up to /etc/ppp/pap-secrets.bak)

?

Congratulations, it should be all set up!

Type '/sbin/ifup ppp0' to bring up your xDSL link and '/sbin/ifdown ppp0'
to bring it down.
Type '/sbin/adsl-status /etc/sysconfig/network-scripts/ifcfg-ppp0'
to see the link status.

    2.4) 启动PPPOE客户端软件

# adsl-start ← 启动ADSL链接
# ← 稍等片刻后若启动成功后出现提示符(无任何提示或Connected意味着链接成功)

若是不成功,请检查网线、ADSL MODEM等物理设备,并查看 /var/log/messages中的信息 
/usr/sbin/adsl-stop 关闭和ISP的链接 
/usr/sbin/adsl-status 查看当前链接的状态 

若是想在Linux系统启动时自动启动ADSL链接,输入如下命令 
#chkconfig --add adsl 
将在当前的运行级下加入ADSL的自启动脚本

        2.5) 测试 

    当链接成功后,使用命令  ifconfig -a 在输出中应该含有关于 ppp0 的一堆信息,其中还绑定了 IP 地址,说明已经从拨号中获 得了IP地址。使用命令 netstat -nr 查看路由表信息,这时的默认路由应该是上面得到的IP地址。 若是没有默认路由,咱们能够手动增长: #route add default gw 上面得到的IP地址使用命令#nslookup www.sina.com.cn 若是解析出新浪的IP,说明已经从拨号中正确得到了DNS服务器最后,使用命令ping某个域名或IP,若是有响应,表示你已经大功告成了。

 

三、配置软件源

    3.1 CentOS的镜像和仓库

<1>CentOS的镜像站点

完整的CentOS软件库很是大。CentOS的软件包位于CentOS的镜像站点的目录树中,可经过FTP或HTTP访问它们。

在http://mirror-status.centos.org/能够看到各镜像的状态。
在http://www.centos.org/modules/tinycontent/index.php?id=22能够看到如何进行镜像的知识。

镜像站点的第一级目录是发行版本号,如三、四、5等。任何CentOS镜像站点的版本号为5的目录下都有下列目录。

  • addons/:包含CentOS的addons仓库。
  • centosplus/:包含CentOS的centosplus仓库。
  • extras/:包含CentOS的extras仓库。
  • fasttrack/:包含CentOS的fasttrack仓库。
  • isos-dvd/:包含发行版的DVD isos下载文件。
  • isos/:包含发行版的CD isos下载文件。
  • os/:包含发行版(distributions)的仓库。
  • updates/:包含CentOS的updates仓库。

<2>CentOS的仓库

仓库(repository)是一个预备好的目录,或是一个网站,包含了软件包和索引文件。yum能够在仓库中自动地定位并获取正确的RPM软件包。这样,你就没必要手动搜索和安装新应用程序和升级补丁了。只用一个命令,就能够更新系统中全部软件,也能够根据指定搜索目标来查找安装新软件。

镜像服务器为每一个版本的CentOS分别提供了一些仓库。CentOS5中的软件管理工具yum已经预先配置为使用下列4个仓库。

  • base:构成CentOS发行版(distributions)的软件包,和光盘上内容相同。
  • updates:base仓库中软件包的更新版本。
  • addons:已编译的但不在发行版(distributions)中的软件包。
  • extras:一大批附加的软件包。

你还可使用下面的仓库,但在CentOS5默认状况下未被启用。

  • centosplus/:用于加强一些现有软件包的功能。

CentOS仓库的目录结构

下面以CentOS5的updates仓库为例,说明其在镜像站点上的目录结构(其余仓库结构相似)。

updates/

SRPMS

*.src.rpm

repodata/

i386

RPMS

*.i386.rpm

*.centos.noarch.rpm

repodata/

x86_64

RPMS

*.i386.rpm

*.centos.noarch.rpm

repodata/

(2)配置yum客户的更新源

yum使用reposdir(/etc/yum.repos.d)目录下的一系列.repo文件列出可得到软件包仓库的镜像站点地址。围住状况下有以下两个文件。

  • CentOS-Base.repo:用于设置远程仓库。
  • CentOS-Media.repo:用于设置本地仓库。

在.repo文件中,配置语法是分段的,每一段配置一个软件仓库,配置语法以下:
[repositoryid]
name=Some name for this repository
baseurl=url://server1/path/to/repository/
url://server2/path/to/repository/
url://server3/path/to/repository/
mirrorlist=url://path/to/mirrorlist/repository/
enabled=0/1
gpgcheck=0/1
gpgkey=A URL pointing to the ASCII-armoured GPG key file for the repository

其中:

  • repositoryid:用于指定一个仓库。
  • name:用于指定易读的仓库名称。
  • baseurl:用于指定本仓库的URL,能够是以下的3种类型。

            http - 用于指定远程HTTP协议的源。
ftp - 用于指定远程FTP协议的源。
file - 用于本地镜像或NFS挂装文件系统。

  • mirrorlist:用于指定仓库的镜像站点。
  • enabled:用于指定是否使用本仓库,默认值为1,便可用。
  • gpgcheck:用于指定是否检查软件包的GPG签名。
  • gpgkey:用于指定GPG签名文件的URL。

Tips:在name baseurl中常用以下的变量:

  • $releaserver - 当前系统的版本号。
  • $basearch - 当前系统的平台架构。

另外,你还要注意如下几点。

  • 文件中以“#”开头的行是注释行。
  • 若指定mirrorlist,系统将从CentOS的镜像站点中选择离你最近的仓库。
  • 并不是全部的国内镜像都在CentOS的镜像站点列表中,因此咱们能够直接使用baseurl直接指定离你最近的仓库。
  • baseurl能够指定多个URL,系统会依次检查你列出的仓库,以便在某个服务器宕机时可使用另外的服务器。
  • 为了加快更新,在确保更新服务器及线路良好的状况下,在baseurl中只指定一个URL便可。

<1>设置网络更新源

#vi /etc/yum.repos.d/CetnOS-Base.repo
[base]
name=CentOS-5-Base
#mirrorlist=http://mirrorlist.centos.org/?release=$releasever5&arch=$basearch&repo=os
#baseurl=http://mirror.centos.org/centos/$releasever/os/$basearch/
baseurl=http://ftp.sjtu.edu.cn/centos/5/os/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#released updates
[update]
name=CentOS-5-Updates
#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=updates
baseurl=http://ftp.sjtu.edu.cn/centos/5/updates/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#packages used/produced in the build but not released
[addons]
name=CentOS-5-Addons
#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=addons

baseurl=http://ftp.sjtu.edu.cn/centos/5/addons/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#additional packages that may be useful
[extras]
name=CentOS-5-Extras
#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=extras

baseurl=http://ftp.sjtu.edu.cn/centos/5/extras/$basearch/
gpgcheck=1
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#additional packages that extend functionality of existing packages
[centosplus]
name=CentOS-5-Plus
#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=centosplus
baseurl=http://ftp.sjtu.edu.cn/centos/5/centosplus/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

#contrib - packages by Centos Users
[contrib]
name=CentOS-5-Contrib
#mirrorlist=http://mirrorlist.centos.org/?release=4&arch=$basearch&repo=contrib
baseurl=http://ftp.sjtu.edu.cn/centos/5/contrib/$basearch/
gpgcheck=1
enabled=0
gpgkey=http://mirror.centos.org/centos/RPM-GPG-KEY-centos5

导入key 
#rpm --import http://ftp.sjtu.edu.cn/centos/5/os/i386/RPM-GPG-KEY-CentOS-5
运行,测试
#yum update   
所有删除临时文件
#yum clean all

<2>设置本地更新源

为了使用安装光盘做为更新源,能够修改CentOS-Media.repo文件,下面是一个配置实例。
[c5-media]
name=CentOS-$releaserver - Media
baseurl=file:///media/CentOS/
file:///media/cdrom/
file:///media/cdrecorder/
gpgcheck=1
enabled=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-beta

Tips:1.为了使用c5-media仓库,须要将CentOS-Base.repo文件中的base仓库用enabled=0设置成不可用。
2.若本地磁盘空间有足够空间,你也能够将安装光盘复制到本地磁盘的一个目录中。

<3>设置非官方更新源

下面以安装rpmforge软件包为例添加非官方更新源。
步骤1:到http://dag.wieers.com/rpm/packages/rpmforge-release/查找适用于RHEL5/CentOS5软件包。
步骤2:下载适用于RHEL5/CentOS5的软件包。
#wget http://dag.wieers.com/rpm/packages/rpmforge-release/rpmforge-release-0.3.6-el5.rf.i386.rpm
#rpm -ivh rpm rpmforge-release-0.3.6-el5.rf.i386.rpm
#rpm –import /etc/pki/rpm-gpg/RPM-GPG-KEY-rpmfiorge-*
安装rpmforge-release软件包以后,你能够看到/etc/yum.repos.d/rpmforge.repo文件。之后yum就可使用这个更新源了。

你也可使用手工方法添加DAG的仓库。好比,创建dag.repo定义非官方库: #vi /etc/yum.repos.d/dag.repo [dag] name=Dag RPM Repository for Red Hat Enterprise Linux baseurl=http://apt.sw.be/redhat/el$releaserver/en/$basearch/dag gpgcheck=1 enabled=1 gpgkey=http://dag.wieers.com/packages/RPM-GPG-KEY.dag.txt

相关文章
相关标签/搜索