Skip to content

Instantly share code, notes, and snippets.

@kaspernissen
Created December 19, 2017 20:57
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save kaspernissen/473806621f76c81abd07cd801b686cfa to your computer and use it in GitHub Desktop.
Save kaspernissen/473806621f76c81abd07cd801b686cfa to your computer and use it in GitHub Desktop.
Script for configuring hostname and static ip of rasbian
#!/bin/sh
hostname=$1
ip=$2 # should be of format: 192.168.1.100
dns=$3 # should be of format: 192.168.1.1
# Change the hostname
sudo hostnamectl --transient set-hostname $hostname
sudo hostnamectl --static set-hostname $hostname
sudo hostnamectl --pretty set-hostname $hostname
sudo sed -i s/raspberrypi/$hostname/g /etc/hosts
# Set the static ip
sudo cat <<EOT >> /etc/dhcpcd.conf
interface eth0
static ip_address=$ip/24
static routers=$dns
static domain_name_servers=$dns
EOT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment