Configure Networking: Difference between revisions

From Alpine Linux
m (→‎Enabling IPv6 (Optional): Replaced the pre tags with Cmd template tags for the commands)
(→‎Interface configuration: Added link to syntax documentation of ifupdown-ng)
 
(58 intermediate revisions by 17 users not shown)
Line 1: Line 1:
This page will assist you in setting up networking on Alpine Linux.
This page documents the various networking options available in Alpine Linux. This page helps to configure your network and to [[#Connectivity testing|test]] your Internet access.
{{Note|You must be logged in as root in order to perform the actions on this page.}}


= Setting System Hostname =
== Network setup-scripts ==
To set the system hostname, do something like the following:
{{Cmd|echo "hostname.domain.com" > /etc/hostname}}


Then, to activate the change, do the following:
Among the alpine setup scripts that are installed as part of <code>alpine-conf</code>, the following network related scripts are available.
{{Cmd|hostname -F /etc/hostname}}


If you're using IPv6, you should also add the following special IPv6 addresses to your <code>/etc/hosts</code> file:
* <code>setup-hostname</code>
<pre>::1            localhost ipv6-localhost ipv6-loopback
* <code>setup-interfaces</code>
* <code>setup-dns</code>
* <code>setup-proxy</code>
* <code>setup-ntp</code>
 
All the above utilities are interactive. {{:Ethernet}}
 
For a versatile networking front end refer [[NetworkManager]]. If your networking needs are more advanced, you have to refer to the following detailed guide for manual network configuration.
 
== Setting hostname ==
 
To set the system hostname:{{Cmd|# echo "shortname" > /etc/hostname}}
 
Then, to activate the change: {{Cmd|# hostname -F /etc/hostname}}
 
If you're using IPv6, you should also add the following special IPv6 addresses to your {{path|/etc/hosts}} file:{{cat|/etc/hosts|...
::1            localhost ipv6-localhost ipv6-loopback
fe00::0        ipv6-localnet
fe00::0        ipv6-localnet
ff00::0        ipv6-mcastprefix
ff00::0        ipv6-mcastprefix
ff02::1        ipv6-allnodes
ff02::1        ipv6-allnodes
ff02::2        ipv6-allrouters
ff02::2        ipv6-allrouters
ff02::3        ipv6-allhosts</pre>
ff02::3        ipv6-allhosts
}}
 
{{Tip|If you're going to use automatic IP configuration, such as IPv4 DHCP or IPv6 Stateless Autoconfiguration, you can skip ahead to [[#Configuring_DNS|Configuring DNS]].  Otherwise, if you're going to use a static IPv4 or IPv6 address, continue below.}}
 
For a static IP configuration, it's common to also add the machine's hostname you just set (above) to the {{path|/etc/hosts}} file.
 
Here's an IPv4 example:{{cat|/etc/hosts|...
192.168.1.150  shortname.domain.com
...
}}
 
And here's an IPv6 example:{{cat|/etc/hosts|...
2001:470:ffff:ff::2  shortname.domain.com
...
}}
 
== Configuring DNS ==


{{Tip|If you are going to use automatic IP configuration, such as IPv4 DHCP or IPv6 Stateless Autoconfiguration, you can skip ahead to [[#Configuring_DNS|Configuring DNS]]. Otherwise, if you are going to use a static IPv4 or IPv6 address, continue below.}}
{{Tip|'''For users of IPv4 DHCP:''' Please note that {{path|/etc/resolv.conf}} will be completely overwritten with any nameservers provided by DHCP.
If DHCP does not provide any nameservers, then {{path|/etc/resolv.conf}} will still be overwritten, but will not contain any nameservers!}}


For a static IP configuration, it's common to also add the machine's hostname you just set (above) to the <code>/etc/hosts</code> file.
For a static IP address and static nameservers, use one of the following examples.


Here's an IPv4 example:
For IPv4 nameservers, edit your {{path|/etc/resolv.conf}} file to look like this:<br />
<pre>192.168.1.150  hostname.domain.com</pre>
The following example uses [https://en.wikipedia.org/wiki/Google_Public_DNS Google's Public DNS servers].
{{cat|/etc/resolv.conf|nameserver 8.8.8.8
nameserver 8.8.4.4
}}


And here's an IPv6 example:
For IPv6 nameservers, edit your {{path|/etc/resolv.conf}} file to look like this:<br />
<pre>2001:470:ffff:ff::2  hostname.domain.com</pre>
The following example uses [https://www.he.net/ Hurricane Electric's] public DNS server.
{{cat|/etc/resolv.conf|nameserver 2001:470:20::2}}
You can also use Hurricane Electric's public IPv4 DNS server:
{{cat|/etc/resolv.conf|nameserver 74.82.42.42}}


= Configuring DNS =
{{Tip|If you decide to use Hurricane Electric's nameserver, be aware that it is 'Google-whitelisted'. What does this mean?  It allows you access to many of Google's services via IPv6. (Just don't add other, non-whitelisted, nameservers to {{path|/etc/resolv.conf}} — ironically, such as Google's Public DNS Servers.) Read [https://www.google.com/intl/en/ipv6/ here] for more information.}}
{{Warning|'''For users of IPv4 DHCP:''' Please note that <code>/etc/resolv.conf</code> will be completely overwritten with any nameservers provided by DHCP. Also, if DHCP does not provide any nameservers, then <code>/etc/resolv.conf</code> will still be overwritten, but will not contain any nameservers! '''''Note to self: This behavior should probably be reported to upstream.'''''}}
{{Note|'''For users of IPv6 Stateless Autoconfiguration:''' The above warning doesn't seem to be an issue here, however, I would advise caution.}}


For using a static IP and static nameservers, use one of the following examples.
== Interface configuration ==
{{Note|Before configuring any interfaces via {{path|/etc/network/interfaces}}, check the type of network manager used in your system. You may check so via the command <code>ifquery --version</code>. On recent Alpine Linux versions, it is likely that ifupdown-ng is configured. The corresponding documentation can be found here: https://github.com/ifupdown-ng/ifupdown-ng/blob/main/doc/ADMIN-GUIDE.md}}


For IPv4 nameservers, edit your <code>/etc/resolv.conf</code> file to look like this:<br />
=== Loopback configuration ===
The following example uses [http://en.wikipedia.org/wiki/Google_Public_DNS Google's Public DNS servers].
  nameserver 8.8.8.8
nameserver 8.8.4.4


For IPv6 nameservers, edit your <code>/etc/resolv.conf</code> file to look like this:<br />
{{Note|The loopback configuration is mandatory and must appear first in {{path|/etc/network/interfaces}} to prevent networking issues.}}
The following example uses [http://www.he.net/ Hurricane Electric's] public DNS server.
nameserver 2001:470:20::2
You can also use Hurricane Electric's public DNS server via IPv4:
nameserver 74.82.42.42


{{Tip|If you decide to use Hurricane Electric's nameserver, be aware that it is 'Google-whitelisted'. What does this mean?  It allows you access to many of Google's services via IPv6. (Just don't add other, non-whitelisted, nameservers to <code>/etc/resolv.conf</code> — ironically, such as Google's Public DNS Servers.) Read [http://www.google.com/intl/en/ipv6/ here] for more information.}}
To configure loopback, add the following to a new file {{path|/etc/network/interfaces}}: {{cat|/etc/network/interfaces|...
auto lo
iface lo inet loopback
}}


= Enabling IPv6 (Optional) =
The above works to set up the IPv4 loopback address (127.0.0.1), and the IPv6 loopback address (<code>::1</code>) — if you enabled IPv6.


If you use IPv6, do the following to enable IPv6 for now and at each boot:
=== Wireless configuration ===
{{Cmd|modprobe ipv6
echo "ipv6" >> /etc/modules}}


= Interface Configuration =
Alpine Linux supports two wireless daemons i.e [[Wi-Fi#wpa_supplicant|wpa_supplicant]] and [[iwd]]. <code>setup-interfaces</code> script uses  [[Wi-Fi#wpa_supplicant|wpa_supplicant]] to configure wireless interface.


== Loopback Configuration (Required) ==
{{Note| Using both wireless daemons simultaneously lead to conflicts.}}
To configure loopback, add the following to a new file <code>/etc/network/interfaces</code>:
<pre>auto lo
iface lo inet loopback</pre>


The above works to setup the IPv4 loopback address (127.0.0.1), and the IPv6 loopback address (<code>::1</code>) — if you enabled IPv6.
=== Ethernet configuration ===


== Ethernet Configuration ==
For the following Ethernet configuration examples, we will assume that you are using Ethernet device <code>eth0</code>.
For the following Ethernet configuration examples, we will assume that you are using Ethernet device <code>eth0</code>.


=== Initial Configuration ===
==== Initial configuration ====
Add the following to the file <code>/etc/network/interfaces</code>, above any IP configuration for <code>eth0</code>:
Add the following to the file {{path|/etc/network/interfaces}}, above any IP configuration for <code>eth0</code>:
<pre>auto eth0</pre>
{{cat|/etc/network/interfaces|...
auto eth0
...
}}
 
==== IPv4 DHCP configuration ====
Add the following to the file {{path|/etc/network/interfaces}}, below the <code>auto eth0</code> definition:
{{cat|/etc/network/interfaces|...
iface eth0 inet dhcp
...
}}
By default, the busybox DHCP client (udhcpc) requests a static set of options from the DHCP server. If you need to extend this set, you can do so by setting some additional command line options for the DHCP client, via the <code>udhcpc_opts</code> in your interface configuration. The following example requests
<code>domain-search</code> option:
{{cat|/etc/network/interfaces|...
iface eth0 inet dhcp
    udhcpc_opts -O search
...
}}
For a complete list of command line options for udhcpc, see [https://busybox.net/downloads/BusyBox.html#udhcpc this document].
 
==== IPv4 Static Address Configuration ====
Add the following to the file {{path|/etc/network/interfaces}}, below the <code>auto eth0</code> definition:
 
{{cat|/etc/network/interfaces|...
iface eth0 inet static
        address 192.168.1.150
        netmask 255.255.255.0
        gateway 192.168.1.1
...
}}
 
Since Alpine 3.13 (and only if you have <code>ifupdown-ng</code> installed) must be:
 
{{cat|/etc/network/interfaces|...
iface eth0 inet static
        address 192.168.1.150/24
        gateway 192.168.1.1
...
}}


=== IPv4 DHCP Configuration ===
===== Additional IP addresses =====
Add the following to the file <code>/etc/network/interfaces</code>, below the <code>auto eth0</code> definition:
<pre>iface eth0 inet dhcp</pre>


=== IPv4 Static Address Configuration ===
{{cat|/etc/network/interfaces|...
Add the following to the file <code>/etc/network/interfaces</code>, below the <code>auto eth0</code> definition:
iface eth0 inet static
<pre>iface eth0 inet static
         address 192.168.1.150
         address 192.168.1.150
         netmask 255.255.255.0
         netmask 255.255.255.0
        gateway 192.168.1.1</pre>


=== IPv6 Stateless Autoconfiguration ===
iface eth0 inet static
Add the following to the file <code>/etc/network/interfaces</code>, below the <code>auto eth0</code> definition:
        address 192.168.1.151/24
<pre>iface eth0 inet6 manual
...
        pre-up echo 1 > /proc/sys/net/ipv6/conf/eth0/accept_ra</pre>
}}
 
Since Alpine 3.13 (and only if you have <code>ifupdown-ng</code> installed) must be:
 
{{cat|/etc/network/interfaces|...
iface eth0 inet static
        address 192.168.1.150/24
        gateway 192.168.1.1
 
iface eth0 inet static
        address 192.168.1.151/24
...
}}
 
==== IPv6 DHCP Configuration ====
Alpine's use of ifupdown-ng supports three DHCP clients: udhcpc, dhclient, and dhcpcd. Of these, only dhcpcd can interact with both DHCP and DHCPv6 from the same process, which ifupdown-ng requires. Thus the IPv4 DHCP configuration given above will also result in the use of DHCPv6, but only if you install the dhcpcd package. (The ifupdown-ng scripts prioritize dhclient over udhcpc, and they prioritize dhcpcd over dhclient; see {{path|/usr/libexec/ifupdown-ng/dhcp}}.)
 
==== IPv6 Stateless Autoconfiguration ====
Add the following to the file {{path|/etc/network/interfaces}}, below the <code>auto eth0</code> definition:
{{cat|/etc/network/interfaces|...
iface eth0 inet6 auto
...
}}


{{Note|'''''The inet6 "manual" method is not yet available in busybox.  A patch has been submitted for review.'''''}}
==== IPv6 Static Address Configuration ====
Add the following to the file {{path|/etc/network/interfaces}}, below the <code>auto eth0</code> definition:


=== IPv6 Static Address Configuration ===
{{cat|/etc/network/interfaces|...
Add the following to the file <code>/etc/network/interfaces</code>, below the <code>auto eth0</code> definition:
iface eth0 inet6 static
<pre>iface eth0 inet6 static
         address 2001:470:ffff:ff::2
         address 2001:470:ffff:ff::2
         netmask 64
         netmask 64
         gateway 2001:470:ffff:ff::1
         gateway 2001:470:ffff:ff::1
         pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra</pre>
         pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra
...
}}
 
Since Alpine Linux 3.13 (and only if you have <code>ifupdown-ng</code> installed) must be as:
 
{{cat|/etc/network/interfaces|...
iface eth0 inet6 static
        address 2001:470:ffff:ff::2/64
        gateway 2001:470:ffff:ff::1
        pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra
...
}}
 
=== Example: Dual-Stack Configuration ===


== Example: Dual-Stack Configuration ==
This example shows a dual-stack configuration.
This example shows a dual-stack configuration.
<pre>auto lo
 
{{cat|/etc/network/interfaces|auto lo
iface lo inet loopback
iface lo inet loopback


Line 103: Line 198:
iface eth0 inet static
iface eth0 inet static
         address 192.168.1.150
         address 192.168.1.150
        netmask 255.255.255.0
      netmask 255.255.255.0
         gateway 192.168.1.1
         gateway 192.168.1.1


Line 110: Line 205:
         netmask 64
         netmask 64
         gateway 2001:470:ffff:ff::1
         gateway 2001:470:ffff:ff::1
         pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra</pre>
         pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra
}}
 
Take care since Alpine 3.13 (and only if you have <code>ifupdown-ng</code> installed) must be as:
 
{{cat|/etc/network/interfaces|auto lo
iface lo inet loopback
 
auto eth0
 
iface eth0 inet static
        address 192.168.1.150/24
        gateway 192.168.1.1


= Firewalling with iptables and ip6tables =
iface eth0 inet6 static
== Install iptables/ip6tables ==
        address 2001:470:ffff:ff::2/64
* To install iptables:
        gateway 2001:470:ffff:ff::1
: {{Cmd|apk add iptables}}
        pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra
}}


* To install ip6tables:
== Networking service ==
: {{Cmd|apk add ip6tables}}


* To install the man pages for iptables and ip6tables:
Changes made to {{path|/etc/network/interfaces}} can be activated by running: {{Cmd|# rc-service networking restart}}
: {{Cmd|apk add iptables-doc}}
To '''start''' (or '''restart''') the networking service: {{Cmd|# rc-service networking --quiet start &}}
To add networking service so that it starts on boot: {{Cmd|# rc-update add networking boot}}


== Configure iptables/ip6tables ==
== Firewall==
{{ Tip| Good examples of how to write iptables rules can be found at the Linux Home Networking Wiki http://www.linuxhomenetworking.com/wiki/index.php/Quick_HOWTO_:_Ch14_:_Linux_Firewalls_Using_iptables }}


== Save Firewall Rules ==
Alpine Linux provides multiple firewall software. Some of the prominent ones are listed below:
* [https://git.alpinelinux.org/awall/about/ Alpine Wall User's Guide]
* [[Iptables]]
* [[nftables]]
* [[Uncomplicated Firewall]]


=== For iptables ===
== Troubleshooting ==
# Set iptables to start on reboot
#* {{ Cmd| rc-update add iptables }}
# Write the firewall rules to disk
#* {{ Cmd| /etc/init.d/iptables save}}
# If you use Alpine Local Backup:
## Add the firewall rules to Alpine Local Backup
##* {{ Cmd| lbu add /var/lib/iptables/rules-save }}
## Save the configuration
##* {{ Cmd| lbu ci }}


=== For ip6tables ===
=== Connectivity testing ===
# Set ip6tables to start on reboot
#* {{ Cmd| rc-update add ip6tables }}
# Write the firewall rules to disk
#* {{ Cmd| /etc/init.d/ip6tables save}}
# If you use Alpine Local Backup:
## Add the firewall rules to Alpine Local Backup
##* {{ Cmd| lbu add /var/lib/ip6tables/rules-save }}
## Save the configuration
##* {{ Cmd| lbu ci }}


= Activating Changes and Testing Connectivity =
Test if networking is configured properly by attempting to ping out:
Changes made to <code>/etc/network/interfaces</code> can be activated by running:
{{Cmd|<nowiki>$ ping www.google.com
{{Cmd|/etc/init.d/networking restart}}
PING www.l.google.com (74.125.47.103) 56(84) bytes of data.
If you did not get any errors, you can now test that networking is configured properly by attempting to ping out:
{{Cmd|ping www.google.com}}
<pre>PING www.l.google.com (74.125.47.103) 56(84) bytes of data.
64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=1 ttl=48 time=58.5 ms
64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=1 ttl=48 time=58.5 ms
64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=2 ttl=48 time=56.4 ms
64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=2 ttl=48 time=56.4 ms
Line 163: Line 253:
--- www.l.google.com ping statistics ---
--- www.l.google.com ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
4 packets transmitted, 4 received, 0% packet loss, time 3007ms
rtt min/avg/max/mdev = 56.411/58.069/60.256/1.501 ms</pre>
rtt min/avg/max/mdev = 56.411/58.069/60.256/1.501 ms
 
</nowiki>}}
For an IPv6 traceroute (<code>traceroute6</code>), you will first need to install the <code>iputils</code> package:
{{Cmd|apk add iputils}}


Then run <code>traceroute6</code>:
For an IPv6 traceroute run <code>traceroute6</code>:
{{Cmd|traceroute6 ipv6.google.com}}
{{Cmd|$ traceroute6 ipv6.google.com
<pre>traceroute to ipv6.l.google.com (2001:4860:8009::67) from 2001:470:ffff:ff::2, 30 hops max, 16 byte packets
traceroute to ipv6.l.google.com (2001:4860:8009::67) from 2001:470:ffff:ff::2, 30 hops max, 16 byte packets
  1  2001:470:ffff:ff::1 (2001:470:ffff:ff::1)  3.49 ms  0.62 ms  0.607 ms
  1  2001:470:ffff:ff::1 (2001:470:ffff:ff::1)  3.49 ms  0.62 ms  0.607 ms
  2  *  *  *
  2  *  *  *
Line 179: Line 267:
  7  2001:4860::2:0:a7 (2001:4860::2:0:a7)  101.754 ms  100.475 ms  100.512 ms
  7  2001:4860::2:0:a7 (2001:4860::2:0:a7)  101.754 ms  100.475 ms  100.512 ms
  8  2001:4860:0:1::c3 (2001:4860:0:1::c3)  99.272 ms  111.989 ms  99.835 ms
  8  2001:4860:0:1::c3 (2001:4860:0:1::c3)  99.272 ms  111.989 ms  99.835 ms
  9  yw-in-x67.1e100.net (2001:4860:8009::67)  101.545 ms  109.675 ms  99.431 ms</pre>
  9  yw-in-x67.1e100.net (2001:4860:8009::67)  101.545 ms  109.675 ms  99.431 ms
}}
 
=== iproute2 ===
 
Install the {{pkg|iproute2}} package which provides the 'ss' command which is an alternate to netstat.: {{Cmd|# apk add iproute2}}
 
Show listening tcp ports:{{Cmd|$ ss -tl}}
Show listening tcp ports and associated processes:{{Cmd|$ ss -ptl}}
Show listening and established tcp connections:{{Cmd|$ ss -ta}}
Show socket usage summary:{{Cmd|$ ss -s}}
Show more options:{{Cmd|$ ss -h}}
 
=== drill ===
 
Install {{pkg|drill}} (it will also install the 'ldns' package) which is a superior replacement for nslookup and dig etc: {{Cmd|# apk add drill}}
 
Then use it as you would for dig: {{Cmd|$ drill alpinelinux.org @8.8.8.8}}
To perform a reverse lookup (get a name from an IP) use the following syntax: {{Cmd|$ drill -x 8.8.8.8 @208.67.222.222}}
 
=== Missing interface ===
 
Sometimes networking interface will not be detected by the installation media. Refer to the steps to [[Wi-Fi#Prerequisites|check interface]].
Refer to [[Wi-Fi#Troubleshooting|Wifi troubleshooting]] page for issues related to wireless interfaces. If nothing works, you may have to use an alternate interface for installation (e.g. a usb to ethernet adapter).
 
== See also ==
 
You may also wish to review the following network related articles:
* [[NetworkManager]] - Front-end to Networking
* [[VLAN|VLAN setup]]
* [[Bonding|Bonding setup]]
* [[Bridge|Network bridge setup]]
* [[udhcpc|udhcpc configuration]]
* [[Wifi#wpa_supplicant|wpa_supplicant]] - Default wifi daemon
* [[Iwd|iwd]] - An alternate wifi daemon
 
[[Category:Networking]]

Latest revision as of 16:08, 12 February 2025

This page documents the various networking options available in Alpine Linux. This page helps to configure your network and to test your Internet access.

Network setup-scripts

Among the alpine setup scripts that are installed as part of alpine-conf, the following network related scripts are available.

  • setup-hostname
  • setup-interfaces
  • setup-dns
  • setup-proxy
  • setup-ntp

All the above utilities are interactive. When installing Alpine linux, the setup-alpine script should have given you the option to setup ethernet/networking. If you need to setup your networking after installation you can use setup-interfaces script. The script configures wireless and ethernet interfaces in addition to other types and will satisfy most trivial configurations.

setup-interfaces

Start the script by running this command:

# setup-interfaces

Available interfaces are: eth0 wlan0.
Enter '?' for help on bridges, bonding and vlans.
Which one do you want to initialize? (or '?' or 'done') [eth0]

choose eth0 for Ethernet or wlan0 for wireless device, as appropriate.

if asked:

Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp]

choose dhcp

Now it will ask Do you to do any manual network configuration? (y/n) [n]

In most cases, you can accept the default option n . Choose y to open the /etc/network/interfaces file for editing in vi editor to proceed with manual network configuration.

The above script configures Networking service adds to boot run level and starts the service. Refer Networking service section, if this needs to be done manually.

For a versatile networking front end refer NetworkManager. If your networking needs are more advanced, you have to refer to the following detailed guide for manual network configuration.

Setting hostname

To set the system hostname:

# echo "shortname" > /etc/hostname

Then, to activate the change:

# hostname -F /etc/hostname

If you're using IPv6, you should also add the following special IPv6 addresses to your /etc/hosts file:

Contents of /etc/hosts

... ::1 localhost ipv6-localhost ipv6-loopback fe00::0 ipv6-localnet ff00::0 ipv6-mcastprefix ff02::1 ipv6-allnodes ff02::2 ipv6-allrouters ff02::3 ipv6-allhosts
Tip: If you're going to use automatic IP configuration, such as IPv4 DHCP or IPv6 Stateless Autoconfiguration, you can skip ahead to Configuring DNS. Otherwise, if you're going to use a static IPv4 or IPv6 address, continue below.

For a static IP configuration, it's common to also add the machine's hostname you just set (above) to the /etc/hosts file.

Here's an IPv4 example:

Contents of /etc/hosts

... 192.168.1.150 shortname.domain.com ...

And here's an IPv6 example:

Contents of /etc/hosts

... 2001:470:ffff:ff::2 shortname.domain.com ...

Configuring DNS

Tip: For users of IPv4 DHCP: Please note that /etc/resolv.conf will be completely overwritten with any nameservers provided by DHCP. If DHCP does not provide any nameservers, then /etc/resolv.conf will still be overwritten, but will not contain any nameservers!

For a static IP address and static nameservers, use one of the following examples.

For IPv4 nameservers, edit your /etc/resolv.conf file to look like this:
The following example uses Google's Public DNS servers.

Contents of /etc/resolv.conf

nameserver 8.8.8.8 nameserver 8.8.4.4

For IPv6 nameservers, edit your /etc/resolv.conf file to look like this:
The following example uses Hurricane Electric's public DNS server.

Contents of /etc/resolv.conf

nameserver 2001:470:20::2

You can also use Hurricane Electric's public IPv4 DNS server:

Contents of /etc/resolv.conf

nameserver 74.82.42.42
Tip: If you decide to use Hurricane Electric's nameserver, be aware that it is 'Google-whitelisted'. What does this mean? It allows you access to many of Google's services via IPv6. (Just don't add other, non-whitelisted, nameservers to /etc/resolv.conf — ironically, such as Google's Public DNS Servers.) Read here for more information.

Interface configuration

Note: Before configuring any interfaces via /etc/network/interfaces, check the type of network manager used in your system. You may check so via the command ifquery --version. On recent Alpine Linux versions, it is likely that ifupdown-ng is configured. The corresponding documentation can be found here: https://github.com/ifupdown-ng/ifupdown-ng/blob/main/doc/ADMIN-GUIDE.md

Loopback configuration

Note: The loopback configuration is mandatory and must appear first in /etc/network/interfaces to prevent networking issues.

To configure loopback, add the following to a new file /etc/network/interfaces:

Contents of /etc/network/interfaces

... auto lo iface lo inet loopback

The above works to set up the IPv4 loopback address (127.0.0.1), and the IPv6 loopback address (::1) — if you enabled IPv6.

Wireless configuration

Alpine Linux supports two wireless daemons i.e wpa_supplicant and iwd. setup-interfaces script uses wpa_supplicant to configure wireless interface.

Note: Using both wireless daemons simultaneously lead to conflicts.

Ethernet configuration

For the following Ethernet configuration examples, we will assume that you are using Ethernet device eth0.

Initial configuration

Add the following to the file /etc/network/interfaces, above any IP configuration for eth0:

Contents of /etc/network/interfaces

... auto eth0 ...

IPv4 DHCP configuration

Add the following to the file /etc/network/interfaces, below the auto eth0 definition:

Contents of /etc/network/interfaces

... iface eth0 inet dhcp ...

By default, the busybox DHCP client (udhcpc) requests a static set of options from the DHCP server. If you need to extend this set, you can do so by setting some additional command line options for the DHCP client, via the udhcpc_opts in your interface configuration. The following example requests domain-search option:

Contents of /etc/network/interfaces

... iface eth0 inet dhcp udhcpc_opts -O search ...

For a complete list of command line options for udhcpc, see this document.

IPv4 Static Address Configuration

Add the following to the file /etc/network/interfaces, below the auto eth0 definition:

Contents of /etc/network/interfaces

... iface eth0 inet static address 192.168.1.150 netmask 255.255.255.0 gateway 192.168.1.1 ...

Since Alpine 3.13 (and only if you have ifupdown-ng installed) must be:

Contents of /etc/network/interfaces

... iface eth0 inet static address 192.168.1.150/24 gateway 192.168.1.1 ...
Additional IP addresses

Contents of /etc/network/interfaces

... iface eth0 inet static address 192.168.1.150 netmask 255.255.255.0 iface eth0 inet static address 192.168.1.151/24 ...

Since Alpine 3.13 (and only if you have ifupdown-ng installed) must be:

Contents of /etc/network/interfaces

... iface eth0 inet static address 192.168.1.150/24 gateway 192.168.1.1 iface eth0 inet static address 192.168.1.151/24 ...

IPv6 DHCP Configuration

Alpine's use of ifupdown-ng supports three DHCP clients: udhcpc, dhclient, and dhcpcd. Of these, only dhcpcd can interact with both DHCP and DHCPv6 from the same process, which ifupdown-ng requires. Thus the IPv4 DHCP configuration given above will also result in the use of DHCPv6, but only if you install the dhcpcd package. (The ifupdown-ng scripts prioritize dhclient over udhcpc, and they prioritize dhcpcd over dhclient; see /usr/libexec/ifupdown-ng/dhcp.)

IPv6 Stateless Autoconfiguration

Add the following to the file /etc/network/interfaces, below the auto eth0 definition:

Contents of /etc/network/interfaces

... iface eth0 inet6 auto ...

IPv6 Static Address Configuration

Add the following to the file /etc/network/interfaces, below the auto eth0 definition:

Contents of /etc/network/interfaces

... iface eth0 inet6 static address 2001:470:ffff:ff::2 netmask 64 gateway 2001:470:ffff:ff::1 pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra ...

Since Alpine Linux 3.13 (and only if you have ifupdown-ng installed) must be as:

Contents of /etc/network/interfaces

... iface eth0 inet6 static address 2001:470:ffff:ff::2/64 gateway 2001:470:ffff:ff::1 pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra ...

Example: Dual-Stack Configuration

This example shows a dual-stack configuration.

Contents of /etc/network/interfaces

auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.1.150 netmask 255.255.255.0 gateway 192.168.1.1 iface eth0 inet6 static address 2001:470:ffff:ff::2 netmask 64 gateway 2001:470:ffff:ff::1 pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra

Take care since Alpine 3.13 (and only if you have ifupdown-ng installed) must be as:

Contents of /etc/network/interfaces

auto lo iface lo inet loopback auto eth0 iface eth0 inet static address 192.168.1.150/24 gateway 192.168.1.1 iface eth0 inet6 static address 2001:470:ffff:ff::2/64 gateway 2001:470:ffff:ff::1 pre-up echo 0 > /proc/sys/net/ipv6/conf/eth0/accept_ra

Networking service

Changes made to /etc/network/interfaces can be activated by running:

# rc-service networking restart

To start (or restart) the networking service:

# rc-service networking --quiet start &

To add networking service so that it starts on boot:

# rc-update add networking boot

Firewall

Alpine Linux provides multiple firewall software. Some of the prominent ones are listed below:

Troubleshooting

Connectivity testing

Test if networking is configured properly by attempting to ping out:

$ ping www.google.com PING www.l.google.com (74.125.47.103) 56(84) bytes of data. 64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=1 ttl=48 time=58.5 ms 64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=2 ttl=48 time=56.4 ms 64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=3 ttl=48 time=57.0 ms 64 bytes from yw-in-f103.1e100.net (74.125.47.103): icmp_seq=4 ttl=48 time=60.2 ms ^C --- www.l.google.com ping statistics --- 4 packets transmitted, 4 received, 0% packet loss, time 3007ms rtt min/avg/max/mdev = 56.411/58.069/60.256/1.501 ms

For an IPv6 traceroute run traceroute6:

$ traceroute6 ipv6.google.com traceroute to ipv6.l.google.com (2001:4860:8009::67) from 2001:470:ffff:ff::2, 30 hops max, 16 byte packets 1 2001:470:ffff:ff::1 (2001:470:ffff:ff::1) 3.49 ms 0.62 ms 0.607 ms 2 * * * 3 * * * 4 pr61.iad07.net.google.com (2001:504:0:2:0:1:5169:1) 134.313 ms 95.342 ms 88.425 ms 5 2001:4860::1:0:9ff (2001:4860::1:0:9ff) 100.759 ms 100.537 ms 89.907 ms 6 2001:4860::1:0:5db (2001:4860::1:0:5db) 115.563 ms 102.946 ms 106.191 ms 7 2001:4860::2:0:a7 (2001:4860::2:0:a7) 101.754 ms 100.475 ms 100.512 ms 8 2001:4860:0:1::c3 (2001:4860:0:1::c3) 99.272 ms 111.989 ms 99.835 ms 9 yw-in-x67.1e100.net (2001:4860:8009::67) 101.545 ms 109.675 ms 99.431 ms

iproute2

Install the iproute2 package which provides the 'ss' command which is an alternate to netstat.:

# apk add iproute2

Show listening tcp ports:

$ ss -tl

Show listening tcp ports and associated processes:

$ ss -ptl

Show listening and established tcp connections:

$ ss -ta

Show socket usage summary:

$ ss -s

Show more options:

$ ss -h

drill

Install drill (it will also install the 'ldns' package) which is a superior replacement for nslookup and dig etc:

# apk add drill

Then use it as you would for dig:

$ drill alpinelinux.org @8.8.8.8

To perform a reverse lookup (get a name from an IP) use the following syntax:

$ drill -x 8.8.8.8 @208.67.222.222

Missing interface

Sometimes networking interface will not be detected by the installation media. Refer to the steps to check interface. Refer to Wifi troubleshooting page for issues related to wireless interfaces. If nothing works, you may have to use an alternate interface for installation (e.g. a usb to ethernet adapter).

See also

You may also wish to review the following network related articles: