Configure Networking
Do not follow instructions here until this notice is removed. |
This page will assist you in setting up basic networking on Alpine Linux.
Setting System Hostname
To set the system hostname, do something like the following:
echo "hostname.domain.com" > /etc/hostname
To activate the change, do the following:
hostname -F /etc/hostname
It's also a good idea to add the hostname to the /etc/hosts file, e.g.:
127.0.0.1 localhost.localdomain localhost 192.168.1.150 hostname.domain.com hostname
Where:
192.168.1.150is the static IP address (IPv4) of the Alpine Linux machine.hostname.domain.comis the FQDN (hostname) we set above.hostnameis the just the host portion from the FQDN we set above.
Configuring DNS
For simple DNS resolution, do something like the following:
echo "nameserver 8.8.8.8" > /etc/resolv.conf echo "nameserver 8.8.4.4" >> /etc/resolv.conf
The above example uses Google's Public DNS servers.
Loopback Configuration
To configure loopback, add the following to a new file /etc/network/interfaces:
auto lo iface lo inet loopback
IPv4 Configuration
DHCP (Automatic Configuration)
Static IPv4
As an example, to configure eth0 for a static IPv4 address, add the following to /etc/network/interfaces:
auto eth0
iface eth0 inet static
address 192.168.1.150
netmask 255.255.255.0
gateway 192.168.1.1
IPv6 Configuration
Loading the ipv6 Kernel Module
In order to use IPv6 on Alpine Linux, you must first load the ipv6 kernel module.
To load it manually for the first time, run:
modprobe ipv6
Now, to set it to load on boot from now on, run:
echo "ipv6" >> /etc/modules
Now you are ready to configure Alpine Linux for IPv6.
Stateless Address Autoconfiguration
Static IPv6
As an example, to configure eth0 for a static IPv6 address, add the following to /etc/network/interfaces:
iface eth0 inet6 static
address 2001:470:ffff:ff::2
netmask 64
gateway 2001:470:ffff:ff::1
Activating Changes and Testing Connectivity
Changes made to /etc/network/interfaces can be activated by running:
/etc/init.d/networking restart
If you did not get any errors, you can now test that 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 (traceroute6), you will first need to install the iputils package:
apk add iputils
Then 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
