Static IP – Alpine Linux

Alpine Linux is highly valued in the server world for its lightweight footprint and security-first approach. However, because it avoids the bloated network management tools found in other distributions, setting up a static IP requires modifying the underlying configuration files directly.

Here is a straightforward guide to configuring a permanent, static IP address on your Alpine Linux server.

Locate Your Network Interface

Before changing any settings, you need to identify the exact name of the network interface you want to configure.

Open your terminal and run:

ip link show

Look for your primary network adapter. It typically starts with eth (like eth0) or en (like ens33 or enp0s3). Note this name down.

Configure the Interfaces File

Alpine Linux manages its network interfaces through the /etc/network/interfaces file. You will need root privileges to edit it.

Open the file using vi (Alpine’s default text editor) or your preferred editor:

setup-interfaces

Tip: While you can use Alpine’s built-in script setup-interfaces to interactively configure your network, editing the file manually gives you complete control and is highly reliable.

To edit manually, open the file:

vi /etc/network/interfaces

Modify or replace the configuration for your interface. A typical static IP setup looks like this:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 192.168.1.50
    netmask 255.255.255.0
    gateway 192.168.1.1

Configuration Breakdown:

  • auto eth0: Tells the system to bring this interface up automatically at boot.
  • iface eth0 inet static: Defines that the interface will use a static IPv4 address.
  • address: The specific IP address you want to assign to your server.
  • netmask: Defines the subnetwork boundaries (usually 255.255.255.0 for home or small office networks).
  • gateway: The IP address of your router or network switch.

Save and close the file (in vi, press Esc, type :wq, and press Enter).

Set Up DNS Nameservers

Now that your local network parameters are set, your server needs to know how to resolve domain names (like translating google.com into an IP address). This is handled by the /etc/resolv.conf file.

Open the file:

vi /etc/resolv.conf

Add your preferred DNS servers. You can use your router’s IP, or reliable public DNS options like Cloudflare or Google:

nameserver 1.1.1.1
nameserver 8.8.8.8

Save and exit the file.

Restart the Networking Service

To apply the changes without rebooting the entire server, restart Alpine’s networking service using the OpenRC init system:

rc-service networking restart

Verify the Changes

Finally, ensure your server is correctly using the new static IP and can communicate with the outside world.

Check the assigned IP address:

ip addr show eth0

Verify external connectivity by pinging a public address:

ping -c 3 1.1.1.1

If the ping commands return successful responses, your Alpine Linux server is officially configured with a stable, permanent static IP address!

Leave a Reply

Your email address will not be published. Required fields are marked *