How to configure static IP address on Alpine Linux

At home or in a cloud environment, IP addresses are assigned dynamically by the DHCP server. Setting a static IP address on your Alpine Linux server is required for various reasons. For instance, Alpine Linux is configured as a DHCP server or KVM server to host multiple VMs. Static IP address makes it easy to work with port forwarding, firewalling, and HTTPS server too. This quick tutorial will explain how to set up a static IP address on Alpine Linux.

Tutorial details
Difficulty level Easy
Root privileges Yes
Requirements Alpine Linux
Est. reading time 2 minutes

Configuring Static IP address on Alpine server

We define DHCP or static configuration in /etc/network/interfaces file. The first entry must be a loopback (lo0) interface. For example, we can use the cat command:
cat /etc/network/interfaces

auto lo
iface lo inet loopback

My Ethernet device name is eth0. See how to find out or display available network interfaces on Linux using the ifconfig command or ip command # ifconfig -a
# ip link show

IPv4 static address configuration for Alpine Linux version 3.13.xx

Let us set static IP address to 192.168.2.16 with 255.255.255.0 (/24) subnet. The default gateway set to 192.168.2.254 and Alpine Linux hostname set to nixcraft-x140e:

auto eth0
iface eth0 inet static
        address 192.168.2.16/24
        gateway 192.168.2.254
        hostname nixcraft-x140e

We can add multiple IP address as follows for eth0:

iface eth0 inet static
        address 192.168.2.16/24
        gateway 192.168.2.254
        hostname nixcraft-x140e
 
iface eth0 inet static
        address 192.168.1.17/24

IPv6 static address configuration

The syntax is simple for Alpine Linux version 3.13.xx:

iface eth0 inet6 static
        address ipv6-here/64
        gateway ipv6-gw-here
        pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra

Configuring DNS Client / Name server IP address

Edit the /etc/resolv.conf as follows:
# vi /etc/resolv.conf
Append the following:

nameserver 192.168.2.236
nameserver 192.168.2.254
Save and close the file.
How to configure static IP address on Alpine Linux

Restating network service

The syntax is as follows:
# /etc/init.d/networking restart
We can use the service command too:
# service networking restart
How to restart networking services on Alpine Linux

Configuring Static IP address using DHCP

For some reason, if you wish to go back to DHCP, then edit the /etc/network/interfaces file as follows:

auto lo
iface lo inet loopback
 
auto eth0
iface eth0 inet dhcp

Restart the networking service on Alpine Linux:
# service networking restart

Summing up

We explained how to assign a static IP address on your Alpine Linux server. See busybox documentation or use the man command:
man busybox


🐧 Get the latest tutorials on Linux, Open Source & DevOps via RSS feed or Weekly email newsletter.

🐧 0 comments... add one

CategoryList of Unix and Linux commands
Disk space analyzersdf ncdu pydf
File Managementcat tree
FirewallAlpine Awall CentOS 8 OpenSUSE RHEL 8 Ubuntu 16.04 Ubuntu 18.04 Ubuntu 20.04
Network UtilitiesNetHogs dig host ip nmap
OpenVPNCentOS 7 CentOS 8 Debian 10 Debian 8/9 Ubuntu 18.04 Ubuntu 20.04
Package Managerapk apt
Processes Managementbg chroot cron disown fg jobs killall kill pidof pstree pwdx time
Searchinggrep whereis which
User Informationgroups id lastcomm last lid/libuser-lid logname members users whoami who w
WireGuard VPNAlpine CentOS 8 Debian 10 Firewall Ubuntu 20.04
0 comments… add one

Leave a Reply

Your email address will not be published.

Use HTML <pre>...</pre> for code samples. Still have questions? Post it on our forum