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

相關文章
相關標籤/搜索