Skip to content

Instantly share code, notes, and snippets.

@utaani
Created March 22, 2012 23:14
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utaani/2165376 to your computer and use it in GitHub Desktop.
Save utaani/2165376 to your computer and use it in GitHub Desktop.
ifconfig eth1 with fixed IP address on Amazon-VPC ENI(Elastic Network Interface)
#!/bin/sh
# set IP address with Amazon-VPC ENI(Elastic Network Interface) address and other.
# get eth0/1 MAC addresses
MACADDR0=`cat /sys/class/net/eth0/address`
MACADDR1=`cat /sys/class/net/eth1/address`
# get eth0/1 IP addresses on ENI
IPADDR0=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MACADDR0}/local-ipv4s/`;
IPADDR1=`/usr/bin/curl -s http://169.254.169.254/latest/meta-data/network/interfaces/macs/${MACADDR1}/local-ipv4s/`;
# ifconfig on eth1 (ENI)
/sbin/ifconfig eth1 inet ${IPADDR1} netmask 255.255.255.0 2>&1 >> /tmp/seteth1.log
# write hostname in /etc/hosts
SYS_HOSTNAME=`hostname`
echo "127.0.0.1 localhost localhost.localdomain" > /etc/hosts
echo "${IPADDR0} ${SYS_HOSTNAME}" >> /etc/hosts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment