Switch to Static IP on Ubuntu Server

I just bought a new Linksys router for my home network and wanted to set-up my Ubuntu Web Server with a static IP address so that I could port-forward a few things. Trouble is, with only the command line it’s a little tricky to figure out exactly how to do it. Following are the steps I used.

sudo nano /etc/network/interfaces

Inside the file, you’ll see the following line:

iface eth1 inet dhcp

We want to switch from dhcp to a static IP address. Comment or delete that line, and then add the following to the file:

iface eth1 inet static
address 192.168.1.200
netmask 255.255.255.0
gateway 192.168.1.1
  1. This line states we want to use a static IP address.
  2. The static IP address you want to use.
  3. The subnet mask.
  4. This is the IP address of my router which connects to the Internet.

Save the file and then restart the network settings:

sudo /etc/init.d/networking restart

Job done.

2007-01-27 [, , , , ]
  • Robert

    Thanks mate, this helped a ton! Much easier than the instructions in the server guide!

  • http://www.none.com peter

    can NOT read white letters on black background. please change it! thank you

  • ANON

    Just highlight the letters to make it easier to read.

  • http://kik-it.com Skeptik

    On a newly installed ubuntu ur primary eth is in dhcp, then u set it static by updating /etc/network/interface (u can edit resolv.conf also for dns) following given instructions on this page, but it might hapen that a dhcpclient is still running on ur server and will overwrite ur static settings periodically.

    If that happens, I wouldn’t recommend removing dhcp-client like some web resources advice u. Because What if one day u want to get an IP from ur DHCP, what if ur PC has more than one nic and one needs a DHCP IP ?

    then try a :

    ps ax|grep dhc

    u probably will see a running dhclient3 process running or a dhclient if u runned it by hand

    kill them respectively with :

    killall dhclient3 killall dhclient

    then a “ps ax|grep dhc” should show no dhcp client running. Now ur server is set to ur static IP and wont request dhcp IPs anymore, even on reboot.

    but u still can request for a dhcp IP by hand.

  • http://www.planotexasdaycare.com Frankie Pochintesta

    I have attempted to post a response here and every time I submit the form times out the screen or provides an error. Can the author possibly look into the reason there is a problem?

  • joshua

    the tutorial it’s great, and it works but i am getting some kind of problems, after 3 – 4 hours the server is not reacheable, but if i do a ping request from the server to any host then the server its reachable again. I don’t know what could it be. help please…

blog comments powered by Disqus