Created
November 26, 2011 10:19
-
-
Save yssk22r/1395420 to your computer and use it in GitHub Desktop.
Automatic Network Configuration based on MAC address.
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/bash | |
| hwaddr=$(ifconfig -a | grep HWaddr | awk '{print $5}') | |
| echo "Update /etc/udev/rules.d/70-persistent-net.rules" | |
| cat <<-EOS > /etc/udev/rules.d/70-persistent-net.rules | |
| SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="${hwaddr}", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0" | |
| EOS | |
| echo "Update hostname and ipaddress" | |
| host=$(echo $hwaddr | awk -F: '{print $6}' | tr '[a-z]' '[A-Z]') | |
| ip=$(echo 16i $host p | dc) | |
| hostname="vm-$ip" | |
| echo "$hostname" > /etc/hostname | |
| cat <<-EOS > /etc/hosts | |
| 127.0.0.1 localhost ${hostname} | |
| 127.0.1.1 ${hostname} | |
| EOS | |
| cat <<-EOS > /etc/network/interfaces | |
| # The loopback network interface | |
| auto lo | |
| iface lo inet loopback | |
| # The primary network interface | |
| auto eth0 | |
| iface eth0 inet static | |
| address 192.168.1.${ip} | |
| netmask 255.255.255.0 | |
| gateway 192.168.1.1 | |
| dns-nameservers 192.168.1.32 8.8.8.8 | |
| broadcast 192.168.1.255 | |
| EOS | |
| echo "Update finished. Please reboot the server" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment