Configure Networking: Difference between revisions
(Note that ifupdown-ng is required for new syntax of `/etc/network/interfaces`) |
Prabuanand (talk | contribs) (moved content related to Ifupdown-ng to its own page and made appropriate changes) |
||
(39 intermediate revisions by 4 users not shown) | |||
Line 1: | Line 1: | ||
This page | This page documents various networking options available in Alpine Linux and helps to configure your network 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. For WiFi, the default wireless daemon [[Wi-Fi|wpa_supplicant]] and [[iwd]] are fully supported in Alpine Linux. For additional gui/tui networking tools refer [[NetworkManager]]. | |||
== Network setup-scripts == | |||
The following network related scripts are available from the {{pkg|alpine-conf}} package as part of [[Alpine setup scripts]]. | |||
* <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> | |||
All the above utilities are interactive. When [[Installation|installing]] Alpine linux, the <code>setup-alpine</code> script calls all the above scripts to setup networking. | |||
== setup-interfaces == | |||
To setup networking quickly use [[#setup-interfaces|setup-interfaces]] script. The 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: {{Cmd|# 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 <code>eth0</code> for Ethernet or <code>wlan0</code> for wireless device, as appropriate. | |||
if asked: | |||
Ip address for eth0? (or 'dhcp', 'none', '?') [dhcp] | |||
choose <code>dhcp</code>, if you are using dhcp. | |||
Now it will ask <code>Do you to do any manual network configuration? (y/n) [n]</code> | |||
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. | |||
The above script configures [[Configure_Networking#Networking_service|Networking service]], starts the service and adds it to the boot run level. | |||
If | If your networking needs are more advanced, 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 | |||
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|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. | |||
For | |||
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|'''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 address and static nameservers, use one of the following examples. | |||
< | For IPv4 nameservers, edit your {{path|/etc/resolv.conf}} file to look like this:<br /> | ||
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 | |||
}} | |||
For IPv6 nameservers, edit your {{path|/etc/resolv.conf}} file to look like this:<br /> | |||
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}} | |||
{{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 == | |||
iface | === Loopback configuration === | ||
{{Warning|Loopback configuration is mandatory and must appear first in {{path|/etc/network/interfaces}} to prevent networking issues.}} | |||
</ | To configure loopback, add the following to the file {{path|/etc/network/interfaces}}: {{cat|/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 (<code>::1</code>) — if you enabled IPv6. | |||
=== Wireless configuration === | |||
{{Main|Wi-Fi}} | |||
For manual interface configuration as explained in this page, <code>eth0</code> can be substituted by the appropriate wireless interface i.e <code>wlan0</code>. | |||
=== Ethernet configuration === | |||
For the following Ethernet configuration examples, we will assume that you are using Ethernet device <code>eth0</code>. | |||
</ | |||
=== | ==== DHCP configuration ==== | ||
The DHCP configuration with Busybox ifupdown syntax is as follows:{{cat|/etc/network/interfaces|... | |||
auto eth0 | |||
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|... | |||
auto eth0 | |||
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]. | |||
With [[ifupdown-ng]], IPv4 DHCP configuration given on this page will also result in the use of DHCPv6, if {{pkg|dhcpcd}} is installed as dhcpcd can interact with both DHCPv4 and DHCPv6 from the same process. | |||
A basic configuration for a desktop computer using the ifupdown-ng syntax appears as follows:{{cat|/etc/network/interfaces|... | |||
auto eth0 | |||
iface eth0 | |||
use dhcp}} | |||
All further configuration below assumes ifupdown-ng being used, unless stated otherwise. | |||
===== 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:{{cat|/etc/network/interfaces|... | |||
auto eth0 | auto eth0 | ||
iface eth0 | |||
use ipv6-ra}} | |||
==== Static address configuration ==== | |||
iface eth0 | {{Note| If [[ifupdown-ng]] is not available/used, use {{ic|iface eth0 inet static}} instead of {{ic|iface eth0}} and use below address format for IPv4 instead of '''203.0.113.2/24 ''' :{{Cat|/etc/network/interfaces|address 203.0.113.2 | ||
netmask 255.255.255.0}}}} | |||
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}} | |||
===== Multiple address ===== | |||
{{cat|/etc/network/interfaces|... | |||
auto eth0 | 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 ===== | |||
iface eth0 | 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 | |||
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 == | |||
Changes made to {{path|/etc/network/interfaces}} 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}} | |||
== Firewall== | |||
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]] | |||
=== | == Troubleshooting == | ||
=== | === Connectivity testing === | ||
Test if networking is configured properly by attempting to ping out: | |||
{{Cmd|<nowiki>$ ping www.google.com | |||
PING www.l.google.com (74.125.47.103) 56(84) bytes of data. | |||
{{Cmd|ping www.google.com | |||
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 234: | Line 198: | ||
--- 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</ | rtt min/avg/max/mdev = 56.411/58.069/60.256/1.501 ms | ||
</nowiki>}} | |||
For an IPv6 traceroute | For an IPv6 traceroute run <code>traceroute6</code>: | ||
{{Cmd|$ 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 | |||
{{Cmd|traceroute6 ipv6.google.com | |||
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 250: | Line 212: | ||
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 | 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}} | |||
{{Cmd| | |||
Show listening tcp ports and associated processes: | Show listening tcp ports:{{Cmd|$ ss -tl}} | ||
{{Cmd|ss - | 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}} | |||
{{Cmd| | |||
Then use it as you would for dig: {{Cmd|$ drill alpinelinux.org @8.8.8.8}} | |||
{{Cmd| | 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 === | ||
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). | |||
== 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 | |||
[[ | * [[NetworkManager]] - Alternate Front-end to Networking | ||
* [[VLAN|VLAN setup]] | |||
[[Bonding|Bonding setup]] | * [[Bonding|Bonding setup]] | ||
* [[Bridge|Network bridge setup]] | |||
[[Bridge|Network bridge setup]] | * [[udhcpc|udhcpc configuration]] | ||
* [[Wifi#wpa_supplicant|wpa_supplicant]] - Default wifi daemon | |||
[[udhcpc|udhcpc configuration]] | * [[Iwd|iwd]] - An alternate wifi daemon | ||
[[Category:Networking]] | [[Category:Networking]] |
Latest revision as of 06:17, 22 March 2025
This page documents various networking options available in Alpine Linux and helps to configure your network using either Network setup-scripts or manually and to test your Internet access.
Alpine Linux uses ifupdown-ng for managing its network configuration. For WiFi, the default wireless daemon wpa_supplicant and iwd are fully supported in Alpine Linux. For additional gui/tui networking tools refer NetworkManager.
Network setup-scripts
The following network related scripts are available from the alpine-conf package as part of Alpine setup scripts.
All the above utilities are interactive. When installing Alpine linux, the setup-alpine
script calls all the above scripts to setup networking.
setup-interfaces
To setup networking quickly use setup-interfaces script. The 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
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
And here's an IPv6 example:
Contents of /etc/hosts
Configuring DNS
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
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
You can also use Hurricane Electric's public IPv4 DNS server:
Contents of /etc/resolv.conf
Interface configuration
Loopback configuration

To configure loopback, add the following to the file /etc/network/interfaces:
Contents of /etc/network/interfaces
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
For manual interface configuration as explained in this page, eth0
can be substituted by the appropriate wireless interface i.e wlan0
.
Ethernet configuration
For the following Ethernet configuration examples, we will assume that you are using Ethernet device eth0
.
DHCP configuration
The DHCP configuration with Busybox ifupdown syntax is as follows:
Contents of /etc/network/interfaces
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
For a complete list of command line options for udhcpc, see this document.
With ifupdown-ng, IPv4 DHCP configuration given on this page will also result in the use of DHCPv6, if dhcpcd is installed as dhcpcd can interact with both DHCPv4 and DHCPv6 from the same process.
A basic configuration for a desktop computer using the ifupdown-ng syntax appears as follows:
Contents of /etc/network/interfaces
All further configuration below assumes ifupdown-ng being used, unless stated otherwise.
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
Static address configuration
iface eth0 inet static
instead of iface eth0
and use below address format for IPv4 instead of 203.0.113.2/24 :Contents of /etc/network/interfaces
Add the following to the file /etc/network/interfaces:
Contents of /etc/network/interfaces
Multiple address
Contents of /etc/network/interfaces
Dual-stack configuration
This example shows a dual-stack configuration.
Contents of /etc/network/interfaces
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
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:
- Ifupdown-ng Basic networking Device Manager in Alpine Linux
- NetworkManager - Alternate Front-end to Networking
- VLAN setup
- Bonding setup
- Network bridge setup
- udhcpc configuration
- wpa_supplicant - Default wifi daemon
- iwd - An alternate wifi daemon