Skip to content

Instantly share code, notes, and snippets.

@utaani
Created Mar 22, 2012
Embed
What would you like to do?
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