Created
August 3, 2017 11:56
-
-
Save deathbybandaid/f02e4aa3104ae9ae0e59ebc56cf8a1cf to your computer and use it in GitHub Desktop.
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 | |
## eth0 raspbian static | |
## Current IP | |
OLDETH_IP=`ip addr show eth0 | grep "inet\b" | awk '{print $2}' | cut -d/ -f1` | |
## Current Gateway | |
OLDETH_GATEWAY=`ip route show 0.0.0.0/0 dev eth0 | cut -d\ -f3` | |
## NEW IP | |
NEWETH_IP=$(whiptail --inputbox "Please enter desired IP for eth0" 10 80 "$OLDETH_IP" 3>&1 1>&2 2>&3) | |
## Cleanup | |
sudo sed -i '/#eth0/d' /etc/dhcpcd.conf | |
sudo sed -i '/interface eth0/d' /etc/dhcpcd.conf | |
sudo sed -i '/static ip_address=$OLDETH_IP/d' /etc/dhcpcd.conf | |
sudo sed -i '/static routers=$OLDETH_GATEWAY/d' /etc/dhcpcd.conf | |
sudo sed -i '/static domain_name_servers=$OLDETH_GATEWAY/d' /etc/dhcpcd.conf | |
## Add New info to dhcpcd | |
sudo echo "" | sudo tee --append /etc/dhcpcd.conf | |
sudo echo "#eth0" | sudo tee --append /etc/dhcpcd.conf | |
sudo echo "interface eth0" | sudo tee --append /etc/dhcpcd.conf | |
sudo echo "static ip_address=$NEWETH_IP" | sudo tee --append /etc/dhcpcd.conf | |
sudo echo "static routers=$OLDETH_GATEWAY" | sudo tee --append /etc/dhcpcd.conf | |
sudo echo "static domain_name_servers=$OLDETH_GATEWAY" | sudo tee --append /etc/dhcpcd.conf | |
## Make the change | |
sudo ifconfig eth0 $NEWETH_IP |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment