Difference between revisions of "Network configuration"

From ArchWiki
Jump to navigation Jump to search
 
Line 1: Line 1:
[[Category:Networking (English)]]
+
[[Category:Network configuration]]
[[Category:Getting and installing Arch (English)]]
+
[[cs:Network configuration]]
[[Category:HOWTOs (English)]]
+
[[el:Network configuration]]
 +
[[es:Network configuration]]
 +
[[fr:Connexions reseau]]
 +
[[it:Network configuration]]
 +
[[ja:ネットワーク設定]]
 +
[[nl:Network configuration]]
 +
[[pt:Network configuration]]
 +
[[ru:Network configuration]]
 +
[[sk:Network configuration]]
 +
[[zh-hans:Network configuration]]
 +
[[zh-hant:Network configuration]]
 +
{{Related articles start}}
 +
{{Related|Network Debugging}}
 +
{{Related|Firewalls}}
 +
{{Related|Jumbo frames}}
 +
{{Related|Internet sharing}}
 +
{{Related|Router}}
 +
{{Related articles end}}
  
{{i18n_links_start}}
+
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.
{{i18n_entry|English|Configuring_network}}
 
{{i18n_entry|Español|Configurando la Red}}
 
{{i18n_entry|Italiano|Configuring_network_(Italiano)}}
 
{{i18n_entry|Slovensky|Statická IP a DHCP}}
 
{{i18n_entry|Русский|Статический IP и DHCP}}
 
{{i18n_entry|Česky|Statická IP a DHCP czech}}
 
{{i18n_entry|简体中文|网络配置}}
 
{{i18n_links_end}}
 
  
== Summary ==
+
== Check the connection ==
  
A simple guide to get your network running.
+
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|8.8.8.8}}, which is a Google DNS server and is a convenient address to test with).
 +
# [[Check if you can resolve domain names]] (e.g. {{ic|archlinux.org}}).
  
== Load the device module ==
+
=== Ping ===
  
Udev should detect your network card (NIC) module and load it automatically at startup. Otherwise, you will need to know which module is needed for your particular model:
+
{{Expansion|Add or link explanation of common ping errors like Unknown hosts / Network is unreachable.}}
 
hwdetect --show-net
 
  
Now when you know which module to use you can load it:
+
[[Wikipedia:Ping (networking utility)|ping]] is used to test if you can reach a host.
  
# modprobe <modulename>
+
{{hc|$ ping www.example.com|2=
 +
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
 +
...
 +
}}
  
If udev is not detecting and loading the proper module automatically, you can add it into the '''MODULES=''' array in <code>/etc/rc.conf</code>, so you don't need to modprobe it everytime you boot. For example, if tg3 is the network module:
+
For every reply you receive, the ping utility will print a line like the above. 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]
  
MODULES=(!usbserial tg3 snd-cmipci)
+
If you receive no reply, this may be related to your default gateway or your Internet Service Provider (ISP). You can run a [[traceroute]] to further diagnose the route to the host.
  
Other common modules are 8139too for cards with the Realtek chipset or sis900 for SiS cards.
+
{{Note|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.}}
  
== Configure IP ==
+
== Network management ==
  
=== For DHCP IP ===
+
To set up a network connection, go through the following steps:
  
For this, you need the dhcpcd package (already available on most installations). Edit <code>/etc/rc.conf</code> like this:
+
# Ensure your [[#Network interfaces|network interface]] is listed and enabled.
 +
# Connect to the network. Plug in the Ethernet cable or [[/Wireless|connect to the wireless LAN]].
 +
# Configure your network connection:
 +
#* [[#Static IP address|static IP address]]
 +
#* dynamic IP address: use [[#DHCP|DHCP]]
  
  eth0="dhcp"
+
{{Note|The installation image enables [[dhcpcd]] ({{ic|dhcpcd@''interface''.service}}) for [https://git.archlinux.org/archiso.git/tree/configs/releng/airootfs/etc/udev/rules.d/81-dhcpcd.rules wired network devices] on boot.}}
INTERFACES=(eth0)
 
ROUTES=(!gateway)
 
  
If you use DHCP and you don't want your DNS servers to change every time you start your network, be sure to add the "-R" option to <code>DHCPCD_ARGS</code> in <code>/etc/conf.d/dhcpcd</code> (used by <code>/etc/rc.d/network</code>). This prevents DHCP from rewriting your <code>/etc/resolv.conf</code> every time:
+
=== net-tools ===
  
DHCPCD_ARGS="-R -t 30 -h $HOSTNAME"
+
Arch Linux has deprecated {{Pkg|net-tools}} in favor of {{Pkg|iproute2}}.[https://www.archlinux.org/news/deprecation-of-net-tools/]
  
Additonally, make sure to add a valid nameserver(s) to <code>/etc/resolv.conf</code>. A sample <code>/etc/resolv.conf</code>:
+
{| class="wikitable"
 +
! Deprecated command !! Replacement commands
 +
|-
 +
| arp || ip neighbor
 +
|-
 +
| [[Wikipedia:ifconfig|ifconfig]] || ip address, ip link
 +
|-
 +
| netstat || [[#Investigate sockets|ss]]
 +
|-
 +
| route || ip route
 +
|}
  
#DHCP but using the same DNS
+
For a more complete rundown, see [https://dougvitale.wordpress.com/2011/12/21/deprecated-linux-networking-commands-and-their-replacements/ this blog post].
nameserver 4.2.2.2
 
nameserver 4.2.2.4
 
  
Finally, if you do not want to reboot, make sure to test your new settings by stopping and starting the <code>/etc/rc.d/network</code> daemon as opposed to bringing down your interface and starting dhcp manually. To restart the network daemon:
+
=== iproute2 ===
  
/etc/rc.d/network restart
+
[[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 use a [[network manager]] or 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.
  
=== For Static IP ===
+
=== Network interfaces ===
  
If you share your internet connection from a Windows box without a router, be sure to use static IPs on both computers. Otherwise you will have LAN issues.
+
By default [[udev]] assigns names to your network interfaces using [http://www.freedesktop.org/wiki/Software/systemd/PredictableNetworkInterfaceNames Predictable Network Interface Names], which prefixes interfaces names with {{ic|en}} (wired/[[Wikipedia:Ethernet|Ethernet]]), {{ic|wl}} (wireless/WLAN), or {{ic|ww}} ([[Wikipedia:Wireless WAN|WWAN]]).
  
You need:
+
{{Tip|To change interface names, see [[#Change interface name]] and [[#Revert to traditional interface names]].}}
  
* Your static IP address,
+
==== Listing network interfaces ====
* The netmask,
 
* The broadcast address,
 
* Your gateway,
 
* Your nameservers' IP addresses,
 
* Your domain name.
 
  
If you are running a private network, it is safe to use IP addresses in 192.168.*.'* for your IPs, with a netmask of 255.255.0.0 and broadcast address of 192.168.255.255.  Unless your network has a router, the gateway address does not matter.  Edit <code>/etc/rc.conf</code> like this, substituting your own values for the IP, netmask, broadcast, and gateway:
+
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:loop device|loop device]] and not used in making network connections.
  
  eth0="eth0 82.137.129.59 netmask 255.255.255.0 broadcast 82.137.129.255"
+
Wireless device names can also be retrieved using {{ic|iw dev}}. See also [[/Wireless#Get the name of the interface]].
INTERFACES=(eth0)
 
gateway="default gw 82.137.129.1"
 
ROUTES=(gateway)
 
  
and your <code>/etc/resolv.conf</code> like this, substituting your nameservers' IPs and your domain name:
+
If your network interface is not listed, make sure your device driver was loaded successfully. See [[/Ethernet#Device driver]] or [[/Wireless#Device driver]].
  
nameserver 61.23.173.5
+
==== Enabling and disabling network interfaces ====
nameserver 61.95.849.8
 
search example.com
 
  
You may include as many nameserver lines as you wish.
+
Network interfaces can be enabled / disabled using {{ic|ip link set ''interface'' up{{!}}down}}, see {{man|8|ip-link}}.
  
==Other option==
+
To check the status of the interface {{ic|eth0}}:
If for some reason dhcpcd eth0 fails, install dhclient (pacman -Sy dhclient)
 
and use '<code>dhclient eth0</code>' instead.
 
  
== Set computer name ==
+
{{hc|$ 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
 +
...
 +
}}
  
Edit <code>/etc/rc.conf</code> and set HOSTNAME to your desired computer name:
+
The {{ic|UP}} in {{ic|<BROADCAST,MULTICAST,UP,LOWER_UP>}} is what indicates the interface is up, not the later {{ic|state DOWN}}.
HOSTNAME="banana"
 
  
 +
{{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 re-establish the default route.  See [[#Routing table]] for re-establishing it.}}
  
== Set host name/IP ==
+
=== Static IP address ===
  
Edit <code>/etc/hosts</code> and add the same HOSTNAME you entered in <code>/etc/rc.conf</code> :
+
A static IP address can be configured with most standard [[#Network managers|network managers]] and also [[dhcpcd]].
127.0.0.1      banana.domain.org  localhost.localdomain      localhost    banana
 
  
This format, including the localhost entries is required for program compatibility.
+
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]].
  
== Load configuration ==
+
=== IP addresses ===
To test your settings either reboot the computer, or as root, run <code>/etc/rc.d/network restart</code>.
 
Try pinging your gateway, DNS server, ISP provider and other Internet sites, in that order, to detect any connection problems along the way.
 
  
 +
[[Wikipedia:IP address|IP addresses]] are managed using {{man|8|ip-address}}.
  
== Some more settings ==
+
List IP addresses:
  
=== Wireless Setup ===
+
$ ip address show
  
See [[Wireless Setup]] for more informations.
+
Add an IP address to an interface:
  
=== Firewall ===
+
# ip address add ''address/prefix_len'' broadcast + dev ''interface''
  
You can install and configure a [[Firewalls|firewall]] to feel more secure. ;-)
+
:Note that:
  
=== Ifplugd ===
+
:* 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
  
You can install 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 don't want to restart the computer or do it from the shell.
+
:{{Note|Make sure manually assigned IP addresses do not conflict with DHCP assigned ones.}}
  
Installation is very simple since it's in [extra]:
+
Delete an IP address from an interface:
  
  # pacman -S ifplugd
+
  $ ip address del ''address/prefix_len'' dev ''interface''
  
By default it is configured to work for eth0 device. This and other settings like delays can be configured in <code>/etc/ifplugd/ifplugd.conf</code>.
+
Delete all addresses matching a criteria, e.g. of a specific interface:
  
Start it with
+
$ ip address flush dev ''interface''
  
# /etc/rc.d/ifplugd start
+
{{Tip|IP addresses can be calculated with [http://jodies.de/ipcalc ipcalc] ({{Pkg|ipcalc}}).}}
  
or add it into DAEMONS array in <code>/etc/rc.conf</code>.
+
=== Routing table ===
  
=== bonding ===
+
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.
You can install 'ifenslave' to bind two real Ethernet cables with one IP address.
 
/etc/conf.d/bonding
 
bond_bond0="eth0 eth1"
 
BOND_INTERFACES=(bond0)
 
/etc/modprobe.conf:
 
options bonding miimon=100
 
/etc/rc.conf
 
MODULES=(... bonding ...)
 
bond0="bond0 192.168.1.1 netmask 255.255.255.0 broadcast 192.168.1.255"
 
INTERFACES=(bond0)
 
restart network by
 
/etc/rc.d/network restart
 
  
=== multiple ip on multiple card===
+
The routing table is managed using {{man|8|ip-route}}.
one ip on one card
 
vi /etc/rc.conf
 
  eth0="eth0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255"
 
  INTERFACES=(lo eth0)
 
two ip on one card (BUG:/etc/rc.d/network stop)
 
vi /etc/rc.conf
 
  eth0="eth0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255"
 
  eth0_0="eth0:0 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255"
 
  INTERFACES=(lo eth0 eth0_0)
 
one ip on two card
 
pacman -S ifenslave
 
vi /etc/rc.conf
 
  bond0="bond0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255"
 
  INTERFACES=(lo bond0)
 
  MODULES=(... bonding ...)
 
two ip on two card (BUG:/etc/rc.d/network stop)
 
pacman -S ifenslave
 
vi /etc/rc.conf
 
  bond0="bond0 192.168.0.1 netmask 255.255.255.0 broadcast 192.168.0.255"
 
  bond01="bond0:1 192.168.0.2 netmask 255.255.255.0 broadcast 192.168.0.255"
 
  INTERFACES=(lo bond0 bond01)
 
  MODULES=(... bonding ...)
 
  
== Troubleshooting ==
+
''PREFIX'' is either a CIDR notation or {{ic|default}} for the default gateway.
 +
 
 +
List IPv4 routes:
 +
 
 +
$ ip route show
 +
 
 +
List IPv6 routes:
 +
 
 +
$ ip -6 route
 +
 
 +
Add a route:
 +
 
 +
# ip route add ''PREFIX'' via ''address'' dev ''interface''
 +
 
 +
Delete a route:
 +
 
 +
# ip route del ''PREFIX'' via ''address'' dev ''interface''
 +
 
 +
=== DHCP ===
 +
 
 +
A [[Wikipedia:Dynamic Host Configuration Protocol|Dynamic Host Configuration Protocol]] (DHCP) server provides clients with a dynamic IP address, the subnet mask, the default gateway IP address and optionally also with DNS name servers.
 +
 
 +
To use DHCP you need a DHCP server in your network and a DHCP client:
 +
 
 +
{| class="wikitable"
 +
! Client !! Package !! [[Archiso]] !! Note !! Systemd units
 +
|-
 +
| [[dhcpcd]] || {{Pkg|dhcpcd}} || {{Yes}} || DHCP, DHCPv6, ZeroConf, static IP || {{ic|dhcpcd.service}}, {{ic|dhcpcd@''interface''.service}}
 +
|-
 +
| [https://www.isc.org/downloads/dhcp/ ISC dhclient] || {{Pkg|dhclient}} || {{Yes}} || DHCP, DHCPv6, BOOTP, static IP || {{ic|dhclient@''interface''.service}}
 +
|}
 +
 
 +
{{Note|
 +
* You should not run two DHCP clients simultaneously.
 +
* Instead of directly using a DHCP client you can also use a [[#Network managers|network manager]].
 +
}}
 +
 
 +
{{Tip|You can check if a DHCP server is running with {{Pkg|dhcping}}.}}
 +
 
 +
==== Servers ====
 +
 
 +
{{Expansion|[[systemd-networkd]] has DHCP server support.}}
 +
 
 +
{| class="wikitable"
 +
! Server !! Package !! IPv4 !! IPv6 !! GUI  !! Interfaces !! Storage backend(s) !! Note
 +
|-
 +
| [[dhcpd]] || {{Pkg|dhcp}} || {{Yes}} || {{Yes}} || [https://github.com/Akkadius/glass-isc-dhcp Glass-ISC-DHCP] || ? || File ||
 +
|-
 +
| [[dnsmasq]] || {{Pkg|dnsmasq}} || {{Yes}} || {{Yes}} || {{No}} || ? || File || Also DNS, PXE and TFTP
 +
|-
 +
| [[Kea]] || {{Pkg|kea}} || {{Yes}} || {{Yes}} || [https://github.com/isc-projects/kea-anterius Kea-Anterius (Experimental)] || REST, RADIUS and NETCONF || File, MySQL, PostgreSQL and Cassandra || Also DNS
 +
|}
 +
 
 +
=== Network managers ===
 +
 
 +
A network manager lets you manage network connection settings in so called network profiles to facilitate switching networks.
 +
 
 +
{{Note|There are many solutions to choose from, but remember that all of them are mutually exclusive; you should not run two daemons simultaneously.}}
 +
 
 +
{| class="wikitable"
 +
! Network manager || GUI || [[Archiso]] [https://git.archlinux.org/archiso.git/tree/configs/releng/packages.x86_64] || CLI tools || [[Wikipedia:Point-to-Point Protocol|PPP]] support <br>(e.g. 3G modem) || [[#DHCP|DHCP client]] || Systemd units
 +
|-
 +
! [[ConnMan]]
 +
| {{Y|8 unofficial}} || {{No}} || {{man|1|connmanctl}} || {{Yes}} (with {{aur|ofono}}) || internal || {{ic|connman.service}}
 +
|-
 +
! [[netctl]]
 +
| {{Y|2 unofficial}} || {{Yes}} || {{man|1|netctl}}, wifi-menu || {{Yes}} || [[dhcpcd]] or {{Pkg|dhclient}} || {{ic|netctl-ifplugd@''interface''.service}}, {{ic|netctl-auto@''interface''.service}}
 +
|-
 +
! [[NetworkManager]]
 +
| {{Yes}} || {{No}} || {{man|1|nmcli}}, {{man|1|nmtui}} || {{Yes}} || internal, [[dhcpcd]] or {{Pkg|dhclient}} || {{ic|NetworkManager.service}}
 +
|-
 +
! [[systemd-networkd]]
 +
| {{No}} || {{Yes}} ({{Pkg|base}}) || {{man|1|networkctl}} || {{No|https://github.com/systemd/systemd/issues/481}} || internal || {{ic|systemd-networkd.service}}, {{ic|systemd-resolved.service}}
 +
|-
 +
! [[Wicd]]
 +
| {{Yes}} || {{No}} || {{man|8|wicd-cli|url=https://manned.org/wicd-cli.8}}, {{man|8|wicd-curses|url=https://manned.org/wicd-curses.8}} || {{No}} || [[dhcpcd]] || {{ic|wicd.service}}
 +
|}
 +
 
 +
There also is [[Wifi Radar]], a GUI application to manage WiFi networks with {{Pkg|wireless_tools}}, it however does not handle wired connections.
 +
 
 +
See also [[List of applications#Network managers]].
 +
 
 +
== Set the hostname ==
 +
 
 +
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''}}:
 +
 
 +
{{hc|/etc/hostname|
 +
''myhostname''
 +
}}
 +
 
 +
{{Tip|For advice on choosing a hostname, see [https://tools.ietf.org/html/rfc1178 RFC 1178].}}
 +
 
 +
Alternatively, using {{man|1|hostnamectl}}:
 +
 
 +
# hostnamectl set-hostname ''myhostname''
 +
 
 +
To temporarily set the hostname (until reboot), use {{man|1|hostname}} from {{Pkg|inetutils}}:
 +
 
 +
# hostname ''myhostname''
 +
 
 +
To set the "pretty" hostname and other machine metadata, see {{man|5|machine-info}}.
 +
 
 +
=== Local hostname resolution ===
 +
 
 +
{{Expansion|Explain why you want a resolvable hostname, why {{ic|127.0.1.1}} is used (and why a static IP address should be preferred over it).}}
 +
 
 +
The {{ic|myhostname}} [[Name Service Switch]] (NSS) module of [[systemd]] provides local hostname resolution without having to edit {{ic|/etc/hosts}} ({{man|5|hosts}}). It is enabled by default.
 +
 
 +
Some clients may however 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.
 +
 
 +
To configure the hosts file, add the following lines to {{ic|/etc/hosts}}:
 +
 
 +
127.0.0.1        localhost
 +
::1              localhost
 +
127.0.1.1        ''myhostname''.localdomain        ''myhostname''
 +
 
 +
{{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 (ie. {{ic|.localdomain}} above). All following strings on the same line are considered aliases. See {{man|5|hosts}} for more info.}}
 +
 
 +
As a result the system resolves to both entries:
 +
 
 +
{{hc|$ 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 {{ic|127.0.1.1}}.
 +
 
 +
=== Local network hostname resolution ===
 +
 
 +
To make your machine accessible in your LAN via its hostname you can:
 +
 
 +
* 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 [[#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.
 +
 
 +
== Tips and tricks ==
 +
 
 +
=== 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 udev-rule. For example:
 +
 
 +
{{hc|/etc/udev/rules.d/10-network.rules|2=
 +
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: {{ic|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 {{ic|DEVPATH}}, for example:
 +
 
 +
{{hc|/etc/udev/rules.d/10-network.rules|2=
 +
SUBSYSTEM=="net", DEVPATH=="/devices/platform/wemac.*", NAME="int"
 +
SUBSYSTEM=="net", DEVPATH=="/devices/pci*/*1c.0/*/net/*", NAME="en"
 +
}}
 +
 
 +
To get the {{ic|DEVPATH}} of all currently-connected devices, see where the symlinks in {{ic|/sys/class/net/}} lead. For example:
 +
 
 +
{{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
 +
}}
 +
 
 +
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}}.
 +
 
 +
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:
 +
 
 +
{{hc|/etc/udev/rules.d/10-network.rules|2=
 +
SUBSYSTEM=="net", ACTION=="add", ATTRS{idVendor}=="12ab", ATTRS{idProduct}=="3cd4", NAME="net2"
 +
}}
 +
 
 +
To [[udev#Testing rules before loading|test]] your rules, they can be triggered directly from userspace, e.g. with {{ic|udevadm --debug test /sys/class/net/*}}. Remember to first take down the interface you are trying to rename (e.g. {{ic|ip link set enp1s0 down}}).
 +
 
 +
{{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.}}
 +
 
 +
=== Revert to traditional interface names ===
  
=== Swapping computers on the cable modem ===
+
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:
  
Most domestic cable ISPs (videotron for example) have the cable modem configured to recognise only one client PC, by the MAC address of its network interface. Once the cable modem has learnt the MAC address of the first PC 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 different MAC address to 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.
+
# ln -s /dev/null /etc/udev/rules.d/80-net-setup-link.rules
  
=== The TCP Window Scaling Issue ===
+
Alternatively, add {{ic|1=net.ifnames=0}} to the [[kernel parameters]].
  
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.
+
=== Set device MTU and queue length ===
  
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.
+
You can change the device [[wikipedia:Maximum transmission unit|MTU]] and queue length by defining manually with an udev-rule. For example:
  
That 8-bit Scale Factor allows the Window to be up to 32 times higher than the initial 64Kb.
+
{{hc|/etc/udev/rules.d/10-network.rules|2=
 +
ACTION=="add", SUBSYSTEM=="net", KERNEL=="wl*", ATTR{mtu}="1500", ATTR{tx_queue_len}="2000"
 +
}}
  
It appears that some broken routers and firewalls on the Internet are rewriting the Scale Factor to 0 which causes misunderstandings between hosts.
+
{{Note|
 +
* {{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.
 +
}}
  
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.
+
=== Bonding or LAG ===
  
The resulting connection is at best very slow or broken.
+
See [[netctl#Bonding]] or [[Wireless bonding]].
  
==== How To Diagnose The Problem? ====
+
=== IP address aliasing ===
  
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).
+
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).
  
'''Warning''': <code>dmesg</code>'s output is OK, logs are clean and <code>ifconfig</code> will report normal status &mdash; and actually everything is normal.
+
==== Example ====
  
If you can't browse any website, but you can ping some rare hosts, chances are great that you're experiencing this issue: ping uses the ICMP protocol and is not affected by TCP issues.
+
To manually set an alias, for some NIC, use {{Pkg|iproute2}} to execute
  
You can try to use WireShark. You might see successful UDP and ICMP communications but unsuccessful TCP communications (only to foreign hosts).
+
# ip addr add 192.168.2.101/24 dev eth0 label eth0:1
  
==== How To Fix It? (The bad way) ====
+
To remove a given alias execute
  
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's not guaranteed, especially for very distant ones.
+
# ip addr del 192.168.2.101/24 dev eth0:1
  
echo "4096 87380 174760" > /proc/sys/net/ipv4/tcp_rmem
+
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}}.
  
Or you can try to remove one of your RAM sticks (yes, sir).
+
=== Promiscuous mode ===
  
==== How To Fix It? (The good way) ====
+
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]].
  
Simply disable Window Scaling. Even if Window Scaling is a nice TCP feature, it may be uncomfortable especially if you can't fix the broken router. There are several ways to disable Window Scaling, and it seems that the most bulletproof (which will work with most kernels) is to add the following lines to your <code>/etc/rc.local</code>:
+
{{hc|/etc/systemd/system/promiscuous@.service|<nowiki>
 +
[Unit]
 +
Description=Set %i interface in promiscuous mode
 +
After=network.target
  
echo 0 > /proc/sys/net/ipv4/tcp_window_scaling
+
[Service]
 +
Type=oneshot
 +
ExecStart=/usr/bin/ip link set dev %i promisc on
 +
RemainAfterExit=yes
  
==== How To Fix It? (The best way) ====
+
[Install]
 +
WantedBy=multi-user.target
 +
</nowiki>}}
  
This issue 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.
+
If you want to enable promiscuous mode on interface {{ic|eth0}} run [[enable]] {{ic|promiscuous@eth0.service}}.
  
==== More about it? ====
+
=== Investigate sockets ===
  
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].
+
''ss'' is a utility to investigate network ports and is part of the {{Pkg|iproute2}} package. It has a similar functionality to the [https://www.archlinux.org/news/deprecation-of-net-tools/ deprecated] netstat utility.  
  
And more recently, some Archers have been hit by this issue:
+
Common usage includes:
  
* [http://www.archlinux.org/pipermail/arch/2006-June/011250.html Odd network issue]
+
Display all TCP Sockets with service names:
* [http://www.archlinux.org/pipermail/arch/2006-September/011943.html Kernel 2.6.17 and TCP window scaling] &mdash; the topic which initiated this article
+
$ ss -at
  
There are also several relevant threads on the LKML.
+
Display all TCP Sockets with port numbers:
 +
$ ss -atn
  
 +
Display all UDP Sockets:
 +
$ ss -au
  
=== Realtek No Link / WOL issue ===
+
For more information see {{man|8|ss}}.
  
Users with Realtek 8168 8169 8101 8111 based NICs (cards / and on board) may notice an issue 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 offical 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 spot if this is issue is affecting you because the Link light will remain off only until Windows boots, during Windows shutdown it will revert back to the Link light being off.  Normal operation should be that the link light is always on as long as the system is on, even during POST.  This issue will also affect other OS's without newer drivers (eg. Live CD's). Here's a couple of fixes for this issue.
+
== Troubleshooting ==
  
==== Method 1 - Rollback/Change Win driver ====
+
=== The TCP window scaling problem ===
  
You can rollback your Windows NIC driver to the Microsoft provided one (if available), or rollback/install to an official Realtek driver pre-dated  May 2007 (maybe on the CD that came with your hardware).
+
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, [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.
  
==== Method 2 - Enable WOL in Win driver ====
+
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.
  
Probably the best and 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 CD's, other OSes).  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.
+
The resulting connection is at best very slow or broken.
  
  In Windows XP (example)
+
==== How to diagnose the problem ====
  Right click my computer
 
  --> Hardware tab
 
    --> Device Manager
 
      --> Network Adapters
 
        --> "double click" Realtek ...
 
          --> Advanced tab
 
            --> Wake-On-Lan After Shutdown
 
              --> Enable.
 
  
==== Method 3 - Newer Realtek Linux driver ====
+
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).
  
Any newer driver for these Realtek cards can be found for Linux on the realtek site. (untested but believed to also solve the problem).
+
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.
  
=== DLink G604T/DLink G502T DNS issue ===
+
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.
Users with a DLink G604T/DLink G502T router, using DHCP and have firmware v2.00+ (typically users with AUS firmware) may have issues with certain programs not resolving the DNS. One of these programs are unfortunatley pacman. The problem is basically the router in certain situations is not sending the DNS properly to DHCP, which causes programs to try and connect to servers with an IP of 1.0.0.0 and fail with a connection timed out error
 
  
==== How To Diagnose The Problem? ====
+
You can try to use [[Wireshark]]. You might see successful UDP and ICMP communications but unsuccessful TCP communications (only to foreign hosts).
The best way to diagnose the problem is to use a firefox/konqueror/links/seamonkey and to enable wget for pacman. If this is a fresh install of archlinux, then you may want to consider installing links through the live CD.
 
  
Firstly enable wget for pacman (since it gives us info about pacman when its downloading packages)
+
==== Ways of fixing it ====
Open /etc/pacman.conf with your favourite editor and uncomment the following line (remove the # if its there)
 
  
XferCommand = /usr/bin/wget --passive-ftp -c -O %o %u
+
===== Bad =====
  
While your in pacman.conf, check the default mirror that pacman uses to download packages.
+
To fix it the bad way, you can change the {{ic|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.
  
Now open up the default mirror in an internet browser to see if the mirror actually works. If it does work then do pacman -Syy (otherwise pick another working mirror and set it to the pacman default), if you get something similar to the following (notice the 1.0.0.0)
+
# echo "4096 87380 174760" > /proc/sys/net/ipv4/tcp_rmem
  
<nowiki>ftp://mirror.pacific.net.au/linux/archlinux/extra/os/i686/extra.db.tar.gz</nowiki>                                                           
+
===== Good =====
            <nowiki>=> `/var/lib/pacman/community.db.tar.gz.part'</nowiki>                           
 
Resolving mirror.pacific.net.au... 1.0.0.0
 
  
Then you most likely have this problem. The 1.0.0.0 means its unable to resolve the DNS, so we must add it to resolv.conf.
+
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 {{ic|/etc/sysctl.d/99-disable_window_scaling.conf}} (see also [[sysctl]]):
  
==== How To Fix It? ====
+
net.ipv4.tcp_window_scaling = 0
Basically what we need to do is to manually add the DNS to our /etc/resolv.conf file, The problem is that DHCP automatically deletes and replaces this file on boot, so we need to edit  /etc/conf.d/dhcpcd and change the flags to stop DHCP doing this
 
  
When you open up /etc/conf.d/dhcpcd, you should see something close to the following
+
===== Best =====
DHCPCD_ARGS="-t 30 -h $HOSTNAME"
 
add the -R flag to the arguments, i.e.
 
DHCPCD_ARGS="-R -t 30 -h $HOSTNAME"
 
  
Save and close, now open /etc/resolv.conf. You should see a single namespace (most likely 10.1.1.1), this is the gateway to your router, which we need to connect to in order to get the DNS of your ISP. Paste the IP into your browser and login to your router. Go to the DNS section and you should see an IP in the Preferred DNS Server, copy it and paste it as a namespace ABOVE the current gateway one.
+
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.
  
i.e. a new resolv.conf should look something along the lines of
+
==== More about it ====
namespace 10.1.1.1
 
  
If my Primary DNS Server is 211.29.132.12 then chance resolv.conf to
+
This section is based on the LWN article [http://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].
namespace 211.29.132.12
 
namespace 10.1.1.1
 
  
Now restart the network daemon by doing /etc/rc.d/network restart and do pacman -Syy, if it syncs fine with the server then problem ssolved
+
There are also several relevant threads on the LKML.
  
==== More about it? ====
+
== See also ==
  
This is the whirlpool forum (Australian ISP community) which talks about and gives the same solution to the problem
+
* [https://www.tldp.org/LDP/nag2/index.html Linux Network Administrators Guide]
http://forums.whirlpool.net.au/forum-replies-archive.cfm/461625.html
+
* [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]
 +
* [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/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]

Latest revision as of 11:45, 27 February 2020

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

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. 8.8.8.8, which is a Google DNS server and is a convenient address to test with).
  7. Check if you can resolve domain names (e.g. archlinux.org).

Ping

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Add or link explanation of common ping errors like Unknown hosts / Network is unreachable. (Discuss in Talk:Network configuration#)

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) 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
...

For every reply you receive, the ping utility will print a line like the above. 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 no reply, this may be related to your default gateway or your Internet Service Provider (ISP). You can run a traceroute to further diagnose the route to the host.

Note: If you receive an error like ping: icmp open socket: Operation not permitted when executing ping, try to re-install the iputils package.

Network management

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 enables dhcpcd (dhcpcd@interface.service) for wired network devices on boot.

net-tools

Arch Linux has deprecated net-tools in favor of iproute2.[2]

Deprecated command Replacement commands
arp ip neighbor
ifconfig ip address, ip link
netstat ss
route ip route

For a more complete rundown, see this blog post.

iproute2

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 use a network manager or 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.

Network interfaces

By default udev assigns names to your network interfaces using Predictable Network Interface Names, which prefixes interfaces names with en (wired/Ethernet), wl (wireless/WLAN), or ww (WWAN).

Tip: To change interface names, see #Change interface name and #Revert to traditional interface names.

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 loop device 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 / disabled using ip link set interface up|down, see ip-link(8).

To check the status of the interface 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.

Note: If your default route is through interface eth0, 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.

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: IP 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

Add a route:

# ip route add PREFIX via address dev interface

Delete a route:

# ip route del PREFIX via address dev interface

DHCP

A Dynamic Host Configuration Protocol (DHCP) server provides clients with a dynamic IP address, the subnet mask, the default gateway IP address and optionally also with DNS name servers.

To use DHCP you need a DHCP server in your network and a DHCP client:

Client Package Archiso Note 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
Note:
  • You should not run two DHCP clients simultaneously.
  • Instead of directly using a DHCP client you can also use a network manager.
Tip: You can check if a DHCP server is running with dhcping.

Servers

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: systemd-networkd has DHCP server support. (Discuss in Talk:Network configuration#)
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

Network managers

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

Note: There are many solutions to choose from, but remember that all of them are mutually exclusive; you should not run two daemons simultaneously.
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), wicd-curses(8) No dhcpcd wicd.service

There also is Wifi Radar, a GUI application to manage WiFi networks with wireless_tools, it however does not handle wired connections.

See also List of applications#Network managers.

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 myhostname:

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

Alternatively, using hostnamectl(1):

# hostnamectl set-hostname myhostname

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

# hostname myhostname

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

Local hostname resolution

Tango-view-fullscreen.pngThis article or section needs expansion.Tango-view-fullscreen.png

Reason: Explain why you want a resolvable hostname, why 127.0.1.1 is used (and why a static IP address should be preferred over it). (Discuss in Talk:Network configuration#)

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
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 (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:

  • 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

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 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).

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 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"
Note:
  • 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