From 199144feaf24dcfe66d3562bf6e42c802718f273 Mon Sep 17 00:00:00 2001 From: Graham Helton Date: Sat, 8 Apr 2023 15:23:31 -0400 Subject: [PATCH] Initial Commit --- README.md | 5 +++++ setnet.sh | 26 ++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 README.md create mode 100755 setnet.sh diff --git a/README.md b/README.md new file mode 100644 index 0000000..5fc82e7 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +# SetNet +A quick tool for automatically setting a static IP on an ubuntu machine using the `netplan` command. + +# Usage +Set the IP for your gateway and DNS server inside the `setnet.sh`. SetNet will then grab the IP your ubuntu machine is currently using and set up a file in `/etc/netplan/` called `1-network-manager-all.yaml` with the configuration needed to assign your current IP as a static IP. It then runs `sudo netplan apply` to apply the changes. diff --git a/setnet.sh b/setnet.sh new file mode 100755 index 0000000..6ef1a78 --- /dev/null +++ b/setnet.sh @@ -0,0 +1,26 @@ +#!/bin/bash +PURPLE=`tput setaf 5` +GREEN=`tput setaf 2` +BLUE=`tput setaf 4` +RED=`tput setaf 1` + +address=$(ip a | grep "2: " -A 2 | grep inet | awk '{print $2}') +dns="your.dns.server.ip" +gateway="your.gateway.ip" + +echo -e $BLUE"Creating$PURPLE /etc/netplan/1-network-manager-all.yaml with the following settings$BLUE" +echo "network: + version: 2 + ethernets: + eth0: + dhcp4: no + addresses: [$address] + gateway4: $gateway + nameservers: + addresses: [$dns]" | tee /etc/netplan/1-network-manager-all.yaml + + + +echo -e $GREEN"Applying Netplan settings" +sudo netplan apply +