Configure Networking: Difference between revisions

From Alpine Linux
(added reference to setup scripts, changed heading levels)
m (readability improvements)
 
(41 intermediate revisions by 2 users not shown)
Line 1: Line 1:
This page will assist you in setting up networking on Alpine Linux.
This page documents the steps to configure network in Alpine Linux using either [[#Network setup-scripts|Network setup-scripts]] or manually and to [[#Connectivity testing|test]] your Internet access. Alpine Linux uses [[ifupdown-ng]] for managing its network configuration by default. For additional gui/tui networking tools [[NetworkManager]] can be used.  


{{Note|You must be logged in as root in order to perform the actions on this page.}}
For Wireless, [[Wi-Fi|wpa_supplicant]] and [[iwd]] are available and both are fully supported in Alpine Linux. [[Wi-Fi|wpa_supplicant]] is the default wireless daemon and is configured as part of [[#setup-interfaces|setup-interfaces]] script.
 
{{Tip|To setup basic networking quickly, use [[#setup-interfaces|setup-interfaces]] script.}}


== Network setup-scripts ==
== Network setup-scripts ==


Among the alpine setup scripts that are installed as part of <code>alpine-conf</code>, the following network related scripts are available.  
A number of network related scripts are available from the {{pkg|alpine-conf}} package as part of [[Alpine setup scripts]]. These scripts can quickly configure various networking related options in Alpine Linux and satisfies most trivial configurations. 
 
When [[Installation|installing]] Alpine linux, the <code>setup-alpine</code> script interactively calls the scripts to setup networking.  
 
* <code>[[Alpine_setup_scripts#setup-hostname|setup-hostname]]</code>
* <code>[[#setup-interfaces|setup-interfaces]]</code>
* <code>[[Alpine_setup_scripts#setup-dns|setup-dns]]</code>
* <code>[[Alpine_setup_scripts#setup-proxy|setup-proxy]]</code>
* <code>[[Alpine_setup_scripts#setup-ntp|setup-ntp]]</code>
 
=== setup-interfaces ===


* <code>setup-hostname</code>
This script can be used to configure ethernet, [[Wi-Fi|wireless]], bridge, bond and vlan interfaces and will satisfy most trivial configurations. Start the script by running the command: {{Cmd|# setup-interfaces}}
* <code>setup-interfaces</code>
Available interfaces are: eth0 wlan0.
* <code>setup-dns</code>
Enter '?' for help on bridges, bonding and vlans.
* <code>setup-proxy</code>
Which one do you want to initialize? (or '?' or 'done') [eth0]
* <code>setup-ntp</code>


All the utilities are interactive in nature, when invoked as follows:
choose <code>eth0</code> for Ethernet or <code>wlan0</code> for wireless device, as appropriate.


{{Cmd|# setup-interfaces}}
if asked:
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp]


helps to configure wireless and ethernet interfaces in addition to a lot other types.
choose <code>dhcp</code>, if you are using dhcp.


The above scripts will satisfy most trivial configurations. If you're needs are more advanced, you've to refer to the following detailed guides..
Now it will ask <code>Do you to do any manual network configuration? (y/n) [n]</code>


== Setting System Hostname ==
In most cases, you can accept the default option '''n''' . Choosing '''y''' will open the {{Path|/etc/network/interfaces}} file for editing in [[BusyBox#vi| '''vi''' editor]] to proceed with manual network configuration.
To set the system hostname:
{{Cmd|# echo "shortname" > /etc/hostname}}


Then, to activate the change:
The above script configures [[Configure_Networking#Networking_service|Networking service]], starts the service and adds it to the boot run level.
{{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:
If your networking needs are more advanced, refer to the following detailed guide for manual network configuration.
{{cat|/etc/hosts|...
 
== 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
::1            localhost ipv6-localhost ipv6-loopback
fe00::0        ipv6-localnet
fe00::0        ipv6-localnet
Line 42: Line 58:
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.
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:
Here's an IPv4 example:{{cat|/etc/hosts|...
{{cat|/etc/hosts|...
192.168.1.150  shortname.domain.com
192.168.1.150  shortname.domain.com
...
...
}}
}}


And here's an IPv6 example:
And here's an IPv6 example:{{cat|/etc/hosts|...
{{cat|/etc/hosts|...
2001:470:ffff:ff::2  shortname.domain.com
2001:470:ffff:ff::2  shortname.domain.com
...
...
Line 55: Line 69:


== Configuring DNS ==
== Configuring DNS ==
{{Tip|'''For users of IPv4 DHCP:''' Please note that {{path|/etc/resolv.conf}} will be completely overwritten with any nameservers provided by DHCP.
{{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!}}
If DHCP does not provide any nameservers, then {{path|/etc/resolv.conf}} will still be overwritten, but will not contain any nameservers!}}
Line 74: Line 89:
{{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.}}
{{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.}}


== Interface Configuration ==
== Interface configuration ==
{{Seealso|Wi-Fi}}
Manual interface configuration is explained in the following sections to meet non-trivial networking requirements. In the following configuration examples, the device name used is <code>eth0</code>. It can be substituted by appropriate device names like <code>wlan0</code> for wireless etc..


=== Loopback Configuration (Required) ===
=== Loopback configuration  ===
{{Note|The loopback configuration must appear first in {{path|/etc/network/interfaces}} to prevent networking issues.}}
 
To configure loopback, add the following to a new file {{path|/etc/network/interfaces}}:
To configure loopback, add the following to the file {{path|/etc/network/interfaces}}: {{cat|/etc/network/interfaces|auto lo
{{cat|/etc/network/interfaces|...
iface lo inet loopback}}
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 (<code>::1</code>) — if you enabled IPv6.
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.


=== Wireless Configuration ===
{{Note| For [[#Busybox ifupdown|Busybox ifupdown]], loopback configuration must appear first in {{path|/etc/network/interfaces}} file to prevent networking issues.}}


See [[Connecting to a wireless access point]].
=== DHCP configuration ===


=== Ethernet Configuration ===
A basic configuration for a desktop computer appears as follows:{{cat|/etc/network/interfaces|...
For the following Ethernet configuration examples, we will assume that you are using Ethernet device <code>eth0</code>.
 
==== Initial Configuration ====
Add the following to the file {{path|/etc/network/interfaces}}, above any IP configuration for <code>eth0</code>:
{{cat|/etc/network/interfaces|...
auto eth0
auto eth0
...
iface eth0
}}
    use dhcp}}
 
==== 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 ====
Refer busybox DHCP client [[udhcpc]] page for additional configuration options. If {{pkg|dhcpcd}} is installed, with [[ifupdown-ng]], DHCPv6 will also be used as dhcpcd interacts with both DHCPv4 and DHCPv6 from the same process.
Add the following to the file {{path|/etc/network/interfaces}}, below the <code>auto eth0</code> definition:


{{cat|/etc/network/interfaces|...
==== IPv6 stateless autoconfiguration ====
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:
With IPv6, stateless auto-configuration is typically used to configure network interfaces. If you are not interested in using IPv4 at all, you can simply use the ipv6-ra executor to ensure that an interface is configured to accept IPv6 RA advertisements:{{cat|/etc/network/interfaces|...
auto eth0
iface eth0
    use ipv6-ra}}


{{cat|/etc/network/interfaces|...
=== Static address configuration ===
iface eth0 inet static
        address 192.168.1.150/24
        gateway 192.168.1.1
...
}}


Add the following to the file {{path|/etc/network/interfaces}}: {{cat|/etc/network/interfaces|...
auto eth0
iface eth0
    address 203.0.113.2/24
    gateway 203.0.113.1}}


===== Additional IP addresses =====
==== Multiple address ====


{{cat|/etc/network/interfaces|...
{{cat|/etc/network/interfaces|...
iface eth0 inet static
auto eth0
        address 192.168.1.150
iface eth0
        netmask 255.255.255.0
    address 203.0.113.2/24
    address 203.0.113.3/24
    address 203.0.113.4/24
    gateway 203.0.113.1}}


iface eth0 inet static
====  Dual-stack configuration ====
        address 192.168.1.151/24
...
}}


Since Alpine 3.13 (and only if you have <code>ifupdown-ng</code> installed) must be:
This example shows a dual-stack configuration. {{cat|/etc/network/interfaces|...
auto eth0
iface eth0
    address 203.0.113.2/24
    address 203.0.113.3/24
    address 203.0.113.4/24
    gateway 203.0.113.1


{{cat|/etc/network/interfaces|...
    address 2001:db8:1000:2::2/64
iface eth0 inet static
    address 2001:db8:1000:2::3/64
        address 192.168.1.150/24
    address 2001:db8:1000:2::4/64
        gateway 192.168.1.1
    gateway 2001:db8:1000:2::1}}


iface eth0 inet static
== Networking service ==
        address 192.168.1.151/24
{{Tip|If [[Wi-Fi]] is used, follow the instructions mentioned on those pages.}}
...
Changes made to {{path|/etc/network/interfaces}} related to ethernet can be activated by running: {{Cmd|# rc-service networking restart}}
}}
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}}


==== IPv6 DHCP Configuration ====
== Advanced network 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 ===
=== Busybox ifupdown ===
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
...
}}


==== IPv6 Static Address Configuration ====
If the default [[ifupdown-ng]] is uninstalled, the [[Busybox]] ifupdown gets used. Busybox ifupdown syntax is slightly different from ifupdown-ng, but [[ifupdown-ng]] fully supports Busybox ifupdown syntax.
Add the following to the file {{path|/etc/network/interfaces}}, below the <code>auto eth0</code> definition:


{{cat|/etc/network/interfaces|...
The CIDR notation '''203.0.113.2/24 ''' is not supported by BusyBox ifupdown, so for IP address use subnet mask notation i.e '''203.0.113.2/255.255.255.0'''.  
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 <code>ifupdown-ng</code> installed) must be as:


The interface configuration file {{Path|/etc/network/interfaces}} for DHCP with Busybox ifupdown syntax appears as follows:
{{cat|/etc/network/interfaces|...
{{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 ===
This example shows a dual-stack configuration.
{{cat|/etc/network/interfaces|auto lo
iface lo inet loopback
auto eth0
auto eth0
 
iface eth0 inet dhcp}}
iface eth0 inet static
For static IP address, use the word {{ic|static}} instead of {{ic|dhcp}} and provide ip address as shown:
        address 192.168.1.150
{{cat|/etc/network/interfaces|...
      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 <code>ifupdown-ng</code> installed) must be as:
 
{{cat|/etc/network/interfaces|auto lo
iface lo inet loopback
 
auto eth0
auto eth0
iface eth0 inet static
iface eth0 inet static
        address 192.168.1.150/24
address 203.0.113.2
        gateway 192.168.1.1
netmask 255.255.255.0}}


iface eth0 inet6 static
=== Change network interface name ===
        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
}}


== Firewalling with iptables and ip6tables ==
To change interface names from default <code>eth0</code> or <code>wlan0</code>, refer appropriate device manager pages i.e  [[Eudev#Predictable_network_interface_names|eudev]] or [[Mdev#Custom_network_interface_name|mdev]].


See also: [[Alpine Wall]] - [[How-To Alpine Wall]] - [https://git.alpinelinux.org/awall/about/ Alpine Wall User's Guide].
Alternately, if [[ifupdown-ng]] is used, to set network interface name as {{ic|dmz}} for a MAC address {{ic|00:11:22:33:44:55}} add the following {{ic|pre-up}} command to your file {{Path|/etc/network/interfaces}} as follows:
{{Cat|/etc/network/interfaces|...
<nowiki>auto dmz
iface dmz inet dhcp
    pre-up nameif -s dmz 00:11:22:33:44:55
</nowiki>}}


=== Install iptables/ip6tables ===
=== Change MAC or hw address ===
* To install iptables (includes ip6tables in alpine 3.19 and up):
: {{Cmd|# apk add {{pkg|iptables|arch=}}}}


* To install ip6tables (Alpine older than 3.19 only):
If [[ifupdown-ng]] is used, to set the MAC or hw address as {{ic|de:ad:be:ef:ca:fe}} for {{ic|wlan0}} interface, add the following {{ic|pre-up}} command to the relevant interface configuration stanza in the file {{Path|/etc/network/interfaces}} as follows:
: {{Cmd|# apk add {{pkg|ip6tables|branch=v3.18|arch=}}}}
{{Cat|/etc/network/interfaces|...
 
<nowiki>auto wlan0
* To install the man pages for iptables and ip6tables:
iface wlan0 inet dhcp
: {{Cmd|# apk add {{pkg|iptables-doc|arch=}}}}
  pre-up ip link set $IFACE addr de:ad:be:ef:ca:fe
</nowiki>}}


=== Configure iptables/ip6tables ===
== Troubleshooting ==


=== Connectivity testing ===


=== Save Firewall Rules ===
Test if networking is configured properly by attempting to ping out:
 
=== For iptables ===
# Set iptables to start on reboot
#* {{ Cmd|# rc-update add iptables }}
# Write the firewall rules to disk
#* {{ Cmd|# rc-service iptables save}}
# If you use Alpine Local Backup:
<!-- Not needed on Alpine > 2.3
## Add the firewall rules to Alpine Local Backup
##* {{ Cmd|# lbu add /var/lib/iptables/rules-save }}
-->
## Save the configuration
##* {{ Cmd|# lbu ci }}
 
=== For ip6tables ===
# Set ip6tables to start on reboot
#* {{ Cmd|# rc-update add ip6tables }}
# Write the firewall rules to disk
#* {{ Cmd|# rc-service ip6tables save}}
# If you use Alpine Local Backup:
<!-- Not needed on Alpine > 2.3
## 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 ==
Changes made to {{path|/etc/network/interfaces}} can be activated by running:
{{Cmd|# rc-service networking restart}}
If you did not get any errors, you can now test that networking is configured properly by attempting to ping out:
{{Cmd|<nowiki>$ ping www.google.com
{{Cmd|<nowiki>$ ping www.google.com
PING www.l.google.com (74.125.47.103) 56(84) bytes of data.
PING www.l.google.com (74.125.47.103) 56(84) bytes of data.
Line 304: Line 226:
  9  yw-in-x67.1e100.net (2001:4860:8009::67)  101.545 ms  109.675 ms  99.431 ms
  9  yw-in-x67.1e100.net (2001:4860:8009::67)  101.545 ms  109.675 ms  99.431 ms
}}
}}
== Additional Utilities ==


=== iproute2 ===
=== iproute2 ===


You may wish to install the 'iproute2' package (note that this will also install iptables if not yet installed)
Install the {{pkg|iproute2}} package which provides the 'ss' command which is an alternate to netstat.: {{Cmd|# apk add iproute2}}


{{Cmd|# apk add iproute2}}
Show listening tcp ports:{{Cmd|$ ss -tl}}
 
Show listening tcp ports and associated processes:{{Cmd|$ ss -ptl}}
This provides the 'ss' command which is IMHO a 'better' version of netstat.
Show listening and established tcp connections:{{Cmd|$ ss -ta}}
 
Show socket usage summary:{{Cmd|$ ss -s}}
Show listening tcp ports:
Show more options:{{Cmd|$ ss -h}}
{{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 ===
=== drill ===


You may also wish to install 'drill' (it will also install the 'ldns' package) which is a superior (IMHO) replacement for nslookup and dig etc:
Install {{pkg|drill}} (it will also install the 'ldns' package) which is a superior replacement for nslookup and dig etc: {{Cmd|# apk add drill}}
 
{{Cmd|# apk add drill}}
 
Then use it as you would for dig:


{{Cmd|$ drill alpinelinux.org @8.8.8.8}}
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}}


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


{{Cmd|$ drill -x 8.8.8.8 @208.67.222.222}}
To list your available network interfaces use the commands {{ic|ip link}} or {{ic|ip a}}. 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 (e.g. a usb to ethernet adapter).


== Related articles ==
== See also ==


You may also wish to review the following network related articles:
You may also wish to review the following network related articles:
 
* [[Ifupdown-ng|Ifupdown-ng]] Basic networking Device Manager in Alpine Linux
[[VLAN|VLAN setup]]
* [[NetworkManager]] - Alternate Front-end to Networking
 
* [[VLAN]]
[[Bonding|Bonding setup]]
* [https://github.com/ifupdown-ng/ifupdown-ng/blob/main/doc/interfaces-vxlan.scd vxlan]
 
* [[Bonding|Bonding setup]]
[[Bridge|Network bridge setup]]
* [[Bridge|Network bridge setup]]
 
* [[udhcpc|udhcpc configuration]]
[[udhcpc|udhcpc configuration]]
* [[Wifi#wpa_supplicant|wpa_supplicant]] - Default wifi daemon
 
* [[Iwd|iwd]] - An alternate wifi daemon
* [[Tutorials and Howtos#Firewall|List of Firewall software]]


[[Category:Networking]]
[[Category:Networking]]

Latest revision as of 07:49, 16 September 2025

This page documents the steps to configure network in Alpine Linux using either Network setup-scripts or manually and to test your Internet access. Alpine Linux uses ifupdown-ng for managing its network configuration by default. For additional gui/tui networking tools NetworkManager can be used.

For Wireless, wpa_supplicant and iwd are available and both are fully supported in Alpine Linux. wpa_supplicant is the default wireless daemon and is configured as part of setup-interfaces script.

Tip: To setup basic networking quickly, use setup-interfaces script.

Network setup-scripts

A number of network related scripts are available from the alpine-conf package as part of Alpine setup scripts. These scripts can quickly configure various networking related options in Alpine Linux and satisfies most trivial configurations.

When installing Alpine linux, the setup-alpine script interactively calls the scripts to setup networking.

setup-interfaces

This script can be used to configure ethernet, wireless, bridge, bond and vlan interfaces and will satisfy most trivial configurations. Start the script by running the 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, if you are using 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 . Choosing y will open the /etc/network/interfaces file for editing in vi editor to proceed with manual network configuration.

The above script configures Networking service, starts the service and adds it to the boot run level.

If your networking needs are more advanced, 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

Manual interface configuration is explained in the following sections to meet non-trivial networking requirements. In the following configuration examples, the device name used is eth0. It can be substituted by appropriate device names like wlan0 for wireless etc..

Loopback configuration

To configure loopback, add the following to the 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.

Note: For Busybox ifupdown, loopback configuration must appear first in /etc/network/interfaces file to prevent networking issues.

DHCP configuration

A basic configuration for a desktop computer appears as follows:

Contents of /etc/network/interfaces

... auto eth0 iface eth0 use dhcp

Refer busybox DHCP client udhcpc page for additional configuration options. If dhcpcd is installed, with ifupdown-ng, DHCPv6 will also be used as dhcpcd interacts with both DHCPv4 and DHCPv6 from the same process.

IPv6 stateless autoconfiguration

With IPv6, stateless auto-configuration is typically used to configure network interfaces. If you are not interested in using IPv4 at all, you can simply use the ipv6-ra executor to ensure that an interface is configured to accept IPv6 RA advertisements:

Contents of /etc/network/interfaces

... auto eth0 iface eth0 use ipv6-ra

Static address configuration

Add the following to the file /etc/network/interfaces:

Contents of /etc/network/interfaces

... auto eth0 iface eth0 address 203.0.113.2/24 gateway 203.0.113.1

Multiple address

Contents of /etc/network/interfaces

... auto eth0 iface eth0 address 203.0.113.2/24 address 203.0.113.3/24 address 203.0.113.4/24 gateway 203.0.113.1

Dual-stack configuration

This example shows a dual-stack configuration.

Contents of /etc/network/interfaces

... auto eth0 iface eth0 address 203.0.113.2/24 address 203.0.113.3/24 address 203.0.113.4/24 gateway 203.0.113.1 address 2001:db8:1000:2::2/64 address 2001:db8:1000:2::3/64 address 2001:db8:1000:2::4/64 gateway 2001:db8:1000:2::1

Networking service

Tip: If Wi-Fi is used, follow the instructions mentioned on those pages.

Changes made to /etc/network/interfaces related to ethernet 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

Advanced network configuration

Busybox ifupdown

If the default ifupdown-ng is uninstalled, the Busybox ifupdown gets used. Busybox ifupdown syntax is slightly different from ifupdown-ng, but ifupdown-ng fully supports Busybox ifupdown syntax.

The CIDR notation 203.0.113.2/24 is not supported by BusyBox ifupdown, so for IP address use subnet mask notation i.e 203.0.113.2/255.255.255.0.

The interface configuration file /etc/network/interfaces for DHCP with Busybox ifupdown syntax appears as follows:

Contents of /etc/network/interfaces

... auto eth0 iface eth0 inet dhcp

For static IP address, use the word static instead of dhcp and provide ip address as shown:

Contents of /etc/network/interfaces

... auto eth0 iface eth0 inet static address 203.0.113.2 netmask 255.255.255.0

Change network interface name

To change interface names from default eth0 or wlan0, refer appropriate device manager pages i.e eudev or mdev.

Alternately, if ifupdown-ng is used, to set network interface name as dmz for a MAC address 00:11:22:33:44:55 add the following pre-up command to your file /etc/network/interfaces as follows:

Contents of /etc/network/interfaces

... auto dmz iface dmz inet dhcp pre-up nameif -s dmz 00:11:22:33:44:55

Change MAC or hw address

If ifupdown-ng is used, to set the MAC or hw address as de:ad:be:ef:ca:fe for wlan0 interface, add the following pre-up command to the relevant interface configuration stanza in the file /etc/network/interfaces as follows:

Contents of /etc/network/interfaces

... auto wlan0 iface wlan0 inet dhcp pre-up ip link set $IFACE addr de:ad:be:ef:ca:fe

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

To list your available network interfaces use the commands ip link or ip a. Refer to Wifi troubleshooting page for issues related to wireless interfaces. If nothing works, you may have to use an alternate interface (e.g. a usb to ethernet adapter).

See also

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