Network configuration

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. 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) 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 received, the ping utility will print a line like the above until you interrupt (Ctrl+c) it interactively. For more information see the manual. Note that computers can be configured not to respond to ICMP echo requests.

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

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:

iproute2

iproute2 is a dependency of the 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 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 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. See also Deprecated Linux networking commands and their replacements.

Network interfaces

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

Listing network interfaces

Both wired and wireless interface names can be found via or . Note that 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 .

To check the status of the interface :

The in is what indicates the interface is up, not the later .

Static or dynamic IP address?

If you are using a Wi-FI or a router, for example, at home, you will most likely be using a dynamic IP address. The IP address is assigned by the Wi-Fi or router and it is what your computer should be configured to use. Or, if you are at home and your computer is connected to your ISP's modem, for example, a cable modem, that will also be using a dynamic IP address. Dynamic IP addresses can change each time you turn your computer on. In a work environment you may have a static IP address or a dynamic IP address. At home you can configure your router to always assign your computer the same IP address in which case you are using a static IP address. When you are using a dynamic IP address you will need to use DHCP so that it can set up your network interface with the correct IP address. In addition to configuring your IP address, DHCP can also configure your routing (how to get from where you are to wherever on the network you are going) as well as your name servers, which convert the host name, for example, google.com, into its IP address, that number with dots in 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

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 .

PREFIX is either a CIDR notation or 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:

ClientPackageArchisoNoteSystemd units
dhcpcdDHCP, DHCPv6, ZeroConf, static IP,
ISC dhclientdhclientDHCP, DHCPv6, BOOTP, static IP
Tip:
  • You can check if a DHCP server is running with dhcping.
  • While waiting for an IP to be assigned you can run something like watch -n 1 ping -c 1 archlinux.org to confirm that the network is connected.

Servers

ServerPackageIPv4IPv6GUIInterfacesStorage backend(s)Note
dhcpdGlass-ISC-DHCP?File
dnsmasq?FileAlso DNS, PXE and TFTP
KeaStorkREST, RADIUS and NETCONFFile, MySQL, PostgreSQL and CassandraAlso DNS

Network managers

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

Network managerGUIArchiso CLI toolsPPP support
(e.g. 3G modem)
DHCP clientsystemd units
ConnMan 8 unofficial (with )internal
netctl , wifi-menudhcpcd or dhclient, netctl-auto@interface.service
NetworkManager , nmtui(1)internal or dhclient
systemd-networkd ()internal,

Set the hostname

A hostname is a unique name created to identify a machine on a network, configured in /etc/hostname—see and 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 :

/etc/hostname
''myhostname''

Alternatively, using :

# hostnamectl set-hostname myhostname

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

# hostname myhostname

To set the "pretty" hostname and other machine metadata, see .

Local network hostname resolution

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

  • edit the 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 . Computers running Windows, macOS, or Linux with running, will be able to find your machine.
    • Hostname resolution via mDNS. Provided by either 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

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:
  • 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 , for example:

To get the of all currently-connected devices, see where the symlinks in 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, would be wrong since it will stop matching once the name is changed to . Only the system-default rule will fire the second time around, causing the name to be changed back to e.g. .

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:

To test your rules, they can be triggered directly from userspace, e.g. with . Remember to first take down the interface you are trying to rename (e.g. ).

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

mtu: 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 .

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

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

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.

If you want to enable promiscuous mode on interface , enable .

Investigate sockets

ss is a utility to investigate network ports and is part of the 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 .

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

Bad

To fix it the bad way, you can change the 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

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:

# 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

(an NSS module provided by systemd and enabled by default in ) provides  and the local hostname resolution to an IP address. Some software may, however, still instead read  directly; see   for examples.

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

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

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:

As a result the system resolves to both entries:

gollark: That was already an inspiration for some of the design ish.
gollark: Does anyone have pointless and never-going-to-be-implemented ideas for minoteaur, my eternally unfinished wiki-style notes system?
gollark: The implications are obvious.
gollark: https://media.discordapp.net/attachments/461970193728667648/793622483152142396/unknown.png?width=758&height=422
gollark: Anyway, I horribly patched it now in my copy so minoteaur can go on.

See also

This article is issued from Archlinux. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.