CentOS 7 設定固定IP自動連線
固定IP是架設伺服器不可或缺的設施之一!但是要怎麼使用在CentOS 7 設定固定IP自動連線呢?
在台灣,使用中華電信,可以申請1個固定IP。
方法1:由ISP業者提供固定IP、Gateway、DNS等資訊,直接在CentOS網路組態裡面。
方法2(本範例):像中華電信這樣,不會提供固定Gateway等資訊,用戶必須透過PPPOE連線程式連線。
安裝PPPOE軟體
1 |
[andy@www~]$ yum install rp-pppoe |
停止Network Manager (大家都知道這軟體是亂源~)
1 2 |
[andy@www~]$ systemctl stop NetworkManager.service [andy@www~]$ systemctl disable NetworkManager.service |
記下主要的網路硬體裝置名稱
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
[andy@www~]$ sudo ifconfig eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192.168.1.200 netmask 255.255.255.0 broadcast 192.168.1.255 inet6 f123::f123:f123:f123:f123 prefixlen 64 scopeid 0x20<link> ether f1:99:f2:88:f3:77 txqueuelen 1000 (Ethernet) RX packets 8780567 bytes 6280044984 (5.8 GiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 695680 bytes 148663847 (141.7 MiB) 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 1 (Local Loopback) RX packets 204039 bytes 113553517 (108.2 MiB) RX errors 0 dropped 0 overruns 0 frame 0 TX packets 204039 bytes 113553517 (108.2 MiB) TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 |
一次列出來好多裝置,怎麼知道我的網路卡是哪一個?
以我的伺服器為例,只有一張網卡,可以看到eth0有MAC address(ether f1:99:f2:88:f3:77)設定值,而且它是有實際傳送與接收資料(RX packets/TX packets)的,所以八九不離十就是他了!
開始設定PPPOE軟體
1 |
[andy@www~]$ pppoe-setup |
設定PPPOE連線帳號
因為要設定固定,所以要填這個值:你的用戶帳號@ip.hinet.net
1 2 3 4 5 |
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 |
輸入網路卡裝置名稱
1 2 3 4 5 6 |
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): eth0 |
此處是程式向你詢問,是不是要閒置一段時間就斷線?
如果想要閒置一段時間就斷線,請輸入:閒置秒數。
如果要永遠保持連線狀態,請輸入:NO
1 2 3 4 5 6 7 |
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): no |
設定兩組DNS位址,分別是主要(primary)DNS、以及次要(secondary)DNS
下列幾個DNS都可以用:
HiNet提供的DNS:168.95.1.1 168.95.192.1
Google提供的DNS:8.8.8.8 8.8.4.4
1 2 3 4 5 6 |
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 |
1 2 3 |
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: 8.8.4.4 |
設定連線密碼,這邊就輸入HiNet給的用戶連線密碼:
1 2 3 |
PASSWORD Please enter your Password: Please re-enter your Password: |
使用者控制,是否允許一般使用者操作PPPOE軟體,控制連線或斷線?
預設值是yes
但如果你的伺服器是要提供給其他使者使用,建議設定為no。(例如:伺服器是為了架起來作為電腦課的教學用途)
1 2 3 4 |
USERCTRL Please enter 'yes' (three letters, lower-case.) if you want to allow normal user to start or stop DSL connection (default yes): yes |
PPPOE軟體給予的連線模式有三種:
None:一般使用 (我們選擇這個)
Standalone:作為防火牆
Masquerade:作為NAT使用
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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 |
(電腦)開機時就自動連線?
這邊肯定要設定成自動連線!(y)
但是小心預設值是否喔!(n)
1 2 3 4 |
Start this connection at boot time Do you want to start this connection at boot time? Please enter no or yes (default no): y |
PPPOE軟體會將剛才的設定值列出來給你再次確認:
正確的話就輸入y,即可完成設定!
不正確的話就輸入n,可以更改設定值!
1 2 3 4 5 6 7 8 9 |
** Summary of what you entered ** Ethernet Interface: eth0 User name: andy Activate-on-demand: No DNS: Do not adjust Firewalling: NONE User Control: yes Accept these settings and adjust configuration files (y/n)? y |
重啟網路服務!
1 |
[andy@www~]$ sudo systemctl restart network |
恭喜!
到此就算設定完成囉!
Pingback:CentOS 7 架站教學彙整 (Apache 2.4 + MySQL 5.7 + php 7 + phpMyAdmin + SSH + sFTP) - BrilliantCode.net
step8跟step9重覆了
真的欸…感覺是寫的過程精神不濟,渾然不知寫了兩個一樣的步驟XDD
感謝提醒