1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to change IP using Batch File

Discussion in 'Windows' started by nimesh, Oct 16, 2009.

  1. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:

    Introduction



    This is an article on how to change IP using batch file using the DOS command NETSH

    Background



    I'm writing this article as this has helped me a lot as I've to use my office laptop both at office and at home, and at office I've to use domain account which is very much restricted.
    So I can do most of the restricted jobs using the runas feature and then using the local account which has got privileges but cannot change the IP as that is not available in runas.

    Also the office network has static IP address and home network is on DHCP, and I have logging off and change the IP and then relogin. So I created this batch file which enables me to change the IP using the runas service.

    The code



    I've created 2 batch files, one for home which changes the IP to dhcp

    Code:
    netsh interface ip set address "Local Area Connection" dhcp
    netsh interface ip set dns     "Local Area Connection" dhcp
    netsh interface ip show config
    
    This is simple to understand

    netsh interface ip is common
    set for changing the settings
    set addess to change the IP address
    set dns to change the dns address
    "Local Area Connection" is the name of the network connection
    dhcp is the mode which is set for IP and dns both

    And netsh interface ip show config is to show the config on screen

    And one for office, which changes to static IP as I want it in office

    Code:
    netsh interface ip set address "Local Area Connection" static 192.168.0.101 255.255.255.0 192.168.0.1 1
    netsh interface ip set dns     "Local Area Connection" static 192.168.0.10
    netsh interface ip add dns     "Local Area Connection" 192.168.0.11 index=2
    netsh interface ip show config
    
    netsh interface ip is common
    set for changing the settings
    set addess to change the IP address
    set dns to set the primary dns address
    add dns to add extra dns address
    "Local Area Connection" is the name of the network connection

    static 192.168.0.101 255.255.255.0 192.168.0.1 1
    to specify the static ip settings
    192.168.0.101 - IP address
    255.255.255.0 - subnet mask
    192.168.0.1 - gateway
    1 - I don't know what's the significance but it didn't work without this

    static 192.168.0.10 - to add static dns address as primary dns
    index=2 to indicate that this is the secondary dns address

    References



    Used this as a reference for making the batch file
    http://www.petri.co.il/configure_tcp_ip_from_cmd.htm
     
    Scripting likes this.
  2. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    Hey Shabbir,

    The Edit Article button is removed from Article page but it appears on the G4EF homepage!!!
     
  3. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    Would Look into it. That would anyway give an error as editing is not allowed.
     
  4. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
    It shows if user have permission to edit but if time has passed it would not show on articles but would show on homepage
     
  5. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
  6. kiddo

    kiddo New Member

    Joined:
    Apr 11, 2009
    Messages:
    65
    Likes Received:
    1
    Trophy Points:
    0
    I'm not understand about the purpose of changing IP address?
    can u explain 4 me a little more?
    Coz from what I know, we can get IP address automatically.

    At home I'm using HSDPA broadband connection, is it also DHCP?
    and what about wireless connection(wi-fi)?

    I'm used to using wi-fi at my campus.

    ----------------------------------------------------------------------------------------

    Long time no c, lol :D
     
  7. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    this is helpful for people who need to switch networks frequently, between static and dhcp (for same network conn) or between various static with different fixed ips. wi-fis can have static ip too but that would have a separate network conn. ltnc..coz I'm travelling (on a vacation) :) ....... currently I m in shabbir's city which I would leave tom morning. ;)
     
  8. kiddo

    kiddo New Member

    Joined:
    Apr 11, 2009
    Messages:
    65
    Likes Received:
    1
    Trophy Points:
    0
    I c...
    so everytime we want to change from static to DHCP ip address,
    we have to switch the connection, right?
    Thx for the explanation
     
  9. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,292
    Likes Received:
    365
    Trophy Points:
    83
  10. JenWarez6

    JenWarez6 New Member

    Joined:
    Nov 18, 2009
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    this is very confusing
     
  11. rasd123

    rasd123 Banned

    Joined:
    Nov 4, 2009
    Messages:
    40
    Likes Received:
    0
    Trophy Points:
    0
    Right on, write on about whatever you feel best.
     
  12. sdnfjeuas

    sdnfjeuas New Member

    Joined:
    Dec 1, 2009
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    At home I'm using HSDPA broadband connection, is it also DHCP?
    and what about wireless connection(wi-fi)?
     
  13. nimesh

    nimesh New Member

    Joined:
    Apr 13, 2009
    Messages:
    770
    Likes Received:
    20
    Trophy Points:
    0
    Occupation:
    Oracle Apps Admin
    Location:
    Mumbai
    Home Page:
    If you get the IP automatically then most probably it will be DHCP.

    You can check it using CMD command: netsh interface ip show config
    In the results you may get single or multiple interface settings based on your current network config

    Go with the interface name that you wish to see the settings,
    You will see the below sentence in the results:
    DHCP Enabled: YES (If DHCP is enabled)
    DHCP Enabled: NO (If DHCP is disabled)

    Or you can go to Network Connection and check from there.
     

Share This Page