2

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?

2
  • 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
8

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

sudo ip addr add 169.254.169.254/16 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

NOTE: According to the current version of this documentation page from AWS the metadata service IP is a link-local address and it points to the Wikipedia article about it. In turn that page points to RFC3927 where it reads:

The IPv4 prefix 169.254/16 is registered with the IANA for this purpose.

2
  • 1
    Shouldn't this be /16? I just saw at serverfault.com/questions/427018/… references that say it's a 16-bit network and should not be subnetted. – Tom Hundt Oct 1 '19 at 22:03
  • Thanks for the tip @TomHundt, I've updated the reply. There's no way to know for sure if AWS is following the RFC, as they technically could do something different, but I'm using the documentation as reference to assume they are. Thanks again! – Sebastian Cruz Feb 3 '20 at 22:54
2

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 !

2
  • Unfortunately, this is exactly what I was doing and what was working but now isn't. – mattdm Apr 28 '13 at 14:32
  • 1
    As I said above, shouldn't this be a /16 network (so, netmask 255.255.0.0)? – Tom Hundt Oct 1 '19 at 22:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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