· 6 years ago · Dec 05, 2018, 01:44 AM
1#!/usr/bin/env bash
2#
3# There are many custom use cases that require
4# assigning multiple 'virtual' IP addresses to
5# a single network interface.
6#
7# One case in particular, is for developing web applications
8# locally on a workstation, to support a project that has multiple
9# sub-domains. In such a case, you would create virtual IP addresses
10# to support virtul hosts in apache/nginx. You would then associate the
11# sub-domains to the virtual IP addresses, in your /etc/hosts file.
12#
13# example:
14#
15# 192.168.1.11 mysite.net
16# 192.168.1.12 subdomain1.mysite.net
17# 192.168.1.13 subdomain2.mysite.net
18#
19# This allows you to stage network connectivity (locally) during
20# development and testing.
21#
22
23# Assign the initial 'physical' address of the NIC
24ifconfig eth1 192.168.1.1 netmask 255.255.255.0 &
25ifconfig eth1 up
26
27# assign 192.168.1.11 to eth1:1
28ifconfig eth1:1 192.168.1.11 netmask 255.255.255.0 &
29ifconfig eth1:1 up
30
31# assign 192.168.1.12 to eth1:2
32ifconfig eth1:2 192.168.1.12 netmask 255.255.255.0 &
33ifconfig eth1:2 up
34
35# assign 192.168.1.13 to eth1:3
36ifconfig eth1:3 192.168.1.13 netmask 255.255.255.0 &
37ifconfig eth1:3 up