Create a permanent virtual IP address in Linux

Create a permanent virtual IP address in Linux

Category : How-to

Get Social!

In a previous post, we saw how to create a virtual IP address, based on an existing network interface. The trouble with this method is that the virtual IP address will vanish when you reboot your machine.

On option is to attach the script to the network up and down scripts however there is a much easier way!

In Debian/ Ubuntu you simply create a new, virtual interface in the interfaces file.

vi /etc/network/interfaces

And add a network interface, based on an existing interface. The below example is a virtual IP based on eth0 – note if this is your second virtual IP you would use eth0:2, and so on.

auto eth0:1
iface eth0:1 inet static
address 192.168.100.9
netmask 255.255.255.0
network 192.168.100.0
broadcast 192.168.100.255

You will need to change the IP addresses to match your network. Notice there is no gateway – usually you can only have one gateway per machine.

Restart networking for the changes to take effect.


Create a Virtual IP Address in Linux

Category : How-to

Get Social!

terminal ifconfigThis post will detail how to set ip a virtual IP address and assign an interface to handle the traffic in the Linux OS. This may not work for all Linux distros but it should be accurate for most.

Run the ifconfig command to see what interfaces are available.

ifconfig

Run the ifconfig command again, however this time create a VIP using the following syntax.

ifconfig [INTERFACE] [IP_ADDRESS] netmask [NETMASK]

Example:

ifconfig eth0:1 192.168.50.53 netmask 255.255.255.0

Substitute INTERFACE = the interface which this VIP will be based on, IP_ADDRESS = the new VIP IP address (note: this must exist) and NETMASK = the netmask of the new VIP.

Update the routing table using arping.

arping -q -U -c 3 -I [INTERFACE] [VIP_IP_ADDRESS]

Example:

arping -q -U -c 3 -I eth0 192.168.50.51

Substitute INTERFACE with the interface to bind this VIP to and VIP_IP_ADDRESS to the VIP IP address which was assigned in the above ifconfig statement.

Note: changes made will be lost when the machine is rebooted.

See this blog post to see how to make a permanent virtual IP address.


Visit our advertisers

Quick Poll

Are you using Docker.io?

Visit our advertisers