Sean O'Donnell

Code Snippets

Contact

Sean O'Donnell
South Pasadena, CA
sean@seanodonnell.com

Configuring Multiple IP Addresses on a single Network Interface Card (NIC)

Category: Unix/Linux
Author: Sean O'Donnell
Thu, Feb. 20th, 2003 @ 2:20:22 (MST)

There are many logical and justifiable purposes for utilizing open source software on your current hardware resources, rather than buying expensive proprietary products to essentially provide with what you already have (but aren't utilizing). This is an endless decision process, and mostly subjective to your project, budget, and many other factors that I won't acknowledge, or disacknowledge, but you're here now, so you're obviously a DIY kinda guy/gal, and that is more fun, and often logical, if you ask me.

Virtual Network Adapters are most advantageous for development of Linux/Apache-based Web Applications on a local workstations/laptops (for example), and configuring multiple projects/web sites to specific virtual host addresses, in your local workspace or LAN staging area. There are also many other types of applications that require the use of 'virtual' network adapters, such as "Virtualization Software" (i.e. Xen, VMware, OpenVZ, etc.), or network appliances that utilize embedded linux kernel ip routing matrices, such as Firewalls, Routers, and Ethernet Switches.

To assign Multiple IP addresses to eth1, we would modify the Interface Configuration (ifconfig), as seen below...

#!/usr/bin/env bash 
#
# Assign the initial 'physical' address of the NIC
ifconfig eth1 192.168.1.1 netmask 255.255.255.0 &
ifconfig eth1 up

# assign 192.168.1.11 to eth1:1
ifconfig eth1:1 192.168.1.11 netmask 255.255.255.0 &
ifconfig eth1:1 up

# assign 192.168.1.12 to eth1:2
ifconfig eth1:2 192.168.1.12 netmask 255.255.255.0 &
ifconfig eth1:2 up

# assign 192.168.1.13 to eth1:3
ifconfig eth1:3 192.168.1.13 netmask 255.255.255.0 &
ifconfig eth1:3 up

Now you will be able to access the same NIC from any of the following IP Addresses (Locally, within your own LAN)...

  • 192.168.1.1
  • 192.168.1.11
  • 192.168.1.12
  • 192.168.1.13

Copyleft (<) 1998-2014 www.seanodonnell.com