By default most Linux distributions including Arch Linux are configured with DHCP. Dynamically assigned IP is convenient for for desktop computers but quite cumbersome for headless servers. Setting up static IP allows a user defined IP addresses that will remain the same allowing to connect remotely. Arch Linux uses it’s own network configuration tool called netctl. Before you configure netctl profile you will need to find your
Network interface is what connects the computer to the network. Traditionally this used to be eth0 or wlan0 for the first ethernet port and wireless adapter. With the new naming convention you may see different names.
Find the network interface name.
In the output look for the name of the
network interface you want to configure. In my case there is only a single ethernet port named
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00 inet 127.0.0.1/8 scope host lo valid_lft forever preferred_lft forever inet6 ::1/128 scope host valid_lft forever preferred_lft forever 2: enp1s0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000 link/ether 74:d4:35:5f:f6:60 brd ff:ff:ff:ff:ff:ff inet 192.168.0.100/24 brd 192.168.0.255 scope global enp1s0 valid_lft forever preferred_lft forever inet6 fe80::76d4:35ff:fe5f:f660/64 scope link valid_lft forever preferred_lft forever
Gateway is the IP of the router that connects to the internet. This is the same IP address you use to log in to your router configuration page. I had my router configured to use 192.168.0.1. If you don’t know your gateway you can easily find out from command line.
Find the gateway address.
In the output the gateway will be on the first line.
default via 192.168.0.1 dev enp1s0 192.168.0.0/24 dev enp1s0 proto kernel scope link src 192.168.0.100
Netmask is used to subdivide a network into subnets or subnetworks. It is generally
255.255.255.0 for simple networks. In slash notation it is written as
Domain Name System is what translates domain names into IP addresses that computers can understand. Since this happens for every request it should be as fast as possible. Public DNS servers are just fine but having a router act as a DNS server can give a minor advantage. I chose to use my router as a DNS server with Google Public DNS servers as backup. Primary DNS in this scenario is
192.168.0.1 or the same as the gateway while secondary and tertiary DNS addresses are Google’s Public DNS
Configure Static IP Address
Copy the sample static ethernet profile from examples directory to profiles directory.
cp /etc/netctl/examples/ethernet-static /etc/netctl/enp1s0
enp1s0 with your actual network interface name or another name that describes the profile well.
Edit the newly copied profile to match your configuration.
sudo nano /etc/netctl/enp1s0
Interface value from
eth0 to your actual network interface name. Modify the
Address value to the desired static IP address followed by the netmask written in slash notation. Swap out the
Gateway value with your actual gateway address. Add a primary DNS address and optionally secondary and tertiary addresses.
Alternatively create a new file and copy the profile from below making changes as needed.
Description='A basic static ethernet connection' Interface=enp1s0 Connection=ethernet IP=static Address=('192.168.0.100/24') Gateway=('192.168.0.1') DNS=('192.168.0.1' '184.108.40.206' '220.127.116.11')
Start netctl profile manually.
sudo netctl start enp1s0
This is useful to verify the profile is working before enabling it.
Enable netctl profile to allow automatic start at boot time.
sudo netctl enable enp1s0
ip addr ip route cp /etc/netctl/examples/ethernet-static /etc/netctl/enp1s0 sudo nano /etc/netctl/enp1s0 sudo netctl start enp1s0 sudo netctl enable enp1s0