Multiple IP on a single network interface

If you use tools like netswitcher to configure on the fly more profiles for accessing the networks from home / office / Internet Cafe you may have a look at netsh command line provided by Windows, that can do this and more weird things, like binding more IP addresses to your network interface.

For example, at home I have a WIFI access point and I don’t use DHCP. But I don’t want to expose the administration console of the access point to Internet, so I put the administration console on a different subnet that is only accessible by air if you are around it. On my laptop then I need to access the Internet subnet (192.168.125.*) routed by the access point and the Intranet subnet (10.21.35.*) to access the access-point administration console, using only my WIFI network card.
This is the script “WIFI Home Static IP.nsh” to do that:

interface ip
set address name="Wireless Network Connection" source=static addr=192.168.125.77 mask=255.255.255.0 gateway=192.168.125.1 gwmetric=0
add address name="Wireless Network Connection" addr=10.21.35.2  mask=255.255.255.0
set dns name="Wireless Network Connection" source=static addr=192.168.178.1

The above script sets two IP addresses and related subnets details for the interface called “Wireless Network Connection”. The interface name comes from the Network Connections dialog of Windows.

To execute the script you use the command:
netsh -f "WIFI Home Static IP.nsh"

Executing that, this is my ipconfig output

Scheda Ethernet Wireless Network Connection:

        Suffisso DNS specifico per connessione:
        Indirizzo IP. . . . . . . . . . . . . : 10.21.35.2
        Subnet mask . . . . . . . . . . . . . : 255.255.255.0
        Indirizzo IP. . . . . . . . . . . . . : 192.168.125.77
        Subnet mask . . . . . . . . . . . . . : 255.255.255.0
        Gateway predefinito . . . . . . . . . : 192.168.125.1

And to restore the default IP settings for other networks (using DHCP for obtaining single IP and DNS) I use this other script called “WI-FI DHCP.nsh”:

interface ip
set address name="Wireless Network Connection" source=dhcp
set dns name="Wireless Network Connection" source=dhcp

The above lines sets IP and DNS address to be obtained automatically from the DHCP (that is the default behavior), for my Wireless Network Connection.

To do things quickly I associated the .nsh file extension to the command netsh -f "%1" and now I can switch network settings just clicking on an icon.

Learning to create netsh scripts can help much if you bring your laptop in different networks.


One Response to “Multiple IP on a single network interface”  

  1. 1 Paul

    This is PERFECT! I was struggling with two web servers that needed to use port 80. By using your script I can have a web server on one ip address and the other web server on the other ip address.

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>



Calendar

August 2007
M T W T F S S
« Jul   Sep »
 12345
6789101112
13141516171819
20212223242526
2728293031  

Follow me

twitter flickr LinkedIn feed

Subscribe by email

Enter your email address:

Archives


Categories

Tag Cloud


Listening