dracoblue.net

Configure hostname and failover ip on ubuntu

If you want to configure two ubuntu nodes in such way, that the second node is a hot standby for the other one, you will need a failover ip.

First of all, set a proper hostname for your machine by editing the /etc/hostname file. Afterwards your machine needs to be rebooted or you call sudo hostname myhostname.example.org.

Since it's still necessary to have both nodes accessible, I use the following steps to make the failover ip available on both devices.

On both machines the /etc/network/interfaces file looked for example like this (working with ip 203.0.113.220):

# Loopback device:
auto lo
iface lo inet loopback

# device: eth0
auto  eth0
iface eth0 inet static
  address   203.0.113.220
  broadcast 203.0.113.255
  netmask   255.255.255.192
  gateway   203.0.113.193
  # default route to access subnet
  up route add -net 203.0.113.192 netmask 255.255.255.192 gw 203.0.113.193 eth0

at the end, I appended (for failover ip 203.0.113.209):

allow-hotplug eth0:1
iface eth0:1 inet static
  address   203.0.113.209
  broadcast 203.0.113.209
  netmask   255.255.255.255
  gateway   203.0.113.209

So far the interface should not be visible, if you query for the inet interfaces:

# ip -f inet addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 203.0.113.220/26 brd 203.0.113.255 scope global eth0

If you want to bring up the alias eth0:1, use:

# ifup eth0:1
RTNETLINK answers: File exists
Failed to bring up eth0:1.

The error messages are miss-leading, it worked already:

# ip -f inet addr show
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN
    inet 127.0.0.1/8 scope host lo
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 203.0.113.220/26 brd 203.0.113.255 scope global eth0
    inet 203.0.113.209/32 brd 203.0.113.209 scope global eth0:1

If you try to use ifconfig eth0:1 up to bring it up, it will fail with: SIOCSIFFLAGS: Cannot assign requested address.

If you want to shutdown the interface again, use:

# ifconfig eth0:1 down

If you try to use ifdown eth0:1 to bring it down, it will fail with: ifdown: interface eth0:1 not configured.

In open source, ubuntu by
@ 22 Dec 2013, Comments at Reddit & Hackernews

Give something back

Were my blog posts useful to you? If you want to give back, support one of these charities, too!

Report hate in social media Campact e.V. With our technology and your help, we protect the oceans from plastic waste. Gesellschaft fur Freiheitsrechte e. V. The civil eye in the mediterranean

Recent Dev-Articles

Read recently

Recent Files

About