Skip to content

Instantly share code, notes, and snippets.

@c0m4r
Last active May 29, 2024 04:00
Show Gist options
  • Save c0m4r/e38d41d0e31f6adda4b4c5a88ba0a453 to your computer and use it in GitHub Desktop.
Save c0m4r/e38d41d0e31f6adda4b4c5a88ba0a453 to your computer and use it in GitHub Desktop.
Alpine Linux installation on Hetzner Cloud VPS (Arm64/IPv6-only)

Alpine Linux installation on Hetzner Cloud VPS

(Arm64/IPv6-only)

This guide describes how to install Alpine Linux on Hetzner Cloud VPS CAX ARM64 Servers with IPv6-only setup.

image

Table of contents:

Introduction

Unfortunately Hetzner forces the use of EFI boot, which makes custom installations a pain in the ass. Fortunately there are workarounds that clever people comes up with. I knew I can just write an ISO to the disk and reboot, it will boot to RAM so I can just go on with the setup. But surprisingly under EFI I wasn't able to choose a block device during installation as I always did. After some trials and errors I eventually found this: https://lemonsh.moe/blog/alpine-hetzner/. Thanks to this recipe I successfully installed Alpine on my server.

Installation

Reboot into Rescue

Get the latest VIRTUAL/aarch64 https://alpinelinux.org/downloads/ ISO

Log into the rescue SSH and write the ISO to the disk:

ssh root@xxxx:xxxx:xxxx:xxxx::1
wipefs -a /dev/sda
wget https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/aarch64/alpine-virt-3.19.0-aarch64.iso
dd if=alpine-virt-3.19.0-aarch64.iso of=/dev/sda
reboot

Open the server Console, log into root (no password required) and proceed with:

cp -r /.modloop /root
cp -r /media/sda /root
umount /.modloop /media/sda
rm /lib/modules
mv /root/.modloop/modules /lib
mv /root/sda /media
setup-alpine
  • For the DHCP part set: none
  • Confirm that you want to add network configuration manually
  • DNS domain: leave empty
  • DNS server: 2606:4700:4700::1111
  • Choose the drive: sda
  • Installation type: sys or lvmsys depending on wheter you want to use lvm or not

Post-installation

Packages

Make sure both main and community are enabled in /etc/apk/repositories:

http://dl-cdn.alpinelinux.org/alpine/v3.19/main
http://dl-cdn.alpinelinux.org/alpine/v3.19/community

To install some useful tools:

apk add bind-tools binutils curl git htop iptraf-ng lsof mc mtr nano ncdu neofetch procps p7zip rsync shadow screen sudo tcpdump unzip util-linux-misc vnstat vim wget whois xz

Network

Network configuration /etc/network//interfaces:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet6 static
	address xxxx:xxxx:xxxx:xxxx::1/64
	gateway fe80::1

SSH

sed -i 's/#ListenAddress ::/ListenAddress ::/g;' /etc/ssh/sshd_config
rc-service sshd restart

DNS

https://1.1.1.1/dns/

echo "nameserver 2606:4700:4700::1111" > /etc/resolv.conf
echo "nameserver 2606:4700:4700::1001" >> /etc/resolv.conf

Grub

Because of the EFI bullshit you'll not be able to see anything on the Console most of the time.

To get the console showing logs during boot you need to add console=tty1 boot parameter.

Edit /etc/default/grub

GRUB_CMDLINE_LINUX_DEFAULT="console=tty1 modules=sd-mod,usb-storage,ext4 rootfstype=ext4"

And then update grub:

update-grub

NTP

Edit /etc/chrony/chrony.conf

Change pool.ntp.org to 2.pool.ntp.org (the only one that resolves with IPv6). Let's also make sure that chronyd starts fast and with only IPv6 enabled.

sed -i 's/ pool.ntp.org/ 2.pool.ntp.org/g;' /etc/chrony/chrony.conf
sed -i 's/FAST_STARTUP=no/FAST_STARTUP=yes/g;' /etc/conf.d/chronyd
sed -i 's/ARGS=""/ARGS="-6"/g;' /etc/conf.d/chronyd
rc-service chronyd restart

Wait a few seconds and check if sources appear:

chronyc sources

Bash

apk add bash bash-completion
echo "PS1='[\u@\h \W]\\$ '" > /etc/profile.d/01-ps1.sh
chsh -s /bin/bash root

fail2ban

apk add fail2ban
sed -i 's/#allowipv6/allowipv6/g;' /etc/fail2ban/fail2ban.conf
rc-update add fail2ban
rc-service fail2ban start

Default SSH jails: /etc/fail2ban/jail.d/alpine-ssh.conf

ip6tables

/etc/init.d/ip6tables save
rc-update add ip6tables
rc-service ip6tables start

Rules are being saved into /etc/iptables/rules6-save

Check out some good examples here: https://gist.github.com/jirutka/3742890#file-rules-ipv6-ip6tables

NAT64

For use-cases where a specific domain doesn't resolve on IPv6 (f.e. github.com) we can use a public NAT64 service. However, we don't necessarily want all traffic being routed through that service. Therfore, we're using dnsmasq to use NAT64 only for domains we need.

apk add dnsmasq
cat <<EOF > /etc/dnsmasq.d/nat64.conf
proxy-dnssec
no-resolv
no-poll
listen-address=::1
bind-interfaces
no-hosts
# Default DNS: cloudflare
server=2606:4700:4700::1111
server=2606:4700:4700::1001
# For specific hosts use Public NAT64 service: https://nat64.net/
server=/github.com/2a00:1098:2c::1
server=/github.com/2a00:1098:2b::1
server=/github.com/2a01:4f8:c2c:123f::1
server=/api.github.com/2a00:1098:2c::1
server=/api.github.com/2a00:1098:2b::1
server=/api.github.com/2a01:4f8:c2c:123f::1
server=/objects.githubusercontent.com/2a00:1098:2c::1
server=/objects.githubusercontent.com/2a00:1098:2b::1
server=/objects.githubusercontent.com/2a01:4f8:c2c:123f::1
EOF
rc-update add dnsmasq
rc-service dnsmasq start
echo "nameserver ::1" > /etc/resolv.conf

Be aware that the public NAT64 solution isn't perfect and may slow down or not work as expected at times due to rate limiting. As an alternative, you can give the via-IPv6 service a try.

Custom stuff

Build essentials

apk add autoconf automake bison binutils build-base cargo cmake flex libtool m4 patch pkgconfig

Docker

apk add docker docker-cli-compose
rc-update add docker
rc-service docker start

See also: Docker inside IPv6-only host

nginx

OpenVPN

https://wiki.alpinelinux.org/wiki/Setting_up_a_OpenVPN_server

PHP

apk add php83-curl php83-ctype php83-fpm php83-gd php83-iconv php83-mbstring php83-openssl php83-phar

Example configuration for nginx + PHP-FPM:

cat <<EOF > /etc/php83/php-fpm.d/nginx.conf
[nginx]
user = nginx
group = nginx
listen = /run/php-fpm83/php-fpm.sock
listen.owner = nginx
listen.group = nginx
listen.mode = 0660
pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3
EOF
rc-service php-fpm83 restart

Check installed modules:

php83 -m

Minecraft Server

apk add openjdk21-jre
wget https://download.getbukkit.org/spigot/spigot-1.20.4.jar
java -Xms1G -Xmx1G -XX:+UseG1GC -Djava.net.preferIPv6Addresses=true -jar spigot-1.20.4.jar --nogui

safe-rm

https://launchpad.net/safe-rm

Safe-rm is a safety tool intended to prevent the accidental deletion of important files by placing a wrapper on top of /bin/rm, which checks the given arguments against a configurable list of exclusions for files and directories that should never be removed.

rm -rf /
safe-rm: Skipping /.

Keep in mind that we're not replacing /bin/rm by itself. We're just pointing to a different binary in /usr/local/bin. This way we will keep /bin/rm from coreutils so it can be updated or used to bypass safe-rm. You can also decide wheter you want to use /bin/rm or /bin/safe-rm depending on your use-case.

apk add cargo make wget
wget https://launchpad.net/safe-rm/trunk/1.1.0/+download/safe-rm-1.1.0.tar.gz
tar -xvf safe-rm-1.1.0.tar.gz
cd safe-rm-1.1.0
make
sudo cp target/release/safe-rm /usr/bin/
# Deploy example config
sudo echo "/" | sudo tee /etc/safe-rm.conf
sudo ls -1 / | sed 's/^/\//g;' | sudo tee -a /etc/safe-rm.conf
sudo ln -s /usr/bin/safe-rm /usr/local/bin/rm

OSSEC

apk add linux-headers bsd-compat-headers openssl-dev libevent-dev inotify-tools-dev findutils file zlib-dev pcre2-dev geoip-dev
wget https://github.com/ossec/ossec-hids/archive/3.7.0.tar.gz
tar xvf 3.7.0.tar.gz
cd ossec-hids-3.7.0
wget -O musl_lack_of_a_out_h.patch https://git.alpinelinux.org/aports/plain/community/ossec-hids-agent/musl_lack_of_a_out_h.patch?h=3.19-stable
patch src/rootcheck/os_string.c < musl_lack_of_a_out_h.patch
mkdir src/headers/asm
wget -O src/headers/asm/a.out.h https://raw.githubusercontent.com/torvalds/linux/master/arch/x86/include/uapi/asm/a.out.h
wget -O src/headers/a.out.h https://raw.githubusercontent.com/torvalds/linux/master/include/uapi/linux/a.out.h
USE_GEOIP=yes USE_INOTIFY=yes USE_SYSTEMD=no ./install.sh
/var/ossec/bin/ossec-control stop
rc-update add ossec
rc-service ossec start
ln -s /var/ossec/logs /var/log/ossec
ln -s /var/ossec/etc /etc/ossec

False positives

In Alpine many system utilities like ls, ps, df etc. are busybox symlinks. This will trigger many false positives due to the /var/ossec/etc/shared/rootkit_trojans.txt entries. You can either comment out individual lines or disable this check in /var/ossec/etc/ossec.conf.

  <rootcheck>
    <!--<rootkit_trojans>/var/ossec/etc/shared/rootkit_trojans.txt</rootkit_trojans>-->

Anti-malware

Consider paranoya - Simple IOC and YARA scanner

GRUB Fallout Theme

https://github.com/shvchk/fallout-grub-theme

image

mkdir /usr/share/grub/themes
cd /usr/share/grub/themes
git clone https://github.com/shvchk/fallout-grub-theme.git
rm /usr/share/grub/themes/fallout-grub-theme/install.sh
cd /usr/share/grub/themes/fallout-grub-theme/icons
echo -n 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAAHk3pUWHRSYXcgcHJvZmlsZSB0eXBlIGV4aWYAAHjarV
hbciQpDPznFHsEJBCP4/BSxN5gj78pqO6ptnvG49ntCpsyTYGkVKZUduufv9X9hQ+nEF2UXFJNyeMTa6zccFP8j8+6xuq92n3ED
11z9FxF7uWLxx3hejfPGAPGcCaf5wXbKNweSM+R3s2TfJgPz2P4xaLy2Ihx3eb7Msdun/LjR3UWhc/OVscWE+KTLqceruw7LOwI
TNiPJVwZP4L7vK+Kq/jmh6Popx++4xpUiSl4pUiTGimtPQ4aMDHy4oyReXDYcyVkrjyCDwTUQgyRlHOoYYYSOAxeIWCWn7bQPrf
u4wYVHDwJK5mwGeGJfbnHzX+93m6kOixEBO8fsYJdzAYDWRSD/cYqAEL6yCPZAX5cHz8AFptErLIwFzjYfD9bdKEfuRXcBjpgoW
CM5+E8rw0QIpwtMIYCEPCJglAin5kzEeJYgE+D5Rxc5A4ISIQnrOQYQgI4he1sPJNpr2XhMw0KAQgJKWRAU0MDVjFKTC7mWJBDT
YJEEUmSpUiVlkKKSVJKORkXWw45Zskp51xyza2EEouUVHIppZbmKtcArkpNNddSa20Nhzbs3PB0Kw0TnXvosUtPPffSa28D6TPi
kJFGHmXU0dzkGWacMtPMs8w626KFVFpxyUorr7LqaopU06BRRZNmL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8zr
UOQXDU0zlP4yat4BHET2GOhXc/ZHFu+8Sxs0mbewV+vdtpujjUdA3Qd+Ylaigkhv3NScEoRlgRfQaQgMipxl5wsOsuRcxuxG9DB
jUrAYbZGBvJWk/GiL7vkHkOzB19NcUUtRyHXgP9B3g+qxKCs0VEM07gtjeOCYMvIv625ksnmbt11uxaftBmlFGEmpcfU1gduP/L
IOfy06hvh5wDzFQFSDwyRjGPYrYVmA6FgLbSzTvyI20u0F1/HyEhi0jII8DEwgXwTOkhbdgIkdBLKgL8hBQPCOoq0C2IV6U/MEc
xBaC2Q/yAA1b/0KdjcD9IJtBLaIvsemD75Nfx/1P3g7+E6ipiCu+CuIHzYn3gXEQH3Bbkh4RBgmD5sVEAeilOD4P8CH2DExVE2g
bT9oHHDUTHjQqlAF3AHfOyCFJUtsz97KB7MR/kg0zFldEafRhJtz5OqFbFLSorwto+xemrzbU1+UWBe2Cd4EWN40iXke816+QaQ
/idWhx0+jirmMz1QV0ApMr4H0S6IxzLnIeKGyPILYT6J7TSJY6mEI3YjspbI8sbSJKv/oT0AGElyEgDHTEuZY4kq0/5yEEEXsh9
aHfdiMEWX/OS/1d0PdMOeK1pjaWU02g+exCIOfmUXS+QrzC1DLAidx6+/3v7W+fA3Pc/AlGTAAAAABJRU5ErkJggg==' \
  | base64 -d > alpine.png
mv gnu-linux.png gnu-linux.png.bak
ln -s alpine.png gnu-linux.png
echo "GRUB_THEME=/usr/share/grub/themes/fallout-grub-theme/theme.txt" >> /etc/default/grub
update-grub

icon mirror1 mirror2 mirror3


If you found this article helpful, please consider making a donation to a charity on my behalf. Thank you.

Enojy your Alpine Linux adventure!

Image source: Mont Blanc oct 2004.JPG

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment