Configure static IP address using systemd on Arch for Raspberry Pi

There are many ways to configure the network on linux. If you are using a headless Rpi, you won’t need any network manager at all, you can use the systemd itself, hence, you will save space and resources.

So, I will extract the following information directly from Arch Linux Wiki.

Persistent configuration on boot using systemd

First create a configuration file for the systemd service

/etc/conf.d/net-conf-eth0

Fill the following information with your network settings.

address=192.168.1.2
netmask=24
broadcast=192.168.1.255
gateway=192.168.1.1

Create a network start script:

/usr/local/bin/net-up.sh
#!/bin/bash
ip link set dev "$1" up
ip addr add ${address}/${netmask} broadcast ${broadcast} dev "$1"

[[ -z ${gateway} ]] || { 
  ip route add default via ${gateway}
}

Network stop script:

/usr/local/bin/net-down.sh
#!/bin/bash
ip addr flush dev "$1"
ip route flush dev "$1"
ip link set dev "$1" down

Make both scripts executable:

# chmod +x /usr/local/bin/net-{up,down}.sh

systemd service file:

/etc/systemd/system/network@.service
[Unit]
Description=Network connectivity (%i)
Wants=network.target
Before=network.target
BindsTo=sys-subsystem-net-devices-%i.device
After=sys-subsystem-net-devices-%i.device

[Service]
Type=oneshot
RemainAfterExit=yes
EnvironmentFile=/etc/conf.d/net-conf-%i
ExecStart=/usr/local/bin/net-up.sh %i
ExecStop=/usr/local/bin/net-down.sh %i

[Install]
WantedBy=multi-user.target

Enable and start the unit network@eth0, passing your name of the interface.

systemctl enable network@eth0.service
systemctl start network@eth0.service

Oh, don’t forget either to put, if there aren’t yet, your DNS on

/etc/resolv.conf
nameserver 208.67.222.222
nameserver 208.67.220.220

 

 

Anuncios

Configuring no-ip dynamic DNS service on Arch Linux ARM

Installation

We will first need to have yaourt installed, so if you don’t have yet, let’s install it.

curl -O https://aur.archlinux.org/packages/pa/package-query/package-query.tar.gz
tar zxvf package-query.tar.gz
cd package-query
makepkg -si
cd ..
curl -O https://aur.archlinux.org/packages/ya/yaourt/yaourt.tar.gz
tar zxvf yaourt.tar.gz
cd yaourt
makepkg -si
cd ..

Once installed, we can install no-ip dynamic updater.

# yaourt noip
==> WARNING: Building package as root is dangerous.
 Please run yaourt as a non-privileged user.
1 aur/guide 1.0.2-1 (0)
    The official IDE for the Chinese NOI/NOIP
2 aur/noip 2.1.9-6 (4)
    Dynamic DNS Client Updater for no-ip.com services
==> Enter n° of packages to be installed (ex: 1 2 3 or 1-3)
==> --------------------------------------------------------
==> 2

We will select the proper option (2, at the moment of writing), and we’ll need to edit PKGBUILD with our editor.

==> Downloading noip PKGBUILD from AUR...
x .AURINFO
x noip.service
x noip.install
x PKGBUILD
Comment by xyproto  (2014-08-01 09:29)
Moved from [community]. See aur-general for more information.

noip 2.1.9-6  (Fri Aug  1 11:28:49 CEST 2014)
( Unsupported package: Potentially dangerous ! )
==> Edit PKGBUILD ? [Y/n] ("A" to abort)
==> ------------------------------------
==> Y

Please add $EDITOR to your environment variables
for example:
export EDITOR="vim" (in ~/.bashrc)
(replace vim with your favorite editor)

==> Edit PKGBUILD with:  nano

On the PKGBUILD, we’ll add the raspberry pi platofrm, armv6h, as shown here.

arch=('x86_64' 'i686' 'armv6h')

We’ll save (in nano we’ll do it with Ctrl + X) and we’ll answer with ‘Yes’ the rest of questions yaourt ask to us to be done.

Configuration

To configure de No-IP DUC you have to execute the noip2 executable with -C option (create the configuration file step by step), or if you want to select all hosts in your account to be updated add the -Y option.

# noip2 -C

To see more options off the No-IP DUC use:

# noip2 -h

To start the service

Start the service with

# systemctl start noip2

To start automatically at boot simply do:

# systemctl enable noip2

Raspberry Pi Optimization Guide

Let’s get some more RAM

Reduce the GPU RAM

If you pretend to use your Raspberry Pi as a headless server, you can safely reduce the amount of RAM dedicated to the GPU, the values proposed here are suposed to be safe.

1. We’ll modify the file /boot/config.txt depending the Raspberry Pi model we have, most probably model B or B+, but the value to set a lower and safe GPU RAM is the same for both: 64MB

WARNING! If we set a too low value to GPU RAM (i.e: under 16MB), Rasberry wouldn’t boot and we’ll need to set back the value by inserting the SD card in a computer to regenerate the file /boot/config.txt
gpu_mem_512=64

Swap area creation

As the installation method does not set a swap partition, we can create a swap file. Swap is not very useful on desktop PCs, but this little computer has only 512MB, and if we pretend to run some servers as I do, may be useful to have some swap space, in order to avoid hangs if RAM gets exhausted.

1. So first we’ll create a file we’ll use as swap space and we’ll assign to it a size of 512 MB

# fallocate -l 512M /swap/swapfile

2. We’ll assign the proper permissions

# chmod 600 /swap/swapfile

3. We’ll format as swap

# mkswap /swap/swapfile

3. And activate it with

# swapon /swap/swapfile

4. To automatically mount at boot, we’ll add the following line to  /etc/fstab

/swap/swapfile none swap defaults 0 0

5. Finally, we’ll set the swappiness to use swap only when we get out of RAM. So we’ll edit /etc/sysctl.d/99-sysctl.conf and add this line

vm.swappiness=10

6. Finish, we can see the results with the command free -h

[root@alarmpi ~]# free -h
              total        used        free      shared  buff/cache   available
Mem:           434M         68M         46M         39M        318M        307M
Swap:          511M          0B        511M
[root@alarmpi ~]#

I need more horseponypower!! (Overclocking)

If you need more power in your Rpi, you can easily overclok some settings on boot time.

There are five overclocking presets, you must bare in mind to buy some heatsinks, they are cheap, from 2-5€ the whole kit and they will help to prolong the live of your Rpi if you’re playing with voltages. And, why not? You can buy some anyway, it won’t hurt the Rpi.

rpidisipadores

  • None (Rpi’s default)
  • Modest, which can be set fairly safe without need of heatsinks.
  • Medium, which can be set also without need of heatsinks, but I would recommend to use them.
  • High and Turbo: those two methods sets and important over voltage, so heatsink is needed if you don’t want to reduce the live of your Rpi.

Take a look sometimes to the temperature of your Rpi, and adjust the settings to have it as cooler as possible. Firts of all, before overclocking, watch its temperature to have a starting point.

[root@alarmpi ~]# /opt/vc/bin/vcgencmd measure_temp
temp=44.9'C

To set the desired mode, we’ll edit  /boot/config.txt and we’ll uncomment some of the overclock options as shown in the example below, where I set Modest preset.

##Modest
arm_freq=800
core_freq=300
sdram_freq=400
over_voltage=0
##Medium
#arm_freq=900
#core_freq=333
#sdram_freq=450
#over_voltage=2
##High
#arm_freq=950
#core_freq=450
#sdram_freq=450
#over_voltage=6
##Turbo
#arm_freq=1000
#core_freq=500
#sdram_freq=500
#over_voltage=6