0

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?

3 Answers 3

2

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).

1
  • The method using the ifcfg-ethX:Y files is prevalent under RedHat based systems (e.g. Fedora, CentOS, etc). Under Debian based systems (e.g. Ubuntu), you would use entries in the /etc/network/interfaces file.
    – wolfgangsz
    Sep 12, 2010 at 9:32
0

In reference to your mysql question. Both. Depending on how you configure it, you can have mysql listen to all 4 IP address, or just one.

Most daemons have an option to select what interface you want them to listen on.

0

(In addition to Prix' reply:) The method using the ifcfg-ethX:Y files is prevalent under RedHat based systems (e.g. Fedora, CentOS, etc). Under Debian based systems (e.g. Ubuntu), you would use entries in the /etc/network/interfaces file. Plus: Your device identifier needs to specify the virtual interface. Example:

iface eth0 inet static
  address 192.168.6.1
  netmask 255.255.255.0
  gateway 192.168.6.254

iface eth0:1 inet static
  address 192.168.6.2
  netmask 255.255.255.0

iface eth0:2 inet static
  address 192.168.6.3
  netmask 255.255.255.0

If you use this to bring up the additional addresses, do NOT add lines for gateways, as you will end up with multiple default routes, which can confuse the hell out of your routing engine.

2
  • Do i have to add the above to the /etc/networks file in-order to make these IP assignments persistent when I restart?
    – user54016
    Sep 12, 2010 at 17:39
  • Yes. There are a few other options possible, too. For example you write a small script containing the commands in your original post and have the script executed when the main interface goes up or down. Read the man page for interfaces for more details.
    – wolfgangsz
    Sep 12, 2010 at 18:05

You must log in to answer this question.