Created
December 19, 2017 20:57
-
-
Save kaspernissen/473806621f76c81abd07cd801b686cfa to your computer and use it in GitHub Desktop.
Script for configuring hostname and static ip of rasbian
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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