reseau-ethernet.sh

Hardkernel ODROID-C2 (Amlogic S905) · File : reseau-ethernet.sh · Language : Bash · Use case : Configurer une adresse IP statique sur le port Ethernet

In a fixed installation, a static IP avoids hunting the board in the DHCP lease list. The script creates (or fixes) a manual NetworkManager profile on the Ethernet port, then pings the gateway to verify.

Hardware

An ODROID-C2 (Amlogic S905, 4 Cortex-A53, 2 GB) running Ubuntu Hardkernel or Armbian, with gigabit Ethernet and a Raspberry-Pi-compatible 40-pin header. One Ethernet cable to the router/switch.

Wiring

RJ45 cable on the board Ethernet port. Pick an address outside the DHCP range to avoid conflicts.

How it works

nmcli connection add sets ipv4.method manual with address/gateway/DNS; connection up applies it. The control ping validates layer 3 immediately.

Running it

On Ubuntu Hardkernel or Armbian: apt install gpiod python3-gpiod; locate the header chip with gpiodetect (usually gpiochip1 on Amlogic) then gpioinfo.

Variants

Add a second DNS, a search domain (ipv4.dns-search), or flip the profile back to DHCP when moving (ipv4.method auto).

reseau-ethernet.sh

#!/bin/bash
# IP statique sur Ethernet via nmcli (plus propre que ifconfig a la main).
# Usage : ./reseau-ethernet.sh 192.168.1.50/24 192.168.1.1 8.8.8.8

set -e
IP="${1:?Usage: $0 IP/prefixe passerelle DNS [interface]}"
PASSERELLE="${2:?passerelle requise}"
DNS="${3:?DNS requis}"

echo "== Interfaces =="
ip -brief link

DEV="${4:-$(ip -brief link | awk '$2=="up" && $1!~"lo|wl"{print $1; exit}')}"
[ -n "$DEV" ] || { echo "aucune interface up"; exit 1; }

echo "== Profil statique sur $DEV =="
nmcli connection add type ethernet con-name statique-$DEV ifname "$DEV" \
  ipv4.method manual ipv4.addresses "$IP" \
  ipv4.gateway "$PASSERELLE" ipv4.dns "$DNS" || \
nmcli connection modify statique-$DEV \
  ipv4.addresses "$IP" ipv4.gateway "$PASSERELLE" ipv4.dns "$DNS"

nmcli connection up statique-$DEV

echo "== Resultat =="
ip -4 -brief addr show "$DEV"
ping -c 2 -W 2 "$PASSERELLE" && echo "passerelle joignable"

← Back to the board