在CentOS 7設定PPPoE撥接功能

pppoe

其實設定撥接應該很簡單,但是因為筆者前兩天在把伺服器更新到 CentOS 7 的時候,發現以前的指令不大一樣,本來想試 NetworkManager,但似乎預設也沒有提供撥接的功能(其實是懶的找),上網查了一下才發現指令已經變了@@,為了避免日後又忘記,所以寫了一篇記錄上來~

要先注意的是,如果你的主機一開始沒有辦法利用撥接上網,那麼就只好將主機放在內部網路中,先用 NetworkManager 設定一下網路,再去安裝以下的套件,不然一開始就連不上網,裝啥?

CentOS 7 的撥接套件是「rp-pppoe」,請利用以下的指令安裝:

#yum install rp-pppoe

為了避免衝突,接下來就可以先關掉 NetworkManager:

#systemctl stop NetworkManager.service
#systemctl disable NetworkManager.service

網路上還有人直接把 NetworkManager 給移掉了,不過筆者是不大建議這樣,可能有一天會急需用到呀~如果真要移除,請用以下指令:

#yum erase NetworkManager

接著設定撥接網路!以前的指令都是「adsl-*」為開頭,現在都改成用「pppoe-*」為開頭的指令,大概網路進入光纖世代,ADSL退位了才有這樣的改變吧 XD(亂入),初始化設定的指令如下:

#pppoe-setup

接下來進入設定的畫面,以下分開說明,首先先設定你的撥接帳號,大多數人都是中華電信,如果要設定固定 IP,在申裝網路時就先和施工人員表明,他會幫你申請,大約 1 個工作天就可以完成(不過通常半天就生效了),此時撥接的帳號應為:你的帳號@ip.hinet.net

Welcome to the PPPoE 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): 你的帳號@ip.hinet.net

接下來會要你輸入用來撥接的網路卡代號,系統預設會打eth0,不過在 CentOS 7 可能會依設備而有所不同,請你先用 ifconfig 查一下:

#ifconfig
eno16777736: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
 inet 192.168.1.40 netmask 255.255.255.0 broadcast 192.168.1.255
 inet6 fe80::20c:29ff:fe5b:8412 prefixlen 64 scopeid 0x20<link>
 ether 00:0c:29:5b:84:12 txqueuelen 1000 (Ethernet)
 RX packets 20047 bytes 29360723 (28.0 MiB)
 RX errors 0 dropped 0 overruns 0 frame 0
 TX packets 3427 bytes 280978 (274.3 KiB)
 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
 inet 127.0.0.1 netmask 255.0.0.0
 inet6 ::1 prefixlen 128 scopeid 0x10<host>
 loop txqueuelen 0 (Local Loopback)
 RX packets 4 bytes 248 (248.0 B)
 RX errors 0 dropped 0 overruns 0 frame 0
 TX packets 4 bytes 248 (248.0 B)
 TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

在本例中的機器只有一張網路,代號為eno16777736,這就是待會要填入的資訊,如下:

INTERFACE

Enter the Ethernet interface connected to the PPPoE 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): eno16777736

接下來的設定是問是否是要隔一段時間重撥?預設是「no」設定為持續連線的狀態。

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 位置:(168.95.1..1)

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: 168.95.1.1

設定次要的 DNS 位置(可以按 Enter 跳過)

Please enter the IP address of your ISP's secondary DNS server.
If you just press enter, I will assume there is only one DNS server.
Enter the secondary DNS server address here:

設定你的撥接帳號的密碼:

PASSWORD

Please enter your Password:******
Please re-enter your Password:******

設定是否讓一般用戶啟動連線,預設為 yes。

USERCTRL

Please enter 'yes' (three letters, lower-case.) if you want to allow
normal user to start or stop DSL connection (default yes):

設定連線的模式,共有 3 種,如果沒有什麼特別需求,選擇 0 ,然後再用別的套件來達到 1 (防火牆)及 2 (NAT)的功能。

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

設定是否要在開機時連線?當然是 yes 囉,不過預設是 no,這部份要注意。

Start this connection at boot time

Do you want to start this connection at boot time?
Please enter no or yes (default no):yes

確認設定是否正確,如果正確的話請按下 y。

** Summary of what you entered **

Ethernet Interface: eth0
User name: root
Activate-on-demand: No
DNS: Do not adjust
Firewalling: NONE
User Control: yes
Accept these settings and adjust configuration files (y/n)? y

完成設定後,重啟網路的方式如下,在「【伺服器】安裝完 CentOS 7 的 7 項基本工作」一篇也有提過:

#/etc/init.d/network restart

如果連線成功,再重新啟動系統試試看是否能正確的連線~完工!

發表迴響

你的電子郵件位址並不會被公開。 必要欄位標記為 *