Network configuration (Polski)
W tym artykule opisano, jak skonfigurować połączenia sieciowe w warstwie sieciowej i wyższych. Na przykładzie /Ethernet i Wi-fi[broken link: invalid section].
Sprawdzanie połączania
Aby rozwiązać problemy z połączeniem z połączaniem, sprawdź następujące warunki i upewnij się, że je spełniasz:
- Twój interfejs sieciowy[broken link: invalid section] jest widoczny i włączony. W przeciwnym razie sprawdź sterownik urządzenia - patrz /Ethernet#Device driver i /Wireless#Device driver.
- Masz połączanie z siecią. Przewód jest podłączony lub jesteś podłączony do sieci bezprzewodowej.
- Twój interfejs sieciowy ma adres IP[broken link: invalid section].
- Twoja tabela trasowania[broken link: invalid section] jest poprawnie skonfigurowana.
- Możesz wysłać ping na lokalny adres IP (np. bramę domyślną).
- Możesz wysłać ping na publiczny adres (np.
8.8.8.8
, który jest serwerem Google DNS i jest wygodnym adresem do testowania). -
Check if you can resolve domain names (np.
archlinux.org
).
Ping
ping służy do sprawdzenia, czy możesz dotrzeć do hosta i mierzenia opóźnienia z połączania z danym hostem.
$ ping www.example.com
PING www.example.com (93.184.216.34): 56(84) data bytes 64 bytes from 93.184.216.34: icmp_seq=0 ttl=56 time=11.632 ms 64 bytes from 93.184.216.34: icmp_seq=1 ttl=56 time=11.726 ms 64 bytes from 93.184.216.34: icmp_seq=2 ttl=56 time=10.683 ms ...
Przy każdej otrzymanej odpowiedzi narzędzie ping wydrukuje wiersz podobny do powyższego. Aby uzyskać więcej informacji zobacz ping(8) manual. Pamiętaj, że komputery można skonfigurować tak, aby nie odpowiadały na żądania echa ICMP. [1]
Jeśli nie otrzymasz odpowiedzi, może to być związane z domyślną bramą lub dostawcą usług internetowych (ISP). Możesz uruchomić traceroute w celu dalszej diagnozy trasy do hosta.
ping: icmp open socket: Operation not permitted
when executing ping, try to re-install the iputils package.Zarządzanie siecią
Aby skonfigurować połączenie sieciowe, wykonaj następujące kroki:
- Upewnij się, że interfejs sieciowy[broken link: invalid section] jest widoczny i włączony.
- Połącz się z siecią. Podłącz przewód Ethernet lub połącz się z siecią bezprzewodową.
- Configure your network connection:
- Statyczny adres IP[broken link: invalid section]
- Dynamiczny adres IP: Użyj DHCP
dhcpcd@interface.service
) dla przewodowych urządzeń sieciowych[dead link 2021-07-05 ⓘ] przy rozruchu.net-tools
Arch Linux wycofał net-tools na rzecz iproute2.[2]
Przestarzałe polecenie | Polecenie alternatywne |
---|---|
arp | ip neighbor |
ifconfig | ip address, ip link |
netstat | ss |
route | ip route |
Aby uzyskać więcej informacji zobacz ten artykuł (po angielsku).
iproute2
iproute2 należy do base meta package i zapewnia interfejs wiersza polecenia ip(8) używany do zarządzania interfejsami sieciowymi[broken link: invalid section], adresami IP[broken link: invalid section] tablicami trasowania[broken link: invalid section]. Należy pamiętać, że konfiguracja wykonana przy użyciu ip
zostanie utracona po restarcie. W celu trwałej konfiguracji można użyć network manager lub zautomatyzować polecenia ip za pomocą skryptów i systemd units. Zauważ też, że ip
polecenia ogólnie mogą być skrócone, dla jasności zostały one jednak określone w tym artykule.
Interfejsy sieciowe
Domyślnie udev przypisuje nazwy do interfejsów sieciowych za pomocą Przewidywalnych nazw interfejsów sieciowych, z których przedrostkami łączyą się nazwy en
(wired/Ethernet), wl
(wireless/WLAN), i ww
(WWAN).
Lista interfejsów sieciowych
Nazwy interfejsów przewodowych i bezprzewodowych można znaleźć za pośrednictwem ls /sys/class/net
lub ip link
. Zauważ, że lo
jest urządzenie pętli i nie jest używane do nawiązywania połączeń sieciowych.
Nazwy urządzeń bezprzewodowych można również pobrać za pomocą iw dev
. Zobacz też /Wireless#Get the name of the interface.
Jeśli Twojego interfejsu sieciowego nie ma na liście, upewnij się, że sterownik urządzenia został pomyślnie załadowany. Zobacz /Ethernet#Device driver lub /Wireless#Device driver.
Włączanie i wyłączanie interfejsów sieciowych
Interfejsy sieciowe można włączać / wyłączać za pomocą ip link set interface up|down
, zobacz ip-link(8).
Aby sprawdzić status interfejsu eth0
:
$ ip link show dev eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state DOWN mode DEFAULT qlen 1000 ...
The UP
in <BROADCAST,MULTICAST,UP,LOWER_UP>
is what indicates the interface is up, not the later state DOWN
.
eth0
, usunięcie go spowoduje również usunięcie trasy, a przywrócenie go z powrotem nie spowoduje automatycznego przywrócenia domyślnej trasy. Zobacz #Routing table[broken link: invalid section] aby ją przywrócić.Statyczny adres IP
Statyczny adres IP można skonfigurować za pomocą większości standardowych menedżerów sieci[broken link: invalid section] zobacz też dhcpcd.
Aby ręcznie skonfigurować statyczny adres IP, dodaj adres IP zgodnie z opisem w #Adres IP, skonfiguruj tablice trasowania[broken link: invalid section] i skonfiguruj serwery DNS.
Adres IP
Adresami IP zarządza się za pomocą ip-address(8).
Wypisz adresy IP:
$ ip address show
Dodaj adres IP do interfejsu:
# ip address add address/prefix_len broadcast + dev interface
- Uwaga:
- adres jest podany w notacji CIDR aby również podać maskę podsieci
-
+
to specjalny symbol, który powoduje, że adres rozgłoszeniowy jest wyliczany z adresu IP i maski podsieci
- Note: Upewnij się, że ręcznie przypisane adresy IP nie powodują konfliktu z adresami przydzielonymi przez DHCP.
Usuń adres IP z interfejsu:
$ ip address del address/prefix_len dev interface
Usuń wszystkie adresy spełniające kryteria, np. Określonego interfejsu:
$ ip address flush dev interface
Tablica trasowania
- Note: Używam polskiej nazwy trasownik zamiast angielskiej router.
Tabela trasowania jest używana do określenia, czy można dotrzeć do adresu IP, bezpośrednio lub przez bramę (trasownik), jeśli dany adres nie należy do naszej sieci i nie jest ustawiana brama dla sieci do której należy dany adres, używana jest brama domyślna.
The routing table is managed using ip-route(8).
PREFIX is either a CIDR notation or default
for the default gateway.
Wyświetl trasy IPv4:
$ ip route show
Wyświetl trasy IPv6:
$ ip -6 route
Dodaj trasę:
# ip route add PREFIX via address dev interface
Usuń trasę:
# ip route del PREFIX via address dev interface
PREFIX - adres sieci docelowej z maską podsieci w postaci CIDR na przykład 192.168.4.0/24 address - adres bramy przez którą mają być przesyłane pakiety interface - nasz interfejs sieciowy (karta sieciowa) dla którego ustawiamy trasę
DHCP
Serwer DHCP przydziela przydziela adres IP, maskę podsieci, adres bramy domyślnej i ewentualnie adresy serwerów DNS i paru innych usług.
Aby korzystać z DHCP, potrzebujesz serwera w sieci i klienta na komputerze:
Klient | pakiet | Archiso | Uwagi | Systemd units |
---|---|---|---|---|
dhcpcd | dhcpcd | Yes | DHCP, DHCPv6, ZeroConf, static IP |
dhcpcd.service , dhcpcd@interface.service
|
ISC dhclient | dhclient | Yes | DHCP, DHCPv6, BOOTP, static IP |
dhclient@interface.service
|
- Nie należy uruchamiać dwóch klientów DHCP jednocześnie.
- Zamiast bezpośredniego korzystania z klienta DHCP można również użyć network manager[broken link: invalid section].
Servers
Server | Package | IPv4 | IPv6 | GUI | Interfaces | Storage backend(s) | Note |
---|---|---|---|---|---|---|---|
dhcpd | dhcp | Yes | Yes | Glass-ISC-DHCP | ? | File | |
dnsmasq | dnsmasq | Yes | Yes | No | ? | File | Also DNS, PXE and TFTP |
Kea | kea | Yes | Yes | Kea-Anterius (Experimental) | REST, RADIUS and NETCONF | File, MySQL, PostgreSQL and Cassandra | Also DNS |
Menadżerzy sieci
Menedżer sieci pozwala zarządzać ustawieniami połączeń sieciowych przy użyciu tak zwany profili sieciowych, aby ułatwić między sieciami.
Network manager | GUI | Archiso [3] | CLI tools |
PPP support (e.g. 3G modem) |
DHCP client | Systemd units |
---|---|---|---|---|---|---|
ConnMan | 8 unofficial | No | connmanctl(1) | Yes (with ofonoAUR) | internal |
connman.service
|
netctl | 2 unofficial | Yes | netctl(1), wifi-menu | Yes | dhcpcd or dhclient |
netctl-ifplugd@interface.service , netctl-auto@interface.service
|
NetworkManager | Yes | No | nmcli(1), nmtui(1) | Yes | internal, dhcpcd or dhclient |
NetworkManager.service
|
systemd-networkd | No | Yes (base) | networkctl(1) | No | internal |
systemd-networkd.service , systemd-resolved.service
|
Wicd | Yes | No | wicd-cli(8)[dead link 2020-02-22], wicd-curses(8)[dead link 2020-02-22] | No | dhcpcd |
wicd.service
|
Zobacz też List of applications#Network managers.
Ustaw nazwę hosta
Nazwa hosta to unikatowa nazwa utworzona w celu identyfikacji komputera w sieci ustawiony w /etc/hostname
—patrz hostname(5) i hostname(7) po więcej informacji. Plik może zawierać nazwę domeny. Aby ustawić nazwę hosta, edytuj /etc/hostname
:
/etc/hostname
nazwaMojegoHosta
Możesz też użyć hostnamectl(1):
# hostnamectl set-hostname nazwaMojegoHosta
Aby tymczasowo ustawić nazwę hosta (do ponownego uruchomienia), użyj hostname(1) z inetutils:
# hostname nazwaMojegoHosta
Aby ustawić „ładną” nazwę hosta i inne metadane komputera, zobacz machine-info(5).
Local hostname resolution
The myhostname
Name Service Switch (NSS) module of systemd provides local hostname resolution without having to edit /etc/hosts
(hosts(5)). It is enabled by default.
Some clients may however still rely on /etc/hosts
, see [4] [5] for examples.
To configure the hosts file, add the following lines to /etc/hosts
:
127.0.0.1 localhost ::1 localhost 127.0.1.1 myhostname.localdomain myhostname
/etc/hosts
is significant. The first string is considered the canonical hostname and may be appended with parent domains, where domain components are separated by a dot (ie. .localdomain
above). All following strings on the same line are considered aliases. See hosts(5) for more info.As a result the system resolves to both entries:
$ getent hosts
127.0.0.1 localhost 127.0.0.1 localhost 127.0.1.1 myhostname.localdomain myhostname
For a system with a permanent IP address, that permanent IP address should be used instead of 127.0.1.1
.
Local network hostname resolution
To make your machine accessible in your LAN via its hostname you can:
- edytuj plik
/etc/hosts
dla każdego hosta, patrz hosts(5) - ustaw nazwy hostów na DNS server i zmuś urządzenia w twojej sieci LAN jego użycia (np. przez #DHCP)
- lub prostszy sposób: użyj usługiZeroconf:
- Rozpoznawanie nazw hostów NetBIOS Microsoftu. Dostarczone przez Samba w systemie Linux. Wymaga tylko uruchomienia
nmb.service
. Komputery z uruchomionym systemem Windows, macOS lub Linux znmb
będą mogły znaleźć Twój komputer. - Rozpoznawanie nazw hostów za pomocą mDNS. Dostarczoną przez
nss_mdns
z Avahi (patrz Avahi#Hostname resolution po więcej informacji) lub systemd-resolved. Komputery z macOS lub Linux z uruchomionym Avahi lub systemd-resolved, będą widzieć twoją nazwę hosta. Starsze trzydziestodwubitowe systemy z rodziny Windows nie obsługują mDNS.
- Rozpoznawanie nazw hostów NetBIOS Microsoftu. Dostarczone przez Samba w systemie Linux. Wymaga tylko uruchomienia
Tips and tricks
Change interface name
You can change the device name by defining the name manually with an udev-rule. For example:
/etc/udev/rules.d/10-network.rules
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="net1" SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="ff:ee:dd:cc:bb:aa", NAME="net0"
These rules will be applied automatically at boot.
A couple of things to note:
- To get the MAC address of each card, use this command:
cat /sys/class/net/device_name/address
- Make sure to use the lower-case hex values in your udev rules. It does not like upper-case.
If the network card has a dynamic MAC, you can use DEVPATH
, for example:
/etc/udev/rules.d/10-network.rules
SUBSYSTEM=="net", DEVPATH=="/devices/platform/wemac.*", NAME="int" SUBSYSTEM=="net", DEVPATH=="/devices/pci*/*1c.0/*/net/*", NAME="en"
To get the DEVPATH
of all currently-connected devices, see where the symlinks in /sys/class/net/
lead. For example:
file /sys/class/net/*
/sys/class/net/enp0s20f0u4u1: symbolic link to ../../devices/pci0000:00/0000:00:14.0/usb2/2-4/2-4.1/2-4.1:1.0/net/enp0s20f0u4u1 /sys/class/net/enp0s31f6: symbolic link to ../../devices/pci0000:00/0000:00:1f.6/net/enp0s31f6 /sys/class/net/lo: symbolic link to ../../devices/virtual/net/lo /sys/class/net/wlp4s0: symbolic link to ../../devices/pci0000:00/0000:00:1c.6/0000:04:00.0/net/wlp4s0
The device path should match both the new and old device name, since the rule may be executed more than once on bootup. For example, in the second rule, "/devices/pci*/*1c.0/*/net/enp*"
would be wrong since it will stop matching once the name is changed to en
. Only the system-default rule will fire the second time around, causing the name to be changed back to e.g. enp1s0
.
If you are using a USB network device (e.g. Android phone tethering) that has a dynamic MAC address and you want to be able to use different USB ports, you could use a rule that matched depending on vendor and product ID instead:
/etc/udev/rules.d/10-network.rules
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="12ab", ATTRS{idProduct}=="3cd4", NAME="net2"
To test your rules, they can be triggered directly from userspace, e.g. with udevadm --debug test /sys/class/net/*
. Remember to first take down the interface you are trying to rename (e.g. ip link set enp1s0 down
).
net0
, net1
, wifi0
, wifi1
. For further details please see the systemd documentation.Revert to traditional interface names
If you would prefer to retain traditional interface names such as eth0, Predictable Network Interface Names can be disabled by masking the udev rule:
# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
Alternatively, add net.ifnames=0
to the kernel parameters.
Set device MTU and queue length
You can change the device MTU and queue length by defining manually with an udev-rule. For example:
/etc/udev/rules.d/10-network.rules
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wl*", ATTR{mtu}="1500", ATTR{tx_queue_len}="2000"
-
mtu
: For PPPoE, the MTU should be no larger than 1492. You can also set MTU via systemd.netdev(5). -
tx_queue_len
: Small value for slower devices with a high latency like modem links and ISDN. High value is recommend for server connected over the high-speed Internet connections that perform large data transfers.
Bonding or LAG
See netctl#Bonding or Wireless bonding.
IP address aliasing
IP aliasing is the process of adding more than one IP address to a network interface. With this, one node on a network can have multiple connections to a network, each serving a different purpose. Typical uses are virtual hosting of Web and FTP servers, or reorganizing servers without having to update any other machines (this is especially useful for nameservers).
Example
To manually set an alias, for some NIC, use iproute2 to execute
# ip addr add 192.168.2.101/24 dev eth0 label eth0:1
To remove a given alias execute
# ip addr del 192.168.2.101/24 dev eth0:1
Packets destined for a subnet will use the primary alias by default. If the destination IP is within a subnet of a secondary alias, then the source IP is set respectively. Consider the case where there is more than one NIC, the default routes can be listed with ip route
.
Promiscuous mode
Toggling promiscuous mode will make a (wireless) NIC forward all traffic it receives to the OS for further processing. This is opposite to "normal mode" where a NIC will drop frames it is not intended to receive. It is most often used for advanced network troubleshooting and packet sniffing.
/etc/systemd/system/promiscuous@.service
[Unit] Description=Set %i interface in promiscuous mode After=network.target [Service] Type=oneshot ExecStart=/usr/bin/ip link set dev %i promisc on RemainAfterExit=yes [Install] WantedBy=multi-user.target
If you want to enable promiscuous mode on interface eth0
run enable promiscuous@eth0.service
.
Investigate sockets
ss is a utility to investigate network ports and is part of the iproute2 package. It has a similar functionality to the deprecated netstat utility.
Common usage includes:
Display all TCP Sockets with service names:
$ ss -at
Display all TCP Sockets with port numbers:
$ ss -atn
Display all UDP Sockets:
$ ss -au
For more information see ss(8).
Troubleshooting
The TCP window scaling problem
TCP packets contain a "window" value in their headers indicating how much data the other host may send in return. This value is represented with only 16 bits, hence the window size is at most 64Kb. TCP packets are cached for a while (they have to be reordered), and as memory is (or used to be) limited, one host could easily run out of it.
Back in 1992, as more and more memory became available, RFC 1323 was written to improve the situation: Window Scaling. The "window" value, provided in all packets, will be modified by a Scale Factor defined once, at the very beginning of the connection. That 8-bit Scale Factor allows the Window to be up to 32 times higher than the initial 64Kb.
It appears that some broken routers and firewalls on the Internet are rewriting the Scale Factor to 0 which causes misunderstandings between hosts. The Linux kernel 2.6.17 introduced a new calculation scheme generating higher Scale Factors, virtually making the aftermaths of the broken routers and firewalls more visible.
The resulting connection is at best very slow or broken.
How to diagnose the problem
First of all, let us make it clear: this problem is odd. In some cases, you will not be able to use TCP connections (HTTP, FTP, ...) at all and in others, you will be able to communicate with some hosts (very few).
When you have this problem, the dmesg
's output is OK, logs are clean and ip addr
will report normal status... and actually everything appears normal.
If you cannot browse any website, but you can ping some random hosts, chances are great that you are experiencing this problem: ping uses ICMP and is not affected by TCP problems.
You can try to use Wireshark. You might see successful UDP and ICMP communications but unsuccessful TCP communications (only to foreign hosts).
Ways of fixing it
Bad
To fix it the bad way, you can change the tcp_rmem
value, on which Scale Factor calculation is based. Although it should work for most hosts, it is not guaranteed, especially for very distant ones.
# echo "4096 87380 174760" > /proc/sys/net/ipv4/tcp_rmem
Good
Simply disable Window Scaling. Since Window Scaling is a nice TCP feature, it may be uncomfortable to disable it, especially if you cannot fix the broken router. There are several ways to disable Window Scaling, and it seems that the most bulletproof way (which will work with most kernels) is to add the following line to /etc/sysctl.d/99-disable_window_scaling.conf
(see also sysctl):
net.ipv4.tcp_window_scaling = 0
Best
This problem is caused by broken routers/firewalls, so let us change them. Some users have reported that the broken router was their very own DSL router.
More about it
This section is based on the LWN article TCP window scaling and broken routers and an archived Kernel Trap article: Window Scaling on the Internet.
There are also several relevant threads on the LKML.
See also
- Linux Network Administrators Guide
- Debian Reference: Network setup
- RHEL7: Networking Guide
- Linux Home Networking[dead link 2021-05-17 ⓘ]
- Monitoring and tuning the Linux Networking Stack: Receiving data
- Monitoring and tuning the Linux Networking Stack: Sending data
- Tracing a packet journey using tracepoints, perf and eBPF