Created
October 30, 2011 08:22
-
-
Save kazu634/1325704 to your computer and use it in GitHub Desktop.
Get the IP address the DHCP server assigns and make it a static one for Ubuntu
This file contains 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/bash | |
# Set the LANG to C | |
LANG=C | |
# Acquiring the IP address | |
echo "[`date '+%Y/%m/%d %H:%M:%S'`] Acquiring the IP address." >> /tmp/static_ip.log | |
IP=`/sbin/ifconfig eth0 | grep 'inet addr' | awk '{print $2;}' | cut -f2 -d':'` | |
echo "[`date '+%Y/%m/%d %H:%M:%S'`] IP address is: $IP" >> /tmp/static_ip.log | |
# Back up the /etc/network/interfaces | |
echo "[`date '+%Y/%m/%d %H:%M:%S'`] Back up the /etc/network/interfaces." >> /tmp/static_ip.log | |
/bin/mv /etc/network/interfaces /etc/network/interfaces.`date '+%Y%m%d%H%M%S'` | |
# Generating the interfaces file: | |
echo "[`date '+%Y/%m/%d %H:%M:%S'`] Generating the /etc/network/interfaces file." >> /tmp/static_ip.log | |
echo "# Generating the interfaces file" >> /etc/network/interfaces | |
echo "# This file describes the network interfaces available on your system" >> /etc/network/interfaces | |
echo "# and how to activate them. For more information, see interfaces(5)." >> /etc/network/interfaces | |
echo "" >> /etc/network/interfaces | |
echo "# The loopback network interface" >> /etc/network/interfaces | |
echo "auto lo" >> /etc/network/interfaces | |
echo "iface lo inet loopback" >> /etc/network/interfaces | |
echo "" >> /etc/network/interfaces | |
echo "# The primary network interface" >> /etc/network/interfaces | |
echo "auto eth0" >> /etc/network/interfaces | |
echo "iface eth0 inet static" >> /etc/network/interfaces | |
echo " address $IP" >> /etc/network/interfaces | |
echo " netmask 255.255.255.0" >> /etc/network/interfaces | |
echo " network 192.168.11.0" >> /etc/network/interfaces | |
echo " broadcast 192.168.11.255" >> /etc/network/interfaces | |
echo " gateway 192.168.11.1" >> /etc/network/interfaces | |
echo "[`date '+%Y/%m/%d %H:%M:%S'`] Finished generating the /etc/network/interfaces file." >> /tmp/static_ip.log |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment