Wednesday, January 21, 2009

Create a Static IP from the Command Line

Creating a static IP from the command line is a very short task. All you need to edit is one configuration file and restart the networking service. You will need to know the settings for your network to do this. I will show how to set a static IP of 192.168.0.101 on a network with a gateway of 192.168.0.1.
  1. Open the configuration file in your favorite editor (mine is nano)
    sudo nano /etc/network/interfaces
  2. Comment out the section where dhcp is being used (put the # in front of the line):
    #auto eth1
    #iface eth1 inet dhcp
  3. Add a section like this example:
    auto eth1
    iface eth1 inet static
    address 192.168.0.101
    netmask 255.255.255.0
    network 192.168.0.0
    broadcast 192.168.0.255
    gateway 192.168.0.1
  4. Close and save the file
  5. Reload the network service:
    sudo /etc/network restart
  6. Check to make sure you can access other computers/internet by using ping:
    ping www.google.com
  7. If you don't get a response then you may have set your network information incorrectly. Just go back and repeat this process at step 3.
Make sure you have entered the correct information for YOUR network. Once you have the static IP set up properly you can then have your other computers access that computer through it's IP address.

1 comment:

www.marcoviera.com said...

Thank you. These were the best directions I found. Very very helpful.