Static IP on Arch Linux

Arch Linux

I was searching how to set static IP on Arch Linux Raspberry Pi.
Here is what I did.

1. Network Interface
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.

ip addr

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

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

2. Gateway
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.1.1. If you don’t know your gateway you can easily find out from command line.

Find the gateway address.

ip route

In the output the gateway will be on the first line.

default via 192.168.1.1 dev enp1s0

3. Netmask
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 /24

4. DNS
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.1.1 or the same as the gateway while secondary and tertiary DNS addresses are Google’s Public DNS 8.8.8.8 and 8.8.4.4 respectively.

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

Replace 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

Change the 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.1.100/24')
Gateway=('192.168.1.1')
DNS=('192.168.0.1' '8.8.8.8' '8.8.4.4')

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

Δεν υπάρχουν σχόλια

Από το Blogger.