About Me

My photo
Kalyan Kumar Pasupuleti B-Tech(Information Technology). • AWS Certified Solutions Architect - Associate • RedHat Certified Engineer(RHCE) • Directory Services and Authentication Certificate of Expertise(LDAP) • Red Hat SELinux Policy Administration Certificate of Expertise(SELinux) • Network Services Security Certificate of Expertise (Network Services) • RedHat Certified Virtualization Administrator(RHCVA) • Red Hat Certified Security Specialist (RHCSS) Working as Cloud DevOps engineer

Tuesday, April 19, 2011

How To Set a Static IP in Ubuntu Server?



The Ubuntu server OS by default installs its network settings as DHCP (dynamic). Anyone who wishes their server to be accessible from outside their network (over the internet) should change this setting to static as any incoming traffic will need permission to enter the network through port 80 on your local network (router/modem). The following will help you to make these changes through ubuntu's command line on your server. One thing to keep in mind, the numbers I use in my example are based on a router whos gateway is 192.168.1.1. This is a very common gateway but it may not be yours. Please check your router configuration for this information before moving on.


The first thing we need to do is get a text editing program called vim-nox. We do this because the text editor that comes with Ubuntu by default has problems making this sort of edit. To get and install vim-nox, in your command line, type:
sudo apt-get install vim-nox
When the vim-nox installation is complete you will be back at the command line. To open your network settings in the text editor, type:
sudo vi /etc/network/interfaces
You should see a few lines of information about your network settings, the last of which should read:

iface eth0 inet dhcp
Navigate to the end of this line and type the letter:
i
This will enable you to edit the text in this file. The first change you will make to this file is to change:

iface eth0 inet dhcp
to:

iface eth0 inet static
Then you will need to enter the following information about your local network:

address 192.168.1.100
netmask 255.255.255.0
network 192.168.1.0
broadcast 192.168.1.255
gateway 192.168.1.1
Next you will need to save the changes that you just made to this file. To do that, press ESC and type:
:wq

Then press enter.

The changes are now made but they will not take effect until the next time the server or network are restarted. To restart your Ubuntu network connection and update the changes you have just made, there is one last step. In your command line type:

sudo /etc/init.d/networking restart
Then press enter and ubuntu will restart its network connection. Now you will be able to configure your router to allow outside traffic to your server through port 80 on IP 192.168.1.100. Everytime you restart your machine, or your router, your ubuntu server will always log on to your local network at the same (static) address. This will save you tons of time and energy from having to change these settings each time on your router. zZoox has a list of other possible router configurations for this method

No comments:

Post a Comment