Linux – Ifconfig eth0:x 192.198.6.x up

configurationlinuxubuntu-9.10

I typed in the following
ifconfig eth0:0 192.198.6.1 up
ifconfig eth0:1 192.198.6.2 up
ifconfig eth0:2 192.198.6.3 up

Now there were no errors for either of these commands. And when i pinged 192.168.6.1, I got the reply from that ip. So what exactly is happening here?

can anyone explain me more about what eth0:0,eth0:1etc denotes?

Does these commands above assign multiple address to same Operating System? I am using Ubuntu

If it is assigning multiple Ips to same machine, then does it mean that hosting a my-sql server for example, would be like hosting in four different machines or a same machine with multiple IP addresses?

Best Answer

It is the same machine with multiple ips, Linux is capable of mapping multiple IP addresses to a single NIC by using IP aliasing.

To set up an IP alias, for example:

ifconfig eth0:0 192.198.5.2 netmask 255.255.255.0 up

This assigns the IP address 192.198.5.2 to eth0 as the first alias (noted as eth0:0) on eth0. If you look at the output of ifconfig, you'll see the distinct IP address for eth0 and another for eth0:0.

The aliases are NetworkInterface:Number for example eth0:0, eth0:1, eth0:2 and so forth.

In some systems you can simple create the aliases file ifcfg-ethX:Y (where X is the Network Interface and Y the alias) in the directory /etc/sysconfig/network-scripts/ and it will read on boot / network restart.

The content of the file is similar to the other interface files, for example:

DEVICE=eth0
ONBOOT=yes
IPADDR="192.198.5.2"
NETMASK="255.255.255.0"

On systems that don't use these network scripts, just add the call to ifconfig directly in your startup script (usually /etc/rc.d/rc.local).