How to Use Netctl in Arch Linux to Set Up a Network Connection

Ethernet cables

Systemd has become a primary feature of many Linux distributions, including Arch Linux. It completes the boot process, starts and stops services, and even works closely alongside the netctl utility for connecting to the Internet.

Arch Linux developers created Netctl, as its man page states, to “control the state of the Systemd services for the network profile manager.” In short, they created Netctl to make it easy to use Systemd-like commands to enable and disable network profiles you create.

This article will show you how to use Netctl to create wired and wireless profiles and manipulate them to start manually or at boot.

Also read: How to Fix “No Route to Host” Connection Error on Linux

Installation

If you’re using Arch Linux, Netctl should have been installed with the base group of utilities. If for any reason you don’t have it on Arch, install with the command:

sudo pacman -S netctl

For other systems, you can find the source code here.

Gathering Preliminary Information

One thing you’ll need to do before making your own network profiles is find out the names of your network devices. Use ip link to get what you need.

iplink command

This machine’s wired device shows up as “enp19s0.” Its wireless card shows up as “wlp18s0b1.” You will use similar values to edit Netctl’s example profiles to make them unique to your machine.

Also read: How to Use tcpdump for Packet Capture

Example Netctl Profiles

Speaking of examples, look what’s available in Netctl’s default samples directory, “/etc/netctl/examples.”

Netctl example profiles

This collection of text files gives you a basis for creating your own custom profiles. The title of each profile here applies to specific situations, including a DHCP-driven wired ethernet connection and a WPA-encrypted wireless connection — both of which you will see below.

Also read: How to Clear Package Cache in Arch Linux

Basic Wired and Wireless Profile Edits

First, take a look at the text of the sample “/etc/netctl/examples/ethernet-dhcp” file.

Netctl ethernet example

By default, many of the options in this file are commented out. You can explore them in depth on the Netctl profile man page with man 5 netctl.profile. For now, you should focus on the “Interface…” line.

You can make use of this profile by copying it to Netctl’s main directory.

1. Change the directories with the command:

cd /etc/netctl/

2. Copy the example file to that directory:

cp ./examples/ethernet-dhcp ./custom-wired-profile

The filename “custom-wired-profile” can be anything you like; try to make it something easy to remember.

3. From there, all you need to do is edit “Interface …” to reflect the name of your network card you found earlier with ip link. In this case, the line should read “Interface=enp19s0.”

4. Now look at the contents of “/etc/netctl/examples/wireless-wpa.”

Netctl wireless profile

You will also need to copy the sample wireless profile to the base Netctl directory:

cp ./examples/ethernet-dhcp ./custom-wireless-profile

When you edit this file, you will again change “Interface …” to match your card name. For this article “Interface=wlp18s0b1” is appropriate.

You must also change the “ESSID=…” and “Key=…” lines to match the name and password of your wireless connection, respectively. Remember to keep your name and password inside the provided single quotes.

Also read: What Is the Yggdrasil Network and How to Install It

Starting and Stopping Connections

Now you’re ready to start a wired or wireless connection. In both cases, the syntax is the same:

netctl start <profile-name>

You will need to cd /etc/netctl/ into the base directory to access your saved profiles.

Netctl commands all look nearly identical as they follow the form netctl command [profile]. Netctl’s help page offers this overview of its commands.

Netctl commands

Any of the above commands that list “[PROFILE]” as part of their listing require a profile name, like “custom-wired-profile.” The others, such as netctl stop-all, do not require a profile name.

Enabling and Disabling Profiles

Systemd users should find these commands similar to their use of services. If a user was to enable the NTP daemon with Systemd, for instance, they would use the systemctl enable ntpd.service.

In that same way, Netctl users can enable their profiles to start at boot with netctl enable <profile-name>. You can just as easily disable a profile to stop it from starting at boot by using “disable” instead of “enable” in that same style command.

Conclusion

You now know enough to edit, start, stop, enable, and disable your custom network profiles.

If you edited your device name, network name, and password lines properly, Netctl should connect without any errors. Should something go wrong, however, you can always diagnose the problem with

netctl status <profile-name>

or

journalctl -xe
Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Casey Houser

I have worked as a professional writer since 2011. I like to compose my articles in Vim, which I also use for hobbyist C and Ruby projects. When I'm not in front of a text editor, I run, bike, and play tennis until I'm too tired to move.