Network configuration: Difference between revisions

From ArchWiki
m (added Domain name resolution to Related articles)
 
(429 intermediate revisions by 67 users not shown)
Line 1: Line 1:
[[Category:Network configuration]]
[[Category:Network configuration]]
[[cs:Network configuration]]
[[el:Network configuration]]
[[es:Network configuration]]
[[es:Network configuration]]
[[fr:Connexions reseau]]
[[fi:Network configuration]]
[[it:Network configuration]]
[[it:Network configuration]]
[[ja:ネットワーク設定]]
[[ja:ネットワーク設定]]
[[nl:Network configuration]]
[[pt:Network configuration]]
[[pt:Network configuration]]
[[ro:Configurare retea]]
[[ru:Network configuration]]
[[ru:Network configuration]]
[[sk:Network configuration]]
[[zh-hans:Network configuration]]
[[zh-hans:Network configuration]]
[[zh-hant:Network configuration]]
{{Related articles start}}
{{Related articles start}}
{{Related|Jumbo frames}}
{{Related|Network Debugging}}
{{Related|Firewalls}}
{{Related|Firewalls}}
{{Related|Wireless network configuration}}
{{Related|Internet sharing}}
{{Related|Network bridge}}
{{Related|Router}}
{{Related|List of applications/Internet#Network managers}}
{{Related|Domain name resolution}}
{{Related|Network Debugging}}
{{Related articles end}}
{{Related articles end}}


This page explains how to set up a '''wired''' connection to a network. If you need to set up '''wireless''' networking see the [[Wireless network configuration]] page.
This article describes how to configure network connections on [[Wikipedia:OSI layer 3|OSI layer 3]] and above. Medium-specifics are handled in the [[/Ethernet]] and [[/Wireless]] subpages.


== Check the connection ==
== Check the connection ==


The basic installation procedure typically has a functional network configuration. Use {{man|8|ping}} to check the connection:
{{Expansion|Step 4. is unclear, [[#Routing table]] does not explain what a correct setup looks like.}}
 
To troubleshoot a network connection, go through the following conditions and ensure that you meet them:
 
# Your [[#Network interfaces|network interface]] is listed and enabled. Otherwise, check the device driver – see [[/Ethernet#Device driver]] or [[/Wireless#Device driver]].
# You are connected to the network. The cable is plugged in or you are [[/Wireless|connected to the wireless LAN]].
# Your network interface has an [[#IP addresses|IP address]].
# Your [[#Routing table|routing table]] is correctly set up.
# You can [[#Ping|ping]] a local IP address (e.g. your default gateway).
# You can [[#Ping|ping]] a public IP address (e.g. {{ic|9.9.9.9}}, which is a DNS server operated by the Quad9 Foundation and is a convenient address to test with).
# [[Domain name resolution#Resolve a domain name using NSS|Check if you can resolve domain names]] (e.g. {{ic|archlinux.org}}).
 
=== Ping ===
 
[[Wikipedia:Ping (networking utility)|ping]] is used to test if you can reach a host.


{{hc|$ ping www.google.com|2=
{{hc|$ ping www.example.com|2=
PING www.l.google.com (74.125.132.105) 56(84) bytes of data.
PING www.example.com (93.184.216.34) 56(84) bytes of data.
64 bytes from wb-in-f105.1e100.net (74.125.132.105): icmp_req=1 ttl=50 time=17.0 ms
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=1 ttl=56 time=11.632 ms
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=2 ttl=56 time=11.726 ms
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=3 ttl=56 time=10.683 ms
...
...
}}
}}


If the ping is successful (you see 64 bytes messages as above), then the network is configured. Press {{ic|Control-C}} to stop the ping.
For every reply received, the ''ping'' utility will print a line like the above until you interrupt ({{ic|Ctrl+c}}) it interactively. For more information see the {{man|8|ping}} manual. Note that computers can be configured not to respond to ICMP echo requests. [https://unix.stackexchange.com/questions/412446/how-to-disable-ping-response-icmp-echo-in-linux-all-the-time]


If the ping failed with an ''Unknown hosts'' error, it  means that your machine was unable to resolve this domain name. It may be related to your service provider or your router/gateway. Try pinging a static IP address to prove that your machine has access to the Internet:
If you receive an error message (see [[Wikipedia:Ping (networking utility)#Error indications|ping error indications]]) or no reply, this may be related to incomplete configuration, but also your default gateway or your Internet Service Provider (ISP). You can run a [[traceroute]] to further diagnose the route to the host.


{{hc|$ ping 8.8.8.8|<nowiki>
== Network management ==
PING 8.8.8.8 (8.8.8.8) 56(84) bytes of data.
64 bytes from 8.8.8.8: icmp_req=1 ttl=53 time=52.9 ms
...
</nowiki>}}


If you are able to ping {{ic|8.8.8.8}} but not {{ic|www.google.com}}, check your DNS configuration. See [[resolv.conf]] for details. The {{ic|hosts}} line in {{ic|/etc/nsswitch.conf}} is another place you can check.
{{Style|Split into manual configuration with iproute2 and automatic with DHCP & SLAAC.}}


If not, check for cable issues before diagnosing further.
To set up a network connection, go through the following steps:


{{Note|
# Ensure your [[#Network interfaces|network interface]] is listed and enabled.
* If you receive an error like {{ic|ping: icmp open socket: Operation not permitted}} when executing ''ping'', try to re-install the {{Pkg|iputils}} package.
# Connect to the network. Plug in the Ethernet cable or [[/Wireless|connect to the wireless LAN]].
* The {{ic|-c ''num''}} option can be used to make exactly {{ic|''num''}} pings, otherwise it pings infinitely and has to be terminated manually. See {{man|8|ping}} for more information.
# Configure your network connection:
* {{ic|8.8.8.8}} is a static address that is easy to remember. It is the address of Google's primary DNS server, therefore it can be considered reliable, and is generally not blocked by content filtering systems and proxies.
#* Most networks use the [[Wikipedia:Dynamic Host Configuration Protocol|Dynamic Host Configuration Protocol]] for network configuration. Clients can automatically obtain a dynamic or static IP address from the DHCP server via [[#Network managers|a standalone DHCP client or using a network manager]].
}}
#* If the network does not have a DHCP server, you can configure a static IP address, routing table and DNS servers manually for each client. See [[#Static IP address]] for details.


== Device driver ==
{{Note|The installation image uses
* [[systemd-networkd]], which is configured as a DHCP client for [https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/configs/releng/airootfs/etc/systemd/network/20-ethernet.network Ethernet], [https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/configs/releng/airootfs/etc/systemd/network/20-wlan.network WLAN] and [https://gitlab.archlinux.org/archlinux/archiso/-/blob/master/configs/releng/airootfs/etc/systemd/network/20-wwan.network WWAN] network interfaces, and 
* [[systemd-resolved]] configured for system-wide [[DNS]], see [[systemd-resolved#DNS]].}}


=== Check the status ===
=== Manual ===


[[udev]] should detect your [[Wikipedia:Network interface controller|network interface controller]] and automatically load the necessary module at start up. Check the "Ethernet controller" entry (or similar) from the {{ic|lspci -v}} output. It should tell you which kernel module contains the driver for your network device. For example:
==== iproute2 ====


{{hc|$ lspci -v|
{{Style|This section does not fit in [[#Network management]] – it does not ''manage'' anything, it only introduces the {{Pkg|iproute2}} package.}}
02:00.0 Ethernet controller: Attansic Technology Corp. L1 Gigabit Ethernet Adapter (rev b0)
...
Kernel driver in use: atl1
Kernel modules: atl1
}}


Next, check that the driver was loaded via {{ic|dmesg <nowiki>|</nowiki> grep ''module_name''}}. For example:
[[Wikipedia:iproute2|iproute2]] is a dependency of the {{Pkg|base}} [[meta package]] and provides the {{man|8|ip}} command-line interface, used to manage [[#Network interfaces|network interfaces]], [[#IP addresses|IP addresses]] and the [[#Routing table|routing table]]. Be aware that configuration made using {{ic|ip}} will be lost after a reboot. For persistent configuration, you can automate ''ip'' commands using scripts and [[systemd#Writing unit files|systemd units]]. Also note that {{ic|ip}} commands can generally be abbreviated, for clarity they are however spelled out in this article.


{{hc|<nowiki>$ dmesg | grep atl1</nowiki>|
{{Note|Arch Linux has deprecated {{Pkg|net-tools}} in favor of {{Pkg|iproute2}}.[https://archlinux.org/news/deprecation-of-net-tools/] See also [https://dougvitale.wordpress.com/2011/12/21/deprecated-linux-networking-commands-and-their-replacements/ Deprecated Linux networking commands and their replacements].}}
...
atl1 0000:02:00.0: eth0 link is up 100 Mbps full duplex
}}


Skip the next section if the driver was loaded successfully. Otherwise, you will need to know which module is needed for your particular model.
==== Static IP address ====


=== Load the module ===
A static IP address can be configured with most standard [[#Network managers|network managers]] and also [[dhcpcd]].


Search in the Internet for the right module/driver for the chipset. Some common modules are {{ic|8139too}} for cards with a Realtek chipset, or {{ic|sis900}} for cards with a SiS chipset. Once you know which module to use, try to [[Kernel modules#Manual module handling|load it manually]]. If you get an error saying that the module was not found, it's possible that the driver is not included in Arch kernel. You may search the [[AUR]] for the module name.
To manually configure a static IP address, add an IP address as described in [[#IP addresses]], set up your [[#Routing table|routing table]] and [[Domain name resolution|configure your DNS servers]].


If udev is not detecting and loading the proper module automatically during bootup, see [[Kernel modules#Automatic module handling]].
==== IP addresses ====


== Network management ==
[[Wikipedia:IP address|IP addresses]] are managed using {{man|8|ip-address}}.


=== Network interfaces ===
List IP addresses:


For computers with multiple NICs, it is important to have fixed interface names. Many configuration problems are caused by interface name changing.
$ ip address show


[[udev]] is responsible for assigning names to each device. Systemd uses [http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames Predictable Network Interface Names], which automatically assigns static names to network devices. Interfaces are now prefixed with {{ic|en}} (wired/[[w:Ethernet|Ethernet]]), {{ic|wl}} (wireless/WLAN), or {{ic|ww}} ([[w:Wireless_WAN|WWAN]]) followed by an automatically generated identifier, creating an entry such as {{ic|enp0s25}}.
Add an IP address to an interface:


==== Get current interface names ====
# ip address add ''address/prefix_len'' broadcast + dev ''interface''


Both wired and wireless interface names can be found via {{ic|ls /sys/class/net}} or {{ic|ip link}}. Note that {{ic|lo}} is the [[w:loop device|loop device]] and not used in making network connections.
:Note that:


Wireless device names can also be retrieved using {{ic|iw dev}}. See also [[Wireless network configuration#Get the name of the interface]].
:* the address is given in [[Wikipedia:Classless Inter-Domain Routing#CIDR notation|CIDR notation]] to also supply a [[Wikipedia:Subnetwork|subnet mask]]
:* {{ic|+}} is a special symbol that makes {{ic|ip}} derive the [[Wikipedia:Broadcast address|broadcast address]] from the IP address and the subnet mask


{{Tip|To change the device names, see [[#Change device name]] and [[#Revert to traditional device names]].}}
:{{Note|Make sure manually assigned IP addresses do not conflict with DHCP assigned ones.}}


==== Enabling and disabling network interfaces ====
Delete an IP address from an interface:


You can activate a network interface using:
# ip address del ''address/prefix_len'' dev ''interface''


# ip link set ''interface'' up
Delete all addresses matching a criteria, e.g. of a specific interface:


To deactivate it do:
# ip address flush dev ''interface''


# ip link set ''interface'' down
{{Tip|IPv4 addresses can be calculated with [http://jodies.de/ipcalc ipcalc] ({{Pkg|ipcalc}}).}}


To check the result for the interface {{ic|eth0}}:
==== Routing table ====


{{hc|$ ip link show dev eth0|
The [[Wikipedia:Routing table|routing table]] is used to determine if you can reach an IP address directly or what gateway (router) you should use. If no other route matches the IP address, the [[Wikipedia:Default gateway|default gateway]] is used.
2: eth0: <BROADCAST,MULTICAST,PROMISC,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state UP mode DEFAULT qlen 1000
...
}}


{{Note|If your default route is through interface {{ic|eth0}}, taking it down will also remove the route, and bringing it back up will not automatically reestablish the default route. See [[#Manual assignment]] for reestablishing it.}}
The routing table is managed using {{man|8|ip-route}}.


=== Dynamic IP address ===
''PREFIX'' is either a CIDR notation or {{ic|default}} for the default gateway.


See [[#Network managers]] for a list of options in setting a dynamic IP address.
List IPv4 routes:


=== Static IP address ===
$ ip route show


A static IP address can be configured with most standard [[#Network managers|network managers]]. Independently of the tool you choose, you will probably need to be prepared with the following information:
List IPv6 routes:


* Static IP address
$ ip -6 route show
* Subnet mask, or possibly its [[wikipedia:Classless Inter-Domain Routing#CIDR notation|CIDR notation]], for example {{ic|/24}} is the CIDR notation of {{ic|255.255.255.0}} netmask.
* [[Wikipedia:Broadcast_address|Broadcast address]]
* [[Wikipedia:Default_gateway|Gateway]]'s IP address
* Name server (DNS) IP addresses. See also [[resolv.conf]].


If you are running a private network, it is safe to use IP addresses in {{ic|192.168.*.*}} for your IP addresses, with a subnet mask of {{ic|255.255.255.0}} and a broadcast address of {{ic|192.168.*.255}}. The gateway is usually {{ic|192.168.*.1}} or {{ic|192.168.*.254}}.
Add a route:


{{Warning|
# ip route add ''PREFIX'' via ''address'' dev ''interface''
* Make sure manually assigned IP addresses do not conflict with DHCP assigned ones. See [http://www.raspberrypi.org/forums/viewtopic.php?f&#61;28&t&#61;16797 this forum thread].
* If you share your Internet connection from a Windows machine without a router, be sure to use static IP addresses on both computers to avoid LAN problems.
}}


{{Tip|Addresses can be calculated with the {{Pkg|ipcalc}} package; see [[#Calculating addresses]].}}
Delete a route:


==== Manual assignment ====
# ip route del ''PREFIX'' via ''address'' dev ''interface''


It is possible to manually set up a static IP using only the {{pkg|iproute2}} package. This is a good way to test connection settings since the connection made using this method will not persist across reboots. First enable the [[#Network interfaces|network interface]]:
=== Automatic ===


# ip link set ''interface'' up
{{Expansion|Explain [[Wikipedia:SLAAC|SLAAC]].}}


Assign a static IP address in the console:
Automatic network configuration is accomplished using [[Wikipedia:Dynamic Host Configuration Protocol|Dynamic Host Configuration Protocol]] (DHCP). The network's DHCP server provides IP address(es), the default gateway IP address(es) and optionally also DNS name servers upon request
from the DHCP client.


# ip addr add ''IP_address''/''subnet_mask'' broadcast ''broadcast_address'' dev ''interface''
See [[Router#DNS and DHCP]] for a DHCP server comparison table.


Then add your gateway IP address:
==== Network managers ====


# ip route add default via ''default_gateway''
A network manager lets you manage network connection settings in so called network profiles to facilitate switching networks.


For example:
{{Tip|You can check if a DHCPv4 server is running with {{Pkg|dhcping}}.}}


# ip link set eth0 up
{{Note|Each network interface should be managed by only one DHCP client or network manager, so it is advised to run only one DHCP client or network manager on the system.}}
# ip addr add 192.168.1.2/24 broadcast 192.168.1.255 dev eth0
# ip route add default via 192.168.1.1


{{Tip|If you get the message {{ic|RTNETLINK answers: Network is unreachable}}, try to break up the route creation in the following two parts:
{| class="wikitable sortable"
! rowspan="2"| Software
! colspan="3"| Connection type
! colspan="2"| [[Network configuration/Wireless#Authentication|Wireless authentication]]
! colspan="3"| IP address, route and DNS management
! colspan="3"| Interface
|-
! Ethernet
! PPPoE
! [[Mobile broadband modem|Mobile broadband]]
! WPA/WPA2
! WPA3
! Static IP
! DHCP client
! [[Domain name resolution]]
! CLI
! TUI
! GUI
|-
! {{Pkg|dhclient}}<sup>1</sup>
| {{Yes}} || {{No}} || {{No}} || colspan="2" {{No}}<sup>2</sup> || {{Yes}} || {{G|internal}} || {{Yes}} (writes {{ic|/etc/resolv.conf}}) || {{No}} || {{No}} || {{No}}
|-
! [[dhcpcd]]
| {{Yes}} || {{No}} || {{No}} || colspan="2" {{Y|[[dhcpcd#10-wpa_supplicant|Launches wpa_supplicant]]<sup>3</sup>}} || {{Yes}} || {{G|internal}} || {{G|[[dhcpcd#/etc/resolv.conf|Yes]] (uses [[resolvconf]] or writes {{ic|/etc/resolv.conf}})}} || {{No}} || {{No}} || {{G|{{AUR|dhcpcd-ui}}}}
|-
! [[ConnMan]]
| {{Yes}} || {{No|https://01.org/jira/browse/CM-63{{Dead link|2023|10|29|status=404}}}} || {{Yes}} (via {{aur|ofono}}) || colspan="2" {{Yes}} (via {{Pkg|wpa_supplicant}} or {{Pkg|iwd}}) || {{Yes}} || {{G|internal}} || {{G|[[ConnMan#DNS management|Yes]]}} (runs a builtin resolver and writes {{ic|/etc/resolv.conf}}) || {{G|{{man|1|connmanctl}}}} || {{G|[[ConnMan#Front-ends|Yes]]}} || {{G|[[ConnMan#Front-ends|Yes]]}}
|-
! [[netctl]]
| {{Yes}} || {{G|[[Netctl#Installation|Yes]] (via {{Pkg|ppp}})}} || {{Yes}} (via {{Pkg|ppp}}) || {{Yes}} (via {{Pkg|wpa_supplicant}}) || {{No}} || {{Yes}} || {{G|{{Pkg|dhcpcd}} or {{Pkg|dhclient}}}} || {{G|[[netctl#/etc/resolv.conf|Yes]] (uses [[resolvconf]])}} || {{G|{{man|1|netctl}}}} || {{Y|{{man|1|wifi-menu}}<sup>4</sup>}} || {{No}}
|-
! [[NetworkManager]]
| {{Yes}} || {{G|[[NetworkManager#PPPoE / DSL support|Yes]] (via {{Pkg|rp-pppoe}})}} || {{G|[[NetworkManager#Mobile broadband support|Yes]] (via {{Pkg|modemmanager}})}} || colspan="2" {{Yes}} (via {{Pkg|wpa_supplicant}} or [[NetworkManager#Using iwd as the Wi-Fi backend|iwd]]) || {{Yes}} || {{G|internal, {{Pkg|dhclient}} or {{Pkg|dhcpcd}}<sup>5</sup>}} || {{G|[[NetworkManager#DNS management|Yes]] (uses [[systemd-resolved]], [[resolvconf]] or writes {{ic|/etc/resolv.conf}})}} || {{G|{{man|1|nmcli}}}} || {{G|{{man|1|nmtui}}}} || {{G|[[NetworkManager#Front-ends|Yes]]}}
|-
! [[systemd-networkd]]
| {{Yes}} || {{No|https://github.com/systemd/systemd/issues/481}} || {{No|https://github.com/systemd/systemd/issues/20370}} || colspan="2" {{No}}<sup>2</sup> || {{Yes}} || {{G|internal}} || {{Yes}} (uses [[systemd-resolved]]) || {{G|{{man|1|networkctl}}}} || {{No}} || {{No}}
|-
! [[wpa_supplicant]]
| {{G|[[Wikipedia:IEEE 802.1X|IEEE 802.1X]]}} || {{No}} || {{No}} || {{Yes}} || {{Yes}} || colspan="3" {{No}} || {{G|{{man|8|wpa_cli}}}} || {{No}} || {{G|{{AUR|wpa_supplicant_gui}}}}
|-
! [[iwd]]
| {{G|[[Wikipedia:IEEE 802.1X|IEEE 802.1X]]}} || {{No}} || {{No}} || {{Yes}} || {{Yes}} || {{G|[[iwd#Enable built-in network configuration|Yes]]}} || {{G|[[iwd#Enable built-in network configuration|internal]]}} || {{G|[[iwd#Select DNS manager|Yes]] (uses [[systemd-resolved]] or [[resolvconf]])}} || {{G|{{man|1|iwctl}}}} || {{No}} || {{G|{{AUR|iwgtk}}}}
|}


# ip route add 192.168.1.1 dev eth0
# No longer maintained as of early 2022. ISC advises no longer using it in production.
# ip route add default via 192.168.1.1 dev eth0
# Wireless authentication can be configured separately with [[wpa_supplicant]] or [[iwd]].
}}
# Wireless authentication must be configured separately with [[wpa_supplicant]].
# Only Wi-Fi connections can be managed.
# NetworkManager does not use dhcpcd for DHCPv6, see [[NetworkManager#DHCP client]].


To undo these steps (e.g. before switching to a dynamic IP), first remove any assigned IP address:
== Network interfaces ==


# ip addr flush dev ''interface''
Network interfaces are managed by [[udev]] and configured by {{man|5|systemd.link}} files. The default configuration assigns names to your [[Wikipedia:Network interface controller|network interface controllers]] using [https://systemd.io/PREDICTABLE_INTERFACE_NAMES/ Predictable Network Interface Names], which prefixes interfaces names with {{ic|en}} (wired/[[Wikipedia:Ethernet|Ethernet]]), {{ic|wl}} (wireless/[[Wikipedia:Wireless LAN|WLAN]]), or {{ic|ww}} (mobile broadband/[[Wikipedia:Wireless WAN|WWAN]]). See {{man|7|systemd.net-naming-scheme}}.


Then remove any assigned gateway:
{{Tip|
* The system {{ic|/usr/lib/systemd/network/99-default.link}} is generally sufficient for most cases.
* To change interface names, see [[#Change interface name]] and [[#Revert to traditional interface names]].
* You can run {{ic|udevadm test-builtin net_setup_link /sys/path/to/network/device}} as the root user to diagnose problems with ''.link'' files.
}}


# ip route flush dev ''interface''
=== Listing network interfaces ===


And finally disable the interface:
Both wired and wireless interface names can be found via {{ic|ls /sys/class/net}} or {{ic|ip link}}. Note that {{ic|lo}} is the [[Wikipedia:Loopback#Virtual loopback interface|virtual loopback interface]] and not used in making network connections.


# ip link set ''interface'' down
Wireless device names can also be retrieved using {{ic|iw dev}}. See also [[/Wireless#Get the name of the interface]].


For more options, see the {{man|8|ip}}. These commands can be automated using scripts and [[systemd#Writing unit files|systemd units]].
If your network interface is not listed, make sure your device driver was loaded successfully. See [[/Ethernet#Device driver]] or [[/Wireless#Device driver]].


==== Calculating addresses ====
=== Enabling and disabling network interfaces ===


You can use {{ic|ipcalc}} provided by the {{Pkg|ipcalc}} package to calculate IP broadcast, network, netmask, and host ranges for more advanced configurations. An example is using Ethernet over Firewire to connect a Windows machine to Linux. To improve security and organization, both machines have their own network with the netmask and broadcast configured accordingly.  
Network interfaces can be enabled or disabled using {{ic|ip link set ''interface'' up{{!}}down}}, see {{man|8|ip-link}}.


Finding out the respective netmask and broadcast addresses is done with {{ic|ipcalc}}, by specifying the IP of the Linux NIC {{ic|10.66.66.1}} and the number of hosts (here two):
To check the status of the interface {{ic|enp2s0}}:


{{hc|$ ipcalc -nb 10.66.66.1 -s 1|<nowiki>
{{hc|$ ip link show dev enp2s0|
Address:  10.66.66.1
2: enp2s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast master br0 state DOWN mode DEFAULT qlen 1000
...
}}
 
The {{ic|UP}} in {{ic|<BROADCAST,MULTICAST,UP,LOWER_UP>}} is what indicates the interface is up, not the later {{ic|state DOWN}}.


Netmask:  255.255.255.252 = 30
{{Note|If your default route is through interface {{ic|enp2s0}}, taking it down will also remove the route, and bringing it back up will not automatically re-establish the default route. See [[#Routing table]] for re-establishing it.}}
Network:  10.66.66.0/30
HostMin:  10.66.66.1
HostMax:  10.66.66.2
Broadcast: 10.66.66.3
Hosts/Net: 2                    Class A, Private Internet
</nowiki>}}


=== Network managers ===
=== Change interface name ===


There are many solutions to choose from, but remember that all of them are mutually exclusive; you should not run two daemons simultaneously. The following table compares the different connection managers. ''Automatically handles wired connection'' means that there is at least one option for the user to simply start the daemon without creating a configuration file.
{{Note|When changing the naming scheme, do not forget to update all network-related configuration files and custom systemd unit files to reflect the change.}}


{| class="wikitable"
You can change the device name by defining the name manually with an {{man|5|systemd.link}} file. For example:
! Connection manager || Automatically handles<br>wired connection || Official <br>GUI || [[Archiso]] [https://git.archlinux.org/archiso.git/tree/configs/releng/packages.both] || Console tools || Systemd units
|-
| [[ConnMan]] || {{Yes}} || {{No}} || {{No}} || {{ic|connmanctl}} || {{ic|connman.service}}
|-
| [[dhcpcd]] || {{Yes}} || {{No}} || {{Yes}} ({{grp|base}}) || {{ic|dhcpcd}} || {{ic|dhcpcd.service}}, {{ic|dhcpcd@''interface''.service}}
|-
| [[netctl]] || {{Yes}} || {{No}} || {{Yes}} ({{grp|base}}) || {{ic|netctl}} || {{ic|netctl-ifplugd@''interface''.service}}
|-
| [[NetworkManager]] || {{Yes}} || {{Yes}} || {{No}} || {{ic|nmcli}},{{ic|nmtui}} || {{ic|NetworkManager.service}}
|-
| [[systemd-networkd]] || {{No}} || {{No}} || {{Yes}} ({{grp|base}}) || || {{ic|systemd-networkd.service}}, {{ic|systemd-resolved.service}}
|-
| [[Wicd]] || {{Yes}} || {{Yes}} || {{No}} || {{ic|wicd-curses}} || {{ic|wicd.service}}
|}


See also [[List of applications#Network managers]].
{{hc|/etc/systemd/network/10-net0.link|2=
[Match]
PermanentMACAddress=aa:bb:cc:dd:ee:ff


== Set the hostname ==
[Link]
Name=net0
}}


A [[Wikipedia:Hostname|hostname]] is a unique name created to identify a machine on a network, configured in {{ic|/etc/hostname}}—see {{man|5|hostname}} and {{man|7|hostname}} for details. The file can contain the system's domain name, if any. To set the hostname, [[textedit|edit]] {{ic|/etc/hostname}} to include a single line with {{ic|''myhostname''}}:
Alternatively, a udev rule can be used:


{{hc|/etc/hostname|
{{hc|/etc/udev/rules.d/10-network.rules|2=
''myhostname''
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="net0"
}}
}}


{{Tip|For advice on choosing a hostname, see [https://tools.ietf.org/html/rfc1178 RFC 1178].}}
These rules will be applied automatically at boot. To apply the change immediately, do a manual trigger of the udev rule on the {{ic|net}} subsystem:
 
# udevadm trigger --verbose --subsystem-match=net --action=add


Alternatively, using {{man|1|hostnamectl}}:
If you want to run a [[udev#Testing rules before loading|test]] on the changes made, {{ic|udevadm --debug test /sys/class/net/*}} can be of help.


# hostnamectl set-hostname ''myhostname''
{{Note|
* The priority of {{ic|Name}} is lower than {{ic|NamePolicy}}, so make sure the latter is unset/empty or the name will not be changed. {{ic|99-default.link}} sets {{ic|NamePolicy}}, requiring the custom config to be ordered before it, i.e. to have a numerical prefix.
* The network interface must be down before changing its name. [https://github.com/systemd/systemd/issues/26601]
* To get the MAC address of each card, run {{ic|ip link}}.
* Make sure to use the lower-case hex values in your udev rules. It does not like upper-case.
}}


To temporarily set the hostname (until reboot), use {{man|1|hostname}} from {{Pkg|inetutils}}:
If the network card has a dynamic MAC, you can use {{ic|Path}} (which can be checked using {{ic|networkctl status ''interface_name''}}):


# hostname ''myhostname''
{{hc|/etc/systemd/network/10-net1.link|2=
[Match]
Path=pci-0000:01:00.0


To set the "pretty" hostname and other machine metadata, see {{man|5|machine-info|https://www.freedesktop.org/software/systemd/man/machine-info.html}}.
[Link]
Name=net1
}}


=== Local network hostname resolution ===
Or, use a udev rule with {{ic|DEVPATH}}:


The pre-requisite is to [[#Set the hostname]], after which hostname resolution works on the local system itself:
{{hc|/etc/udev/rules.d/10-network.rules|2=
SUBSYSTEM=="net", DEVPATH=="/devices/pci*/*1c.0/*/net/*", NAME="net1"
}}


{{hc|$ ping ''myhostname''|2=
To get the {{ic|DEVPATH}} of all currently-connected devices, see where the symlinks in {{ic|/sys/class/net/}} lead. For example:
PING ''myhostname'' (192.168.1.2) 56(84) bytes of data.
64 bytes from ''myhostname'' (192.168.1.2): icmp_seq=1 ttl=64 time=0.043 ms}}


To allow other machines to address the host by name, it is necessary to either:
{{hc|$ 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
}}


* Configure the {{man|5|hosts}} file, or
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 given rule, {{ic|"/devices/pci*/*1c.0/*/net/en*"}} would be wrong since it will stop matching once the name is changed to {{ic|net1}}. Only the system-default rule will fire the second time around, causing the name to be changed back.
* Enable a service which resolves the hostname.


{{Note|1={{Pkg|systemd}} provides hostname resolution via the {{ic|myhostname}} nss module, enabled by default in {{ic|/etc/nsswitch.conf}}. However, clients may still rely on {{ic|/etc/hosts}}, see [https://lists.debian.org/debian-devel/2013/07/msg00809.html] [https://bugzilla.mozilla.org/show_bug.cgi?id=87717#c55] for examples.}}
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 model ID instead:


To configure the hosts file, add the following line to {{ic|/etc/hosts}}:
{{hc|/etc/systemd/network/20-net2.link|2=
[Match]
Property=ID_VENDOR_ID=12ab ID_MODEL_ID=3cd4


127.0.1.1 ''myhostname''.localdomain ''myhostname''
[Link]
Name=net2
}}


As a result the system resolves to both entries:
or


{{hc|$ getent hosts|
{{hc|/etc/udev/rules.d/10-network.rules|2=
127.0.0.1      localhost
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="12ab", ATTRS{idProduct}=="3cd4", NAME="net2"
127.0.1.1      ''myhostname''.localdomain ''myhostname''
}}
}}


For a system with a permanent IP address, that permanent IP address should be used instead of {{ic|127.0.1.1}}.
{{Note|When choosing the static names '''it should be avoided to use names in the format of "eth''X''" and "wlan''X''"''', because this may lead to race conditions between the kernel and udev during boot. Instead, it is better to use interface names that are not used by the kernel as default, e.g.: {{ic|net0}}, {{ic|net1}}, {{ic|wifi0}}, {{ic|wifi1}}. For further details please see the [https://systemd.io/PREDICTABLE_INTERFACE_NAMES/ systemd] documentation.}}


{{Note|1=Another option is to set up a full DNS server such as [[BIND]] or [[Unbound]], but that is overkill and too complex for most systems. For small networks and dynamic flexibility with hosts joining and leaving the network [[Wikipedia:Zero-configuration_networking|zero-configuration networking]] services may be more applicable:
=== Revert to traditional interface names ===
*[[Samba]] provides hostname resolution via Microsoft's '''NetBIOS'''. It only requires installation of {{Pkg|samba}} and enabling of the {{ic|nmbd.service}} service. Computers running Windows, macOS, or Linux with {{ic|nmbd}} running, will be able to find your machine.
 
*[[Avahi]] provides hostname resolution via '''zeroconf''', also known as Avahi or Bonjour. It requires slightly more complex configuration than Samba: see [[Avahi#Hostname resolution]] for details. Computers running macOS, or Linux with an Avahi daemon running, will be able to find your machine. Windows does not have an built-in Avahi client or daemon.
If you would prefer to retain traditional interface names such as {{ic|eth0}}, [https://systemd.io/PREDICTABLE_INTERFACE_NAMES/ Predictable Network Interface Names] can be disabled by changing the default {{ic|NamePolicy}} for udev's {{ic|net_setup_link}} built-in:
 
{{hc|/etc/systemd/network/99-default.link.d/traditional-naming.conf|2=
[Link]
NamePolicy=keep kernel
}}
}}


== Tips and tricks ==
Alternatively, {{ic|net_setup_link}} can be completely disabled by masking the corresponding udev rule:


=== Change device name ===
# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules


{{Note|When changing the naming scheme, do not forget to update all network-related configuration files and custom systemd unit files to reflect the change.}}
or by adding {{ic|1=net.ifnames=0}} to the [[kernel parameters]].


You can change the device name by defining the name manually with an udev-rule. For example:
{{Note|{{man|5|systemd.link}} relies on {{ic|net_setup_link}} to work. Prefer to use the first approach unless you fully understand what you are doing.}}


{{hc|/etc/udev/rules.d/10-network.rules|<nowiki>
=== Set device MTU and queue length ===
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"
</nowiki>}}


These rules will be applied automatically at boot.
You can change the device [[wikipedia:Maximum transmission unit|MTU]] and queue length by defining manually with a {{man|5|systemd.link}} config. For example:


A couple of things to note:
{{hc|/etc/systemd/network/30-mtu.link|2=
[Match]
Type=wlan


* To get the MAC address of each card, use this command: {{ic|cat /sys/class/net/''device_name''/address}}
[Link]
* Make sure to use the lower-case hex values in your udev rules. It doesn't like upper-case.
MTUBytes=1500
TransmitQueueLength=2000
}}


If the network card has a dynamic MAC, you can use {{ic|DEVPATH}}, for example:
Or through a udev rule:


{{hc|/etc/udev/rules.d/10-network.rules|<nowiki>
{{hc|/etc/udev/rules.d/10-network.rules|2=
SUBSYSTEM=="net", DEVPATH=="/devices/platform/wemac.*", NAME="int"
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wl*", ATTR{mtu}="1500", ATTR{tx_queue_len}="2000"
SUBSYSTEM=="net", DEVPATH=="/devices/pci*/*1c.0/*/net/*", NAME="en"
}}
</nowiki>}}


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, {{ic|"/devices/pci*/*1c.0/*/net/enp*"}} would be wrong since it will stop matching once the name is changed to {{ic|en}}. Only the system-default rule will fire the second time around, causing the name to be changed back to e.g. {{ic|enp1s0}}.
{{ic|MTUBytes}}: Using a value larger than 1500 (so called [[Wikipedia:jumbo frame|jumbo frame]]s) can significantly speed up your network transfers. Note that all network interfaces, including switches in the local network, must support the same MTU in order to use jumbo frames. For PPPoE, the MTU should not be larger than 1492. You can also set MTU via {{man|5|systemd.netdev}}.


To [[Udev#Testing_rules_before_loading|test]] your rules, they can be triggered directly from userspace, e.g. with {{ic|udevadm --debug test /sys/''DEVPATH''}}. Remember to first take down the interface you are trying to rename (e.g. {{ic|ip link set enp1s0 down}}).
{{ic|TransmitQueueLength}}: Small value for slower devices with a high latency like modem links and ISDN. High value is recommended for server connected over the high-speed internet connections that perform large data transfers.


{{Note|When choosing the static names '''it should be avoided to use names in the format of "eth''X''" and "wlan''X''"''', because this may lead to race conditions between the kernel and udev during boot. Instead, it is better to use interface names that are not used by the kernel as default, e.g.: {{ic|net0}}, {{ic|net1}}, {{ic|wifi0}}, {{ic|wifi1}}. For further details please see the [http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames systemd] documentation.}}
== Set the hostname ==


=== Revert to traditional device names ===
A [[Wikipedia:Hostname|hostname]] is a unique name created to identify a machine on a network, configured in {{ic|/etc/hostname}}—see {{man|5|hostname}} and {{man|7|hostname}} for details. The file can contain the system's domain name, if any. To set the hostname, [[textedit|edit]] {{ic|/etc/hostname}} to include a single line with {{ic|''yourhostname''}}:


If you would prefer to retain traditional interface names such as eth0,  [http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames Predictable Network Interface Names] can be disabled by masking the udev rule:
{{hc|/etc/hostname|
''yourhostname''
}}


  # ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
{{Tip|For advice on choosing a hostname, see [[RFC:1178|RFC 1178]].}}


Alternatively, add {{ic|1=net.ifnames=0}} to the [[kernel parameters]].
Alternatively, using {{man|1|hostnamectl}}:


=== Set device MTU and queue length ===
# hostnamectl hostname ''yourhostname''


You can change the device [[wikipedia:Maximum_transmission_unit|MTU]] and queue length by defining manually with an udev-rule. For example:
To temporarily set the hostname (until reboot), use {{man|1|hostname}} from {{Pkg|inetutils}}:
 
{{hc|/etc/udev/rules.d/10-network.rules|<nowiki>
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wl*", ATTR{mtu}="1500", ATTR{tx_queue_len}="2000"
</nowiki>}}


{{Note|
# hostname ''yourhostname''
* {{ic|mtu}}: For PPPoE, the MTU should be no larger than 1492. You can also set MTU via {{man|5|systemd.netdev}}.
* {{ic|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.
}}


=== ifplugd for laptops ===
To set the "pretty" hostname and other machine metadata, see {{man|5|machine-info}}.


{{Tip|[[dhcpcd]] provides the same feature out of the box.}}
=== Local network hostname resolution ===


{{Pkg|ifplugd}} is a daemon which will automatically configure your Ethernet device when a cable is plugged in and automatically unconfigure it if the cable is pulled. This is useful on laptops with onboard network adapters, since it will only configure the interface when a cable is really connected. Another use is when you just need to restart the network but do not want to restart the computer or do it from the shell.
To make your machine accessible in your LAN via its hostname you can:


By default it is configured to work for the {{ic|eth0}} device. This and other settings like delays can be configured in {{ic|/etc/ifplugd/ifplugd.conf}}.
* edit the {{ic|/etc/hosts}} file for every device in your LAN, see {{man|5|hosts}}
* set up a [[DNS server]] to resolve your hostname and make the LAN devices use it (e.g. via [[Router#DNS and DHCP|DHCP]])
* or the easy way: use a [[Wikipedia:Zero-configuration networking|Zero-configuration networking]] service:
** Hostname resolution via Microsoft's [[Wikipedia:NetBIOS#Name service|NetBIOS]]. Provided by [[Samba]] on Linux. It only requires the {{ic|nmb.service}}. Computers running Windows, macOS, or Linux with {{ic|nmb}} running, will be able to find your machine.
** Hostname resolution via [[Wikipedia:Multicast DNS|mDNS]]. Provided by either {{ic|nss_mdns}} with [[Avahi]] (see [[Avahi#Hostname resolution]] for setup details) or [[systemd-resolved]]. Computers running macOS, or Linux with Avahi or systemd-resolved running, will be able to find your machine. The older Win32 API does not support mDNS, which may prevent some older Windows applications from accessing your device.


{{Note|[[netctl]] package includes {{ic|netctl-ifplugd@.service}}, otherwise you can use {{ic|ifplugd@.service}} from {{Pkg|ifplugd}} package. For example, [[enable]] {{ic|ifplugd@eth0.service}}.}}
== Tips and tricks ==


=== Bonding or LAG ===
=== Bonding or LAG ===


See [[netctl#Bonding]] or [[Wireless bonding]].
See [[netctl#Bonding|netctl]] or [[systemd-networkd#Bonding a wired and wireless interface|systemd-networkd]], or [[Wireless bonding]].


=== IP address aliasing ===
=== IP address aliasing ===
Line 348: Line 394:
To manually set an alias, for some NIC, use {{Pkg|iproute2}} to execute
To manually set an alias, for some NIC, use {{Pkg|iproute2}} to execute


  # ip addr add 192.168.2.101/24 dev eth0 label eth0:1
  # ip addr add 192.168.2.101/24 dev enp2s0 label enp2s0:1


To remove a given alias execute
To remove a given alias execute


  # ip addr del 192.168.2.101/24 dev eth0:1
  # ip addr del 192.168.2.101/24 dev enp2s0: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 {{ic|ip route}}.
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 {{ic|ip route}}.
=== Change MAC/hardware address ===
See [[MAC address spoofing]].
=== Internet sharing ===
See [[Internet sharing]].
=== Router configuration ===
See [[Router]].


=== Promiscuous mode ===
=== Promiscuous mode ===


Toggling [[wikipedia:Promiscuous_mode|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 [[wikipedia:Packet_sniffing|packet sniffing]].
Toggling [[wikipedia:Promiscuous mode|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 [[wikipedia:Packet sniffing|packet sniffing]].


{{hc|/etc/systemd/system/promiscuous@.service|<nowiki>
{{hc|/etc/systemd/system/promiscuous@.service|<nowiki>
Line 386: Line 420:
</nowiki>}}
</nowiki>}}


If you want to enable promiscuous mode on interface {{ic|eth0}} run [[enable]] {{ic|promiscuous@eth0.service}}.
If you want to enable promiscuous mode on interface {{ic|enp2s0}}, [[enable]] {{ic|promiscuous@enp2s0.service}}.
 
=== Investigate sockets ===
 
''ss'' is a utility to investigate network ports and is part of the {{Pkg|iproute2}} package. It has a similar functionality to the [https://archlinux.org/news/deprecation-of-net-tools/ deprecated] netstat utility.
 
Common usage includes:
 
Display all TCP Sockets with service names:
$ ss -at


== Troubleshooting ==
Display all TCP Sockets with port numbers:
$ ss -atn


=== Swapping computers on the cable modem ===
Display all UDP Sockets:
$ ss -au


Some cable ISPs (videotron for example) have the cable modem configured to recognize only one client PC, by the MAC address of its network interface. Once the cable modem has learned the MAC address of the first PC or equipment that talks to it, it will not respond to another MAC address in any way. Thus if you swap one PC for another (or for a router), the new PC (or router) will not work with the cable modem, because the new PC (or router) has a MAC address different from the old one. To reset the cable modem so that it will recognise the new PC, you must power the cable modem off and on again. Once the cable modem has rebooted and gone fully online again (indicator lights settled down), reboot the newly connected PC so that it makes a DHCP request, or manually make it request a new DHCP lease.
For more information see {{man|8|ss}}.


If this method does not work, you will need to clone the MAC address of the original machine. See also [[#Change MAC/hardware address]].
== Troubleshooting ==


=== The TCP window scaling problem ===
=== 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.
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 64KiB. 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, [http://www.faqs.org/rfcs/rfc1323.html 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.
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 64KiB.


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.
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.
Line 408: Line 453:
==== How to diagnose the problem ====
==== How to diagnose the problem ====


First of all, let's 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).
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 {{ic|dmesg}}'s output is OK, logs are clean and {{ic|ip addr}} will report normal status... and actually everything appears normal.
When you have this problem, the output from [[dmesg]] is okay, logs are clean and {{ic|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're experiencing this problem: ping uses ICMP and is not affected by TCP problems.
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).
You can try to use [[Wireshark]]. You might see successful UDP and ICMP communications but unsuccessful TCP communications (only to foreign hosts).
Line 432: Line 477:
===== Best =====
===== Best =====


This problem is caused by broken routers/firewalls, so let's change them. Some users have reported that the broken router was their very own DSL router.
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 ====
==== More about it ====


This section is based on the LWN article [http://lwn.net/Articles/92727/ TCP window scaling and broken routers] and a Kernel Trap article: [http://kerneltrap.org/node/6723 Window Scaling on the Internet].
This section is based on the LWN article [https://lwn.net/Articles/92727/ TCP window scaling and broken routers] and an archived Kernel Trap article: [https://web.archive.org/web/20120426135627/http://kerneltrap.org:80/node/6723 Window Scaling on the Internet].


There are also several relevant threads on the LKML.
There are also several relevant threads on the LKML.


=== Realtek no link / WOL problem ===
=== Connected second PC unable to use bridged LAN ===


Users with Realtek 8168 8169 8101 8111(C) based NICs (cards / and on-board) may notice a problem where the NIC seems to be disabled on boot and has no Link light. This can usually be found on a dual boot system where Windows is also installed. It seems that using the official Realtek drivers (dated anything after May 2007) under Windows is the cause. These newer drivers disable the Wake-On-LAN feature by disabling the NIC at Windows shutdown time, where it will remain disabled until the next time Windows boots. You will be able to notice if this problem is affecting you if the Link light remains off until Windows boots up; during Windows shutdown the Link light will switch off. Normal operation should be that the link light is always on as long as the system is on, even during POST. This problem will also affect other operating systems without newer drivers (eg. Live CDs). Here are a few fixes for this problem.
{{Move|Internet sharing|This is specific to a connection sharing setup.}}


==== Enable the NIC directly in Linux ====
First PC have two LAN. Second PC have one LAN and connected to first PC. Lets go second PC to give all access to LAN after bridged interface:


Follow [[#Enabling and disabling network interfaces]] to enable the interface.
{{Expansion|Explain what the settings actually do.}}


==== Rollback/change Windows driver ====
# sysctl net.bridge.bridge-nf-filter-pppoe-tagged=0
# sysctl net.bridge.bridge-nf-filter-vlan-tagged=0
# sysctl net.bridge.bridge-nf-call-ip6tables=0
# sysctl net.bridge.bridge-nf-call-iptables=0
# sysctl net.bridge.bridge-nf-call-arptables=0


You can roll back your Windows NIC driver to the Microsoft provided one (if available), or roll back/install an official Realtek driver pre-dating May 2007 (may be on the CD that came with your hardware).
=== localhost is resolved over the network ===


==== Enable WOL in Windows driver ====
{{man|8|nss-myhostname}} (an [[Name Service Switch|NSS]] module provided by [[systemd]] and enabled by default in {{ic|/etc/nsswitch.conf}}) provides {{ic|localhost}} and the local hostname resolution to an IP address. Some software may, however, still instead read {{ic|/etc/hosts}} directly; see [https://lists.debian.org/debian-devel/2013/07/msg00809.html] [https://bugzilla.mozilla.org/show_bug.cgi?id=87717#c55] for examples.


Probably the best and the fastest fix is to change this setting in the Windows driver. This way it should be fixed system-wide and not only under Arch (eg. live CDs, other operating systems). In Windows, under Device Manager, find your Realtek network adapter and double-click it. Under the "Advanced" tab, change "Wake-on-LAN after shutdown" to "Enable".
To prevent such software from unsafely resolving localhost over the network, add entries for {{ic|localhost}} to the {{man|5|hosts}} file:


In Windows XP (example):
{{hc|/etc/hosts|
127.0.0.1        localhost
::1              localhost
}}


Right click my computer and choose "Properties"
{{Note|Report any software affected by this issue in {{Bug|56684}}. This may help in getting {{ic|localhost}} entries added to the default {{ic|/etc/hosts}}.}}
--> "Hardware" tab
  --> Device Manager
    --> Network Adapters
      --> "double click" Realtek ...
        --> Advanced tab
          --> Wake-On-Lan After Shutdown
            --> Enable


{{Note|Newer Realtek Windows drivers (tested with ''Realtek 8111/8169 LAN Driver v5.708.1030.2008'', dated 2009/01/22, available from GIGABYTE) may refer to this option slightly differently, like ''Shutdown Wake-On-LAN --> Enable''. It seems that switching it to {{ic|Disable}} has no effect (you will notice the Link light still turns off upon Windows shutdown). One rather dirty workaround is to boot to Windows and just reset the system (perform an ungraceful restart/shutdown) thus not giving the Windows driver a chance to disable LAN. The Link light will remain on and the LAN adapter will remain accessible after POST - that is until you boot back to Windows and shut it down properly again.}}
To allow resolving the local hostname, additionally add it to the {{man|5|hosts}} file:


==== Newer Realtek Linux driver ====
{{hc|/etc/hosts|
 
127.0.0.1        localhost
Any newer driver for these Realtek cards can be found for Linux on the realtek site (untested but believed to also solve the problem).
::1              localhost
 
127.0.1.1        ''yourhostname''
==== Enable ''LAN Boot ROM'' in BIOS/CMOS ====
}}
 
It appears that setting ''Integrated Peripherals --> Onboard LAN Boot ROM --> Enabled'' in BIOS/CMOS reactivates the Realtek LAN chip on system boot-up, despite the Windows driver disabling it on OS shutdown.


{{Note|This was tested several times on a GIGABYTE GA-G31M-ES2L motherboard, BIOS version F8 released on 2009/02/05.}}
For a system with a permanent IP address, replace {{ic|127.0.1.1}} with that permanent IP address. For a system with a [[Wikipedia:Fully qualified domain name|fully qualified domain name]], insert the fully qualified domain name before the hostname (see the following link for [https://www.debian.org/doc/manuals/debian-reference/ch05.en.html#_the_hostname_resolution the reasoning]). For example:


=== No interface with Atheros chipsets ===
{{hc|/etc/hosts|
 
127.0.0.1        localhost
Users of some Atheros ethernet chips are reporting it does not work out-of-the-box (with installation media of February 2014). The working solution for this is to install {{AUR|backports-patched}}.
::1              localhost
 
203.0.113.45    host1.fqdomain.example host1
=== Broadcom BCM57780 ===
 
This Broadcom chipset sometimes does not behave well unless you specify the order of the modules to be loaded. The modules are {{ic|broadcom}} and {{ic|tg3}}, the former needing to be loaded first.
 
These steps should help if your computer has this chipset:
 
* Find your NIC in ''lspci'' output:
 
{{hc|<nowiki>$ lspci | grep Ethernet</nowiki>|
02:00.0 Ethernet controller: Broadcom Corporation NetLink BCM57780 Gigabit Ethernet PCIe (rev 01)
}}
}}


* If your wired networking is not functioning in some way or another, try unplugging your cable then doing the following:
{{Note|The order of hostnames/aliases that follow the IP address in {{ic|/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. All following strings on the same line are considered aliases. See {{man|5|hosts}} for more information.}}


# modprobe -r tg3
As a result the system resolves to both entries:
# modprobe broadcom
# modprobe tg3


* Plug your network cable in. If this solves your problems you can make this permanent by adding {{ic|broadcom}} and {{ic|tg3}} (in this order) to the {{ic|MODULES}} array in {{ic|/etc/mkinitcpio.conf}}:
{{hc|$ getent hosts|
 
127.0.0.1      localhost
MODULES=".. broadcom tg3 .."
127.0.0.1      localhost
 
127.0.1.1      ''yourhostname''
* Rebuild the initramfs:
 
# mkinitcpio -p linux
 
* Alternatively, you can create an {{ic|/etc/modprobe.d/broadcom.conf}}:
 
softdep tg3 pre: broadcom
 
{{Note|These methods may work for other chipsets, such as BCM57760.}}
 
=== Realtek RTL8111/8168B ===
 
{{hc|<nowiki># lspci | grep Ethernet</nowiki>|
03:00.0 Ethernet controller: Realtek Semiconductor Co., Ltd. RTL8111/8168B PCI Express Gigabit Ethernet controller (rev 02)
}}
}}
The adapter should be recognized by the {{ic|r8169}} module. However, with some chip revisions the connection may go off and on all the time. The alternative {{Pkg|r8168}} should be used for a reliable connection in this case. [[Blacklist]] {{ic|r8169}}, if {{Pkg|r8168}} is not automatically loaded by [[udev]], see [[Kernel modules#Automatic module handling]].
{{Accuracy|"some revisions", no proof the driver is the cause, and not e.g poorly configured DNS servers}}
Another fault in the drivers for some revisions of this adapter is poor IPv6 support. [[IPv6#Disable functionality]] can be helpful if you encounter issues such as hanging webpages and slow speeds.
=== Gigabyte Motherboard with Realtek 8111/8168/8411 ===
With motherboards such as the ''Gigabyte GA-990FXA-UD3'', booting with [[PCI_passthrough_via_OVMF#Setting_up_IOMMU|IOMMU]] off (which can be the default) will cause the network interface to be unreliable, often failing to connect or connecting but allowing no throughput. This will apply to the onboard NIC an to any other pci-NIC in the box because the IOMMU setting affects the entire network interface on the board. Enabling IOMMU and booting with the install media will throw AMD I-10/xhci page faults for a second, but then boots normally, resulting in a fully functional onboard NIC (even with the r8169 module).
When configuring the boot process for your installation, add {{ic|1=iommu=soft}} as a [[kernel parameter]] to eliminate the error messages on boot and restore USB3.0 functionality.


== See also ==
== See also ==


* [https://www.tldp.org/LDP/nag2/index.html Linux Network Administrators Guide]
* [https://www.debian.org/doc/manuals/debian-reference/ch05.en.html Debian Reference: Network setup]
* [https://www.debian.org/doc/manuals/debian-reference/ch05.en.html Debian Reference: Network setup]
* [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/ RHEL7: Networking Guide]
* [https://access.redhat.com/documentation/en-US/Red_Hat_Enterprise_Linux/7/html/Networking_Guide/ RHEL7: Networking Guide]
* [http://www.linuxhomenetworking.com/wiki/ Linux Home Networking]
* [https://blog.packagecloud.io/eng/2016/06/22/monitoring-tuning-linux-networking-stack-receiving-data/ Monitoring and tuning the Linux Networking Stack: Receiving data]
* [https://blog.packagecloud.io/eng/2016/06/22/monitoring-tuning-linux-networking-stack-receiving-data/ Monitoring and tuning the Linux Networking Stack: Receiving data]
* [https://blog.packagecloud.io/eng/2017/02/06/monitoring-tuning-linux-networking-stack-sending-data/ Monitoring and tuning the Linux Networking Stack: Sending data]
* [https://blog.packagecloud.io/eng/2017/02/06/monitoring-tuning-linux-networking-stack-sending-data/ Monitoring and tuning the Linux Networking Stack: Sending data]
* [http://blog.yadutaf.fr/2017/07/28/tracing-a-packet-journey-using-linux-tracepoints-perf-ebpf/ Tracing a packet journey using tracepoints, perf and eBPF]
* [https://blog.yadutaf.fr/2017/07/28/tracing-a-packet-journey-using-linux-tracepoints-perf-ebpf/ Tracing a packet journey using tracepoints, perf and eBPF]

Latest revision as of 20:43, 21 March 2024

This article describes how to configure network connections on OSI layer 3 and above. Medium-specifics are handled in the /Ethernet and /Wireless subpages.

Check the connection

This article or section needs expansion.

Reason: Step 4. is unclear, #Routing table does not explain what a correct setup looks like. (Discuss in Talk:Network configuration)

To troubleshoot a network connection, go through the following conditions and ensure that you meet them:

  1. Your network interface is listed and enabled. Otherwise, check the device driver – see /Ethernet#Device driver or /Wireless#Device driver.
  2. You are connected to the network. The cable is plugged in or you are connected to the wireless LAN.
  3. Your network interface has an IP address.
  4. Your routing table is correctly set up.
  5. You can ping a local IP address (e.g. your default gateway).
  6. You can ping a public IP address (e.g. 9.9.9.9, which is a DNS server operated by the Quad9 Foundation and is a convenient address to test with).
  7. Check if you can resolve domain names (e.g. archlinux.org).

Ping

ping is used to test if you can reach a host.

$ ping www.example.com
PING www.example.com (93.184.216.34) 56(84) bytes of data.
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=1 ttl=56 time=11.632 ms
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=2 ttl=56 time=11.726 ms
64 bytes from 93.184.216.34 (93.184.216.34): icmp_seq=3 ttl=56 time=10.683 ms
...

For every reply received, the ping utility will print a line like the above until you interrupt (Ctrl+c) it interactively. For more information see the ping(8) manual. Note that computers can be configured not to respond to ICMP echo requests. [1]

If you receive an error message (see ping error indications) or no reply, this may be related to incomplete configuration, but also your default gateway or your Internet Service Provider (ISP). You can run a traceroute to further diagnose the route to the host.

Network management

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: Split into manual configuration with iproute2 and automatic with DHCP & SLAAC. (Discuss in Talk:Network configuration)

To set up a network connection, go through the following steps:

  1. Ensure your network interface is listed and enabled.
  2. Connect to the network. Plug in the Ethernet cable or connect to the wireless LAN.
  3. Configure your network connection:
Note: The installation image uses

Manual

iproute2

This article or section needs language, wiki syntax or style improvements. See Help:Style for reference.

Reason: This section does not fit in #Network management – it does not manage anything, it only introduces the iproute2 package. (Discuss in Talk:Network configuration)

iproute2 is a dependency of the base meta package and provides the ip(8) command-line interface, used to manage network interfaces, IP addresses and the routing table. Be aware that configuration made using ip will be lost after a reboot. For persistent configuration, you can automate ip commands using scripts and systemd units. Also note that ip commands can generally be abbreviated, for clarity they are however spelled out in this article.

Note: Arch Linux has deprecated net-tools in favor of iproute2.[2] See also Deprecated Linux networking commands and their replacements.

Static IP address

A static IP address can be configured with most standard network managers and also dhcpcd.

To manually configure a static IP address, add an IP address as described in #IP addresses, set up your routing table and configure your DNS servers.

IP addresses

IP addresses are managed using ip-address(8).

List IP addresses:

$ ip address show

Add an IP address to an interface:

# ip address add address/prefix_len broadcast + dev interface
Note that:
Note: Make sure manually assigned IP addresses do not conflict with DHCP assigned ones.

Delete an IP address from an interface:

# ip address del address/prefix_len dev interface

Delete all addresses matching a criteria, e.g. of a specific interface:

# ip address flush dev interface
Tip: IPv4 addresses can be calculated with ipcalc (ipcalc).

Routing table

The routing table is used to determine if you can reach an IP address directly or what gateway (router) you should use. If no other route matches the IP address, the default gateway is used.

The routing table is managed using ip-route(8).

PREFIX is either a CIDR notation or default for the default gateway.

List IPv4 routes:

$ ip route show

List IPv6 routes:

$ ip -6 route show

Add a route:

# ip route add PREFIX via address dev interface

Delete a route:

# ip route del PREFIX via address dev interface

Automatic

This article or section needs expansion.

Reason: Explain SLAAC. (Discuss in Talk:Network configuration)

Automatic network configuration is accomplished using Dynamic Host Configuration Protocol (DHCP). The network's DHCP server provides IP address(es), the default gateway IP address(es) and optionally also DNS name servers upon request from the DHCP client.

See Router#DNS and DHCP for a DHCP server comparison table.

Network managers

A network manager lets you manage network connection settings in so called network profiles to facilitate switching networks.

Tip: You can check if a DHCPv4 server is running with dhcping.
Note: Each network interface should be managed by only one DHCP client or network manager, so it is advised to run only one DHCP client or network manager on the system.
Software Connection type Wireless authentication IP address, route and DNS management Interface
Ethernet PPPoE Mobile broadband WPA/WPA2 WPA3 Static IP DHCP client Domain name resolution CLI TUI GUI
dhclient1 Yes No No No2 Yes internal Yes (writes /etc/resolv.conf) No No No
dhcpcd Yes No No Launches wpa_supplicant3 Yes internal Yes (uses resolvconf or writes /etc/resolv.conf) No No dhcpcd-uiAUR
ConnMan Yes [dead link 2023-10-29 ⓘ] No Yes (via ofonoAUR) Yes (via wpa_supplicant or iwd) Yes internal Yes (runs a builtin resolver and writes /etc/resolv.conf) connmanctl(1) Yes Yes
netctl Yes Yes (via ppp) Yes (via ppp) Yes (via wpa_supplicant) No Yes dhcpcd or dhclient Yes (uses resolvconf) netctl(1) wifi-menu(1)4 No
NetworkManager Yes Yes (via rp-pppoe) Yes (via modemmanager) Yes (via wpa_supplicant or iwd) Yes internal, dhclient or dhcpcd5 Yes (uses systemd-resolved, resolvconf or writes /etc/resolv.conf) nmcli(1) nmtui(1) Yes
systemd-networkd Yes No No No2 Yes internal Yes (uses systemd-resolved) networkctl(1) No No
wpa_supplicant IEEE 802.1X No No Yes Yes No wpa_cli(8) No wpa_supplicant_guiAUR
iwd IEEE 802.1X No No Yes Yes Yes internal Yes (uses systemd-resolved or resolvconf) iwctl(1) No iwgtkAUR
  1. No longer maintained as of early 2022. ISC advises no longer using it in production.
  2. Wireless authentication can be configured separately with wpa_supplicant or iwd.
  3. Wireless authentication must be configured separately with wpa_supplicant.
  4. Only Wi-Fi connections can be managed.
  5. NetworkManager does not use dhcpcd for DHCPv6, see NetworkManager#DHCP client.

Network interfaces

Network interfaces are managed by udev and configured by systemd.link(5) files. The default configuration assigns names to your network interface controllers using Predictable Network Interface Names, which prefixes interfaces names with en (wired/Ethernet), wl (wireless/WLAN), or ww (mobile broadband/WWAN). See systemd.net-naming-scheme(7).

Tip:
  • The system /usr/lib/systemd/network/99-default.link is generally sufficient for most cases.
  • To change interface names, see #Change interface name and #Revert to traditional interface names.
  • You can run udevadm test-builtin net_setup_link /sys/path/to/network/device as the root user to diagnose problems with .link files.

Listing network interfaces

Both wired and wireless interface names can be found via ls /sys/class/net or ip link. Note that lo is the virtual loopback interface and not used in making network connections.

Wireless device names can also be retrieved using iw dev. See also /Wireless#Get the name of the interface.

If your network interface is not listed, make sure your device driver was loaded successfully. See /Ethernet#Device driver or /Wireless#Device driver.

Enabling and disabling network interfaces

Network interfaces can be enabled or disabled using ip link set interface up|down, see ip-link(8).

To check the status of the interface enp2s0:

$ ip link show dev enp2s0
2: enp2s0: <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.

Note: If your default route is through interface enp2s0, taking it down will also remove the route, and bringing it back up will not automatically re-establish the default route. See #Routing table for re-establishing it.

Change interface name

Note: When changing the naming scheme, do not forget to update all network-related configuration files and custom systemd unit files to reflect the change.

You can change the device name by defining the name manually with an systemd.link(5) file. For example:

/etc/systemd/network/10-net0.link
[Match]
PermanentMACAddress=aa:bb:cc:dd:ee:ff

[Link]
Name=net0

Alternatively, a udev rule can be used:

/etc/udev/rules.d/10-network.rules
SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="aa:bb:cc:dd:ee:ff", NAME="net0"

These rules will be applied automatically at boot. To apply the change immediately, do a manual trigger of the udev rule on the net subsystem:

# udevadm trigger --verbose --subsystem-match=net --action=add

If you want to run a test on the changes made, udevadm --debug test /sys/class/net/* can be of help.

Note:
  • The priority of Name is lower than NamePolicy, so make sure the latter is unset/empty or the name will not be changed. 99-default.link sets NamePolicy, requiring the custom config to be ordered before it, i.e. to have a numerical prefix.
  • The network interface must be down before changing its name. [3]
  • To get the MAC address of each card, run ip link.
  • 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 Path (which can be checked using networkctl status interface_name):

/etc/systemd/network/10-net1.link
[Match]
Path=pci-0000:01:00.0

[Link]
Name=net1

Or, use a udev rule with DEVPATH:

/etc/udev/rules.d/10-network.rules
SUBSYSTEM=="net", DEVPATH=="/devices/pci*/*1c.0/*/net/*", NAME="net1"

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 given rule, "/devices/pci*/*1c.0/*/net/en*" would be wrong since it will stop matching once the name is changed to net1. Only the system-default rule will fire the second time around, causing the name to be changed back.

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 model ID instead:

/etc/systemd/network/20-net2.link
[Match]
Property=ID_VENDOR_ID=12ab ID_MODEL_ID=3cd4

[Link]
Name=net2

or

/etc/udev/rules.d/10-network.rules
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="12ab", ATTRS{idProduct}=="3cd4", NAME="net2"
Note: When choosing the static names it should be avoided to use names in the format of "ethX" and "wlanX", because this may lead to race conditions between the kernel and udev during boot. Instead, it is better to use interface names that are not used by the kernel as default, e.g.: 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 changing the default NamePolicy for udev's net_setup_link built-in:

/etc/systemd/network/99-default.link.d/traditional-naming.conf
[Link]
NamePolicy=keep kernel

Alternatively, net_setup_link can be completely disabled by masking the corresponding udev rule:

# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules

or by adding net.ifnames=0 to the kernel parameters.

Note: systemd.link(5) relies on net_setup_link to work. Prefer to use the first approach unless you fully understand what you are doing.

Set device MTU and queue length

You can change the device MTU and queue length by defining manually with a systemd.link(5) config. For example:

/etc/systemd/network/30-mtu.link
[Match]
Type=wlan

[Link]
MTUBytes=1500
TransmitQueueLength=2000

Or through a udev rule:

/etc/udev/rules.d/10-network.rules
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wl*", ATTR{mtu}="1500", ATTR{tx_queue_len}="2000"

MTUBytes: Using a value larger than 1500 (so called jumbo frames) can significantly speed up your network transfers. Note that all network interfaces, including switches in the local network, must support the same MTU in order to use jumbo frames. For PPPoE, the MTU should not be larger than 1492. You can also set MTU via systemd.netdev(5).

TransmitQueueLength: Small value for slower devices with a high latency like modem links and ISDN. High value is recommended for server connected over the high-speed internet connections that perform large data transfers.

Set the hostname

A hostname is a unique name created to identify a machine on a network, configured in /etc/hostname—see hostname(5) and hostname(7) for details. The file can contain the system's domain name, if any. To set the hostname, edit /etc/hostname to include a single line with yourhostname:

/etc/hostname
yourhostname
Tip: For advice on choosing a hostname, see RFC 1178.

Alternatively, using hostnamectl(1):

# hostnamectl hostname yourhostname

To temporarily set the hostname (until reboot), use hostname(1) from inetutils:

# hostname yourhostname

To set the "pretty" hostname and other machine metadata, see machine-info(5).

Local network hostname resolution

To make your machine accessible in your LAN via its hostname you can:

  • edit the /etc/hosts file for every device in your LAN, see hosts(5)
  • set up a DNS server to resolve your hostname and make the LAN devices use it (e.g. via DHCP)
  • or the easy way: use a Zero-configuration networking service:
    • Hostname resolution via Microsoft's NetBIOS. Provided by Samba on Linux. It only requires the nmb.service. Computers running Windows, macOS, or Linux with nmb running, will be able to find your machine.
    • Hostname resolution via mDNS. Provided by either nss_mdns with Avahi (see Avahi#Hostname resolution for setup details) or systemd-resolved. Computers running macOS, or Linux with Avahi or systemd-resolved running, will be able to find your machine. The older Win32 API does not support mDNS, which may prevent some older Windows applications from accessing your device.

Tips and tricks

Bonding or LAG

See netctl or systemd-networkd, 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 enp2s0 label enp2s0:1

To remove a given alias execute

# ip addr del 192.168.2.101/24 dev enp2s0: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 enp2s0, enable promiscuous@enp2s0.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 64KiB. 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 64KiB.

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 output from dmesg is okay, 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.

Connected second PC unable to use bridged LAN

This article or section is a candidate for moving to Internet sharing.

Notes: This is specific to a connection sharing setup. (Discuss in Talk:Network configuration)

First PC have two LAN. Second PC have one LAN and connected to first PC. Lets go second PC to give all access to LAN after bridged interface:

This article or section needs expansion.

Reason: Explain what the settings actually do. (Discuss in Talk:Network configuration)
# sysctl net.bridge.bridge-nf-filter-pppoe-tagged=0
# sysctl net.bridge.bridge-nf-filter-vlan-tagged=0
# sysctl net.bridge.bridge-nf-call-ip6tables=0
# sysctl net.bridge.bridge-nf-call-iptables=0
# sysctl net.bridge.bridge-nf-call-arptables=0

localhost is resolved over the network

nss-myhostname(8) (an NSS module provided by systemd and enabled by default in /etc/nsswitch.conf) provides localhost and the local hostname resolution to an IP address. Some software may, however, still instead read /etc/hosts directly; see [4] [5] for examples.

To prevent such software from unsafely resolving localhost over the network, add entries for localhost to the hosts(5) file:

/etc/hosts
127.0.0.1        localhost
::1              localhost
Note: Report any software affected by this issue in FS#56684. This may help in getting localhost entries added to the default /etc/hosts.

To allow resolving the local hostname, additionally add it to the hosts(5) file:

/etc/hosts
127.0.0.1        localhost
::1              localhost
127.0.1.1        yourhostname

For a system with a permanent IP address, replace 127.0.1.1 with that permanent IP address. For a system with a fully qualified domain name, insert the fully qualified domain name before the hostname (see the following link for the reasoning). For example:

/etc/hosts
127.0.0.1        localhost
::1              localhost
203.0.113.45     host1.fqdomain.example host1
Note: The order of hostnames/aliases that follow the IP address in /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. All following strings on the same line are considered aliases. See hosts(5) for more information.

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       yourhostname

See also