HowTo: Creating virtual interfaces in solaris/Redhat/Debian

Sometimes it’s useful to create a virtual network interface on your Solaris box, so that you can associate multiple IP addresses with the same host and not have to go through all the trouble of buying another NIC.

Here’s a quick HOWTO. Let’s assume our network card is eri0, and we want to create a virtual interface called eri0:1

Create the virtual interface:

# ifconfig eri0:1 plumb

Configure the virtual interface:

# ifconfig eri0:1 179.164.83.161 netmask 255.255.255.0 broadcast 179.164.83.255

Check to make sure it worked:

# ifconfig -a

eri0:1: flags=1000842 mtu 1500 index 2

inet 179.164.83.161 netmask ffffff00 broadcast 179.164.83.255

Finally bring up your new virtual interface:

# ifconfig eri0:1 up

To make it come up on start:

create /etc/hostname.eri0:1 with hostname in it

make sure the hostname is in /etc/hosts

To Disable: ifconfig eri0:1 unplumb

In RedHat

# ifconfig eth0:1 192.168.30.128 netmask 255.255.255.0

That’s all it takes! Let’s check to make sure it took:

# ifconfig -a

You can (and should!) also give this new address its own name in the /etc/hosts file:

192.168.30.128 stationX

To make this permanent in RedHat or Mandriva, look in the directory /etc/sysconfig/network-scripts — you’ll see a file called ifcfg-eth0. Copy that file and edit it to create a new ifcfg-eth0:1 (Be sure to edit the contents of the file to give it the right address and netmask, of course.)

Now your eth0:1 interface will start automatically at reboot, just like eth0 itself. You can have as many of these “ifcfg-” files as you like, within reason.

In Debian

the file is called “/etc/network/interfaces” and is somewhat simpler:

auto eth0

iface eth0 inet static

address 172.16.0.6

netmask 255.255.255.0

auto eth0:1

iface eth0:1 inet static

address 192.168.30.128

netmask 255.255.255.0

You still have to tell the machine about the new network of which it is now a member. That’s the job of the route command:

# route add -net 192.168.30.0 netmask 255.255.255.0

# route

Cheers!!!

About these ads

2 Responses to “HowTo: Creating virtual interfaces in solaris/Redhat/Debian”

  1. felipe1982 Says:

    thanks for this. Very useful on RHEL

  2. Lucas Says:

    To make this work on Fedora 13, you need to use the following:

    # ifconfig ethx:x inet xxx.xxx.xxx.xxx netmask xxx.xxx.xxx.xxx broadcast xxx.xxx.xxx.xxx

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: