Konfigurace sítě

From Gentoo Wiki
Jump to:navigation Jump to:search
This page is a translated version of the page Handbook:AMD64/Installation/Networking and the translation is 100% complete.
AMD64 Handbook
Instalace
O instalaci
Výběr média
Konfigurace sítě
Příprava disků
Instalace stage3
Instalace základního systému
Konfigurace jádra
Konfigurace systému
Instalace nástrojů
Konfigurace zavaděče
Dokončení
Práce s Gentoo
Úvod do Portage
Přepínače USE
Funkce portage
Systém initskriptů
Proměnné prostředí
Práce s Portage
Soubory a adresáře
Proměnné
Mísení softwarových větví
Doplňkové nástroje
Vlastní strom Portage
Pokročilé funkce
Konfigurace sítě
Začínáme
Pokročilá konfigurace
Modulární síťování
Bezdrátové sítě
Přidání funkcí
Dynamická správa

Je možné, že to prostě funguje?

Pokud je systém zapojen do sítě ethernet s DHCP serverem, je velmi pravděpodobné, že síť byla nastavena automaticky. Pokud je tomu tak, pak spousta příkazů pracujících se sítí, které jsou součástí instalačního CD, jako jsou mezi jinými ssh, scp, ping, irssi, wget a links, budou bezprostředně fungovat.

Použití DHCP

DHCP (Dynamic Host Configuration Protocol) umožňuje automaticky obdržet informace o síti (IP adresu, síťovou masku, broadcast adresu, bránu, jmenné servery, atd.). Funguje pouze v případě, že je v síti DHCP server (nebo pokud poskytovatel připojení poskytuje službu DHCP). Aby vaše síťové rozhraní obdrželo tuto informaci automaticky, použijte dhcpcd:

DHCP requires that a server be running on the same Layer 2 (Ethernet) segment as the client requesting a lease. DHCP is often used on RFC1918 (private) networks, but is also used to acquire public IP information from ISPs.

Tip
Official Gentoo boot media runs dhcpcd automatically at startup. This behavior can be disabled by adding the nodhcp argument to the boot media kernel commandline.

If it is not already running, dhcpcd can be started on enp1s0 with:

root #dhcpcd eth0

Někteří správci sítě vyžadují, aby systém použil název počítače a domény poskytované DHCP serverem. V takovém případě použijte příkaz:

root #dhcpcd -HD eth0

To stop dhcpcd, -x can be used:

root #dhcpcd -x
sending signal Term to pid 10831
waiting for pid 10831 to exit
See also
Dhcpcd usage

Kontrola sítě

A properly configured default route is a critical component of Internet connectivity, route configuration can be checked with:

root #ip route
default via 192.168.0.1 dev enp1s0

If no default route is defined, Internet connectivity is unavailable, and additional configuration is required.

Basic internet connectivity can be confirmed with a ping:

root #ping -c 3 1.1.1.1
Tip
It's helpful to start by pinging a known IP address instead of a hostname. This can isolate DNS issues from basic Internet connectivity issues.

Outbound HTTPS access and DNS resolution can be confirmed with:

root #curl --location gentoo.org --output /dev/null

Pokud vše funguje, můžete přeskočit zbytek této kapitoly a jít rovnou na další krok instalačních pokynů (Příprava disků).

If curl reports an error, but Internet-bound pings work, DNS may need configuration.

If Internet connectivity has not been established, first interface information should be verified, then:

Určete názvy rozhraní

If networking doesn't work out of the box, additional steps must be taken to enable Internet connectivity. Generally, the first step is to enumerate host network interfaces.

Jako alternativu k příkazu ifconfig můžete použít k rozlišení názvů rozhraní příkaz ip. Následující příklad ukazuje výstup ip addr (u jiného systému, tudíž zobrazená informace je odlišná od předchozího příkladu):

The link argument can be used to display network interface links:

root #ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
4: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP mode DEFAULT group default qlen 1000
    link/ether e8:40:f2:ac:25:7a brd ff:ff:ff:ff:ff:ff

The address argument can be used to query device address information:

root #ip addr
2: eno1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP group default qlen 1000
    link/ether e8:40:f2:ac:25:7a brd ff:ff:ff:ff:ff:ff
    inet 10.0.20.77/22 brd 10.0.23.255 scope global eno1
       valid_lft forever preferred_lft forever
    inet6 fe80::ea40:f2ff:feac:257a/64 scope link 
       valid_lft forever preferred_lft forever

The output of this command contains information for each network interface on the system. Entries begin with the device index, followed by the device name: enp1s0.

Tip
Pokud standardní příkaz ifcondif nezobrazí žádná rozhraní, zkuste použít stejný příkaz s volbou -a. Tato možnost donutí utilitu, aby ukázala všechna síťová rozhraní detekovaná v systému, ať už jsou v zapnutém nebo vypnutím stavu. Pokud je výstup příkazu ifconfig -a bez výsledku, pak to značí selhání hardwaru nebo nebyl do jádra nahrán ovladač rozhraní. Obě situace zasahují mimo záběr této příručky. Pro podporu kontaktuje #gentoo (webchat).

Ve zbývající části tohoto dokumentu budeme předpokládat, že rozhraní je pojmenováno eth0.

V důsledku posunu k předvídatelným názvům síťových rozhraní se pojmenování rozhraní mohou od starších konvencí eth0 docela lišit. Nejnovější instalační média mohou u běžných síťových rozhraní zobrazovat jména jako eno0, ens1 nebo enp5s0. Ve výstupu příkazu ifconfig hledejte rozhraní, které má IP adresu odpovídající místní síti.

Optional: Application specific configuration

The following methods are not generally required, but may be helpful in situations where additional configuration is required for Internet connectivity.

Volitelné: Konfigurace proxy serverů

Pokud k internetu přistupujete přes proxy server, musíte v průběhu instalace nastavit informace o proxy. Nastavení proxy je velmi jednoduché: zkrátka definujte proměnnou, která obsahuje informace o proxy serveru.

Certain text-mode web browsers such as links can also make use of environment variables that define web proxy settings; in particular for the HTTPS access it also will require the https_proxy environment variable to be defined. While Portage will be influenced without passing extra run time parameters during invocation, links will require proxy settings to be set.

Ve většině případů dostačuje, pokud se proměnný definuje za použití hostitelského jména serveru. Na příklad předpokládejme, že proxy má název proxy.gentoo.org s portem 8080.

Poznámka
The # symbol in the following commands is a comment. It has een added for clarity only and does not need to be typed when entering the commands.

Nastavení HTTP proxy (HTTP a HTTPS provoz):

root #export http_proxy="http://proxy.gentoo.org:8080"

Pokud proxy vyžaduje uživatelské jméno a heslo, použijte pro proměnnou následující syntaxi:

CODE Přidání uživatelského jména a hesla k proměnné proxy
http://username:password@proxy.gentoo.org:8080

Start links using the following parameters for proxy support:

user $links -http-proxy ${http_proxy} -https-proxy ${https_proxy}

Nastavení FTP proxy:

root #export ftp_proxy="ftp://proxy.gentoo.org:8080"

Start links using the following parameter for a FTP proxy:

user $links -ftp-proxy ${ftp_proxy}

Nastavení RSYNC proxy:

root #export RSYNC_PROXY="proxy.gentoo.org:8080"

Alternativa: Použití PPP

If PPPoE is required for Internet access, the Gentoo boot media includes the pppoe-setup script to simplify ppp configuration.

During setup, pppoe-setup will ask for:

  • The name of the Ethernet interface connected to the ADSL modem.
  • The PPPoE username and password.
  • DNS server IPs.
  • Whether or not a firewall is needed.
root #pppoe-setup
root #pppoe-start

In the event of failure, credentials in /etc/ppp/pap-secrets or /etc/ppp/chap-secrets should be verified. If credentials are correct, PPPoE Ethernet interface selection should be checked.

Alternativa: Použití PPTP

Pokud je vyžadována podpora PPTP, použijte program pptpclient, který je poskytován instalačními CD. Nejprve se však ujistěte o správnosti nastavení. Upravte soubor /etc/ppp/pap-secrets nebo /etc/ppp/chap-secrets, aby obsahoval správnou kombinaci uživatelského jména a hesla:

Edit /etc/ppp/pap-secrets or /etc/ppp/chap-secrets so it contains the correct username/password combination:

root #nano -w /etc/ppp/chap-secrets

Po té upravte /etc/ppp/options.pptp, pokud je to potřeba:

root #nano -w /etc/ppp/options.pptp

Jakmile je toto všechno hotové, spusťte pptp (společně s volbami, které nelze nastavit options.pptp) k připojení na server:

root #pptp <ip serveru>

Příprava bezdrátového připojení

Upozornění
Do not use WEP unless it is the only option. WEP provides essentially no security over an open network.
Poznámka
Příkaz iw může být podporován pouze na určitých architekturách. Pokud není příkaz k dispozici, jestli je pro vaši současnou architekturu k dispozici balíček net-wireless/iw. Příkaz iw bude nedostupný, dokud nebude balíček net-wireless/iw nainstalován.

Pokud používáte bezdrátovou (802.11) kartu, je nutné nastavit parametry bezdrátového připojení, bez toho se nejde dostat dál. Ke zjištění současného nastavení bezdrátové karty lze použít příkaz iw. Po spuštění iw zobrazí něco podobného tomuto:

root #iw dev wlp9s0 info
Interface wlp9s0
	ifindex 3
	wdev 0x1
	addr 00:00:00:00:00:00
	type managed
	wiphy 0
	channel 11 (2462 MHz), width: 20 MHz (no HT), center1: 2462 MHz
	txpower 30.00 dBm

Pokud chcete zkontrolovat současné připojení:

root #iw dev wlp9s0 link
Not connected.

nebo

root #iw dev wlp9s0 link
Connected to 00:00:00:00:00:00 (on wlp9s0)
	SSID: GentooNode
	freq: 2462
	RX: 3279 bytes (25 packets)
	TX: 1049 bytes (7 packets)
	signal: -23 dBm
	tx bitrate: 1.0 MBit/s
Poznámka
Název zařízení některých bezdrátových karet může znít wlan0 nebo ra0 namísto wlp9s0. Ke zjištění správného názvu zařízení spusťte ip link.

Pro většinu uživatelů bude potřebné změnit pouze dvě nastavení, aby se mohli připojit, ESSID (tj. název bezdrátové sítě) a, volitelně, WEP klíč.

  • Nejprve se ujistěte, že je rozhraní aktivní:
root #ip link set dev wlp9s0 up
  • Pro připojení k otevřené síti s názvem :GentooNode":
root #iw dev wlp9s0 connect -w GentooNode
  • Pro připojení s hexovým WEP klíčem, přidejte před kód d::
root #iw dev wlp9s0 connect -w GentooNode key 0:d:1234123412341234abcd
  • Pro připojení s ASCII WEP klíčem, vložte před klíč s::
root #iw dev wlp9s0 connect -w GentooNode key 0:some-password
Poznámka
Pokud bezdrátová síť používá WPA nebo WPA2, je nutné použít wpa_supplicant. Pokud chcete načerpat více informací o konfiguraci bezdrátových sítí v Gentoo Linuxu, přečtěte si prosím kapitolu o bezdrátových sítích Příručky Gentoo.

Ověřte si bezdrátové nastavení opět pomocí iw dev wlp9s0 link. Jakmile bezdrát funguje, pokračujte v nastavení IP úrovně sítě, tak jak je to popsáno v následující sekci (Terminologie sítí) nebo použijte nástroj net-setup jak bylo již dříve popsáno.

Automatická konfigurace sítě

In cases where automatic network configuration is unsuccessful, the Gentoo boot media provides scripts to aid in network configuration. net-setup can be used to configure wireless network information and static IPs.

root #net-setup eth0

net-setup se vás zeptá na několik otázek o vaší síti. Jakmile bude vše hotové, síťové připojení by mělo fungovat. Vyzkoušejte ho tak, jak je popsáno výše. Pokud je test pozitivní, gratulujeme. Přeskočte zbytek této sekce a pokračujte na Příprava disků.

Důležité
Network status should be tested after any configuration steps are taken. In the event that configuration scripts do not work, manual network configuration is required.

Porozumnění terminologii sítí

If all of the above fails, the network must be configured manually. This is not particularly difficult, but should be done with consideration. This section serves to clarify terminology and introduce users to basic networking concepts pertaining to manually configuring an Internet connection.

Tip
Some CPE (Carrier Provided Equipment) combines the functions of a router, access point, modem, DHCP server, and DNS server into one unit. It's important to differentiate the functions of a device from the physical appliance.

Interfaces and addresses

Network interfaces are logical representations of network devices. An interface needs an address to communicate with other devices on the network. While only a single address is required, multiple addresses can be assigned to a single interface. This is especially useful for dual stack (IPv4 + IPv6) configurations.

For consistency, this primer will assume the interface enp1s0 will be using the address 192.168.0.2.

Důležité
IP addresses can be set arbitrarily. As a result, it's possible for multiple devices to use the same IP address, resulting in an address conflict. Address conflicts should be avoided by using DHCP or SLAAC.
Tip
IPv6 typically uses StateLess Address AutoConfiguration (SLAAC) for address configuration. In most cases, manually setting IPv6 addresses is a bad practice. If a specific address suffix is preferred, interface identification tokens can be used.

Networks and CIDR

Once an address is chosen, how does a device know how to talk to other devices?

IP addresses are associated with networks. IP networks are contiguous logical ranges of addresses.

Classless Inter-Domain Routing or CIDR notation is used to distinguish network sizes.

  • The CIDR value, often notated starting with a /, represents the size of the network.
    • The formula 2 ^ (32 - CIDR) can be used to calculate network size.
    • Once network size is calculated, usable node count must be reduced by 2.
      • The first IP in a network is the Network address, and the last is typically the Broadcast address. These addresses are special and cannot be used by normal hosts.
Tip
The most common CIDR values are /24, and /32, representing 254 nodes and a single node respectively.

A CIDR of /24 is the de-facto default network size. This corresponds to a subnet mask of 255.255.255.0, where the last 8 bits are reserved for IP addresses for nodes on a network.

The notation: 192.168.0.2/24 can be interpreted as:

  • The address 192.168.0.2
  • On the network 192.168.0.0
  • With a size of 254 (2 ^ (32 - 24) - 2)
    • Usable IPs are in the range 192.168.0.1 - 192.168.0.254
  • With a broadcast address of 192.168.0.255
    • In most cases, the last address on a network is used as the broadcast address, but this can be changed.

Using this configuration, a device should be able to communicate with any host on the same network (192.168.0.0).

The Internet

Once a device is on a network, how does it know how to talk to devices on the Internet?

To communicate with devices outside of local networks, routing must be used. A router is simply a network device that forwards traffic for other devices. The term default route or gateway typically refers to whatever device on the current network is used for external network access.

Tip
It's a standard practice to make the gateway the first or last IP on a network.

If an Internet-connected router is available at 192.168.0.1, it can be used as the default route, granting Internet access.

To summarize:

  • Interfaces must be configured with an address and network information, such as the CIDR value.
  • Local network access is used to access a router on the same network.
  • The default route is configured, so traffic destined for external networks is forwarded to the gateway, providing Internet access.

The Domain Name System

Remembering IPs is hard. The Domain Name System was created to allow mapping between Domain Names and IP addresses.

Linux systems use /etc/resolv.conf to define nameservers to be used for DNS resolution.

Tip
Many routers can also function as a DNS server, and using a local DNS server can augment privacy and speed up queries through caching.

Many ISPs run a DNS server that is generally advertised to the gateway over DHCP. Using a local DNS server tends to improve query latency, but most public DNS servers will return the same results, so server usage is largely based on preference.

Ruční nastavení sítě

Interface address configuration

Důležité
When manually configuring IP addresses, the local network topology must be considered. IP addresses can be set arbitrarily; conflicts may cause network disruption.

To configure enp1s0 with the address 192.168.0.2 and CIDR /24:

root #ip address add 192.168.0.2/24 dev enp1s0
Tip
The start of this command can be shortened to ip a.

Default route configuration

Configuring address and network information for an interface will configure link routes, allowing communication with that network segment:

root #ip route
192.168.0.0/24 dev enp1s0 proto kernel scope link src 192.168.0.2
Tip
This command can be shortened to ip r.

The default route can be set to 192.168.0.1 with:

root #ip route add default via 192.168.0.1

DNS configuration

Nameserver info is typically acquired using DHCP, but can be set manually by adding nameserver entries to /etc/resolv.conf.

Upozornění
If dhcpcd is running, changes to /etc/resolv.conf will not persist. Status can be checked with ps x | grep dhcpcd.

nano is included in Gentoo boot media and can be used to edit /etc/resolv.conf with:

root #nano -w /etc/resolv.conf

Lines containing the keyword nameserver followed by a DNS server IP address are queried in order of definition:

FILE /etc/resolv.confUse Quad9 DNS.
nameserver 9.9.9.9
nameserver 149.112.112.112
FILE /etc/resolv.confUse Cloudflare DNS.
nameserver 1.1.1.1
nameserver 1.0.0.1

DNS status can be checked by pinging a domain name:

root #ping -c 3 gentoo.org

Once connectivity has been verified, continue with Preparing the disks.