The network is automatically configured during the initial installation. If Network Manager gets installed (which is generally the case for full desktop installations), then it might be that no configuration is actually required (for example, if you rely on DHCP on a wired connection and have no specific requirements). If a configuration is required (for example, for a WiFi interface), then it will create the appropriate file in /etc/NetworkManager/system-connections/
.
If Network Manager is not installed, then the installer will configure
ifupdown by creating the
/etc/network/interfaces
file. A line starting with
auto
gives a list of interfaces to be automatically configured on boot by the
networking
service. When there are many interfaces, it is good practice to keep the configuration in different files inside
/etc/network/interfaces.d/
as described in sidebar
基本 結尾是 .d
的資料夾名稱.
In a server context, ifupdown is thus the network configuration tool that you usually get. That is why we will cover it in the next sections. For more information about the syntax of the configuration file please read interfaces(5).
電腦使用 Ethernet 網路卡時,必須以下列的方法之一組態 IP 網路。最簡單的方式是以 DHCP 動態組態,需要在地網路的 DHCP 伺服器。可以使用與下例 hostname
設定的主機名稱。DHCP 伺服器就會送出組態設定給適當的網路。
範例 8.1. DHCP 組態
auto enp0s31f6
iface enp0s31f6 inet dhcp
hostname arrakis
“靜態” 組態必須以固定方式指明網路設定。至少包括 IP 網址及次網路遮罩;有時也列出網路及廣播位址。必須以閘道指出連結外部的路由器。
範例 8.2. 靜態組態
auto enp0s31f6
iface enp0s31f6 inet static
address 192.168.0.3/24
broadcast 192.168.0.255
network 192.168.0.0
gateway 192.168.0.1
8.2.2. Wireless Interface
Getting wireless network cards to work can be a bit more challenging. First of all, they often require the installation of proprietary firmwares which are not installed by default in Debian. Then wireless networks rely on cryptography to restrict access to authorized users only, this implies storing some secret key in the network configuration. Let's tackle those topics one by one.
8.2.2.1. Installing the required firmwares
First you have to enable the non-free repository in APT's sources.list file: see
節 6.1, “寫入 sources.list
檔案” for details about this file. Many firmware are proprietary and are thus located in this repository. You can try to skip this step if you want, but if the next step doesn't find the required firmware, retry after having enabled the non-free section.
Then you have to install the appropriate firmware-*
packages. If you don't know which package you need, you can install the isenkram package and run its isenkram-autoinstall-firmware
command. The packages are often named after the hardware manufacturer or the corresponding kernel module: firmware-iwlwifi for Intel wireless cards, firmware-atheros for Qualcomm Atheros, firmware-ralink for Ralink, etc. A reboot is then recommended because the kernel driver usually looks for the firmware files when it is first loaded and no longer afterwards.
8.2.2.2. Wireless specific entries in /etc/network/interfaces
ifupdown is able to manage wireless interfaces but it needs the help of the wpasupplicant package which provides the required integration between ifupdown and the wpa_supplicant
command used to configure the wireless interfaces (when using WPA/WPA2 encryption). The usual entry in /etc/network/interfaces
needs to be extended with two supplementary parameters to specify the name of the wireless network (aka its SSID) and the Pre-Shared Key (PSK).
範例 8.3. DHCP configuration for a wireless interface
auto wlp4s0
iface wlp4s0 inet dhcp
wpa-ssid Falcot
wpa-psk ccb290fd4fe6b22935cbae31449e050edd02ad44627b16ce0151668f5f53c01b
The wpa-psk
parameter can contain either the plain text passphrase or its hashed version generated with wpa_passphrase SSID passphrase
. If you use an unencrypted wireless connection, then you should put a wpa-key-mgmt NONE
and no wpa-psk
entry. For more information about the possible configuration options, have a look at /usr/share/doc/wpasupplicant/README.Debian.gz
.
At this point, you should consider restricting the read permissions on /etc/network/interfaces
to the root user only since the file contains a private key that not all users should have access to.
8.2.3. 經由 PSTN 數據機的 PPP 連結
點對點 (PPP) 連結建立斷續的連結;這是電話數據機最常見的連結方式 (“PSTN 數據機”,經由公共交換電話網路)。
電話數據機需要帳號才能連結,包括電話號碼、使用者名稱、密碼、以及認證協定。這種連結 Debian 同名套件內的使用 pppconfig
工具。預設使用的名稱是 提供者
(做為網際網路服務提供者)。對認證協定有疑義時,選擇 PAP:大多數網際網路服務提供者使用它。
組態之後,就可以使用 pon
命令 (提供者
的預設值不適用時,將連結的名稱當成參數)。以 poff
命令斷線。這兩個令可以被根使用者執行,或位在 dip
群組的其他使用者。
“ADSL 數據機” 一辭包括不同功能的多種設備。使用 Linux 的數據機有 Ethernet 介面 (不祗是 USB 介面)。這是極為普遍的數據機;大部份的 ADSL 網際網路服務商出借 (或出租) 一個含 Ethernet 介面的 “盒子”。視其類型而有不同的設定。
部份 Ethernet 數據機使用 PPPOE 協定 (乙太網上的對等協定,Point to Point Protocol over Ethernet)。pppoeconf
工具 (位於同名套件內) 將組態其連結。修改 /etc/ppp/peers/dsl-provider
檔案內容時,採用 /etc/ppp/pap-secrets
與 /etc/ppp/chap-secrets
檔案的內容。建議全盤接納所有的提議。
組態完成之後,以命令 pon dsl-provider
開啟 ADSL 連結,並以命令 poff dsl-provider
斷線。
PPTP (點對點隧道協議,Point-to-Point Tunneling Protocol) 協定由微軟創製。在 ADSL 的初期就已布置,取代 PPPOE。若被強迫使用此協定,參見
節 10.3.4, “PPTP”。
以 Ethernet 纜線 (跳線) 連線電腦的數據機,可以在電腦以 DHCP 組態網路連結;數據機自動成為閘道且執行路由的功能 (就是管理電腦與網際網路的流量)。
大部份的 “ADSL 路由器” 也能這麼做,網際網路服務供應商提供的 ADSL 數據機也具有此功能。
Falcot 公司的工程師擁有專業用的筆電,同時也在家裡使用它。根據使用場所的不同,網路有不同的組態方式。在家裡,可能使用 WiFi 網路 (以 WPA 鑰保護),在工作場合則使用較安全與頻寬更充足的固接網路。
為了避免人工連結與斷線對應的網路介面,管理者在漫遊機器安裝 network-manager 套件。此軟體可以讓使用者從圖形桌面的小圖示,在多個網路間切換。按下此圖示即顯示可用的網路 (固接與無線),藉以選擇其中之一。此程式儲存曾連結網路的組態,斷線時自動選擇最佳的網路。
為了達到這個目的,程式分為兩個部份:在根部執行後台進程並組態網路介面與使用者介面控制該後台進程。PolicyKit 處理必要的權限以控制此程式,然後由 Debian 組態 PolicyKit 讓 netdev 群組成員可以新增或修改 Network Manager 的連結。
Network Manager knows how to handle various types of connections (DHCP, manual configuration, local network), but only if the configuration is set with the program itself. This is why it will systematically ignore all network interfaces in /etc/network/interfaces
and /etc/network/interfaces.d/
for which it is not suited. Since Network Manager doesn't give details when no network connections are shown, the easy way is to delete from /etc/network/interfaces
any configuration for all interfaces that must be managed by Network Manager.
在初始安裝階段選擇 “桌面環境”的工作,就能夠預設安裝此程式。