Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to emulate the Amazon EC2 metadata service on my local system for testing. In EC2, this runs on 169.254.169.254. I understand that this is the designated range for pseudorandom local addresses on DHCP failure, but Amazon in their wisdom are also using it for this purpose, so I need to do the same thing.

I'm using F19 Alpha. In earlier Fedora, I could simply make a virtual interface on the loopback device, like lo:0 and assign that a static address using the normal ifcfg- scripts. Now, that fails with "Error: Connection activation failed: Device not managed by NetworkManager or unavailable".

(I'm running NetworkManager, but previously I was doing this underneath it.)

Is finding some way to continue what I was doing with lo:0 the right approach (and if so, how?), or is there a better way?

share|improve this question
    
Couldn't you do this with netfilter/iptables? Like NAT back to 127.0.0.1? – goldilocks Apr 26 '13 at 20:26
    
@goldilocks why fake it when you can do it for real? ;) – Tim Apr 26 '13 at 20:59

Haven't used Fedora in a while, but it should still be very similar to CentOS. I did this on CentOS 6.

Copy /etc/sysconfig/network-scripts/ifcfg-lo to /etc/sysconfig/network-scripts/ifcfg-lo:1

Your new config should look like so:

DEVICE=lo:1
IPADDR=169.254.169.254
NETMASK=255.0.0.0
ONBOOT=yes
NAME=loopback1

Restart the network service service network restart.

Bonne chance mon ami !

share|improve this answer
    
Unfortunately, this is exactly what I was doing and what was working but now isn't. – mattdm Apr 28 '13 at 14:32

To answer your specific question, you can use iproute2 to assign the IP address like this:

sudo ip addr add 169.254.169.254/8 dev lo

It will just add a new IP to the interface, no need for aliasing with :0, :1, etc. Note this is going to be lost after a reboot.

And to quickly emulate the metadata service you can use netcat like this:

while true; do sudo nc -l 169.254.169.254 80 <<< '"region" : "eu-west-1"'; test $? != 0 && break; done

This will give you the region when asking like this:

curl -s http://169.254.169.254/latest/dynamic/instance-identity/document
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.