setting a static ip on ubuntu a beginner's guide

8
Setting a static IP on Ubuntu: a beginner's guide Many situations occur when a static IP address needs to be set. For example, if you have programs that use the IP address say for remote login, then you might hardcode the IP address. But if the IP address is dynamic it can change, and thus you need an IP that does not change and hence you would need to set a static IP for your system. This tutorial deals with setting a static IP for buntu !". 1 Manually confguring the interace This step involves manually con#guring the networ$ interface by ma$ing changes to the %interfaces% #le. &ere I use the %gedit% #le editor but it is possible to use other editor li$e %nano%, %vi%, etc. Type the following command in the terminal' sudo gedit /etc/network/interfaces If it as$s for password enter that and a #le will open that loo$s li$e' ( interfaces)*+ #le used by ifup) + and ifdown) + auto lo iface lo inet loopbac$ iface etho inet dynamic There might be more than one networ$ card and so be sure which networ$ card you want to change. First open another terminal and run the command' ifconfig This gives the IP address of your system along with %Bcast% address and %mas$%. -ote the IP, Bcast and the mas$ of your system. This is done so that you can go bac$ to the original IP when needed. et/s assume the values we have got for %eth0% networ$ interface )that is my ethernet connection+ is' address' 123.14 .3 .56 Bcast' 123.14 .3 .3** Mas$' 3**.3**.3**.0 "o, when the interfaces #le is con#gured for a static IP on %eth0%, it must have a general format li$e below' ( interfaces)*+ #le used by ifup) + and ifdown) +

Upload: rakesh-bhardwaj

Post on 06-Oct-2015

235 views

Category:

Documents


0 download

DESCRIPTION

Setting a Static IP on Ubuntu a Beginner's Guide

TRANSCRIPT

Setting a static IP on Ubuntu: a beginner's guideMany situations occur when a static IP address needs to be set. For example, if you have programs that use the IP address say for remote login, then you might hardcode the IP address. But if the IP address is dynamic it can change, and thus you need an IP that does not change and hence you would need to set a static IP for your system. This tutorial deals with setting a static IP for Ubuntu OS.1 Manually configuring the interfaceThis step involves manually configuring the network interface by making changes to the "interfaces" file. Here I use the "gedit" file editor but it is possible to use other editors like "nano", "vi", etc. Type the following command in the terminal:sudo gedit /etc/network/interfacesIf it asks for password enter that and a file will open that looks like:# interfaces(5) file used by ifup(8) and ifdown(8)auto loiface lo inet loopbackiface etho inet dynamicThere might be more than one network card and so be sure which network card you want to change. First open another terminal and run the command:ifconfigThis gives the IP address of your system along with "Bcast" address and "mask". Note the IP, Bcast and the mask of your system. This is done so that you can go back to the original IP when needed. Let's assume the values we have got for "eth0" network interface (that is my ethernet connection) is:address: 192.168.28.37Bcast: 192.168.28.255Mask: 255.255.255.0So, when the interfaces file is configured for a static IP on "eth0", it must have a general format like below:# interfaces(5) file used by ifup(8) and ifdown(8)auto lo eth0iface lo inet loopbackiface eth0 inet static address xxx.xxx.xxx.xxx(enter your ip here) netmask xxx.xxx.xxx.xxx gateway xxx.xxx.xxx.xxx(enter gateway ip here,usually the address of the router)Below is a screenshot of my "interfaces" file. Note that Bcast also means Gateway, and mask also means netmask. Here we assume that our new static IP to set is 192.168.3.215.

So please make changes according to your "interfaces" file. Save and close it.2 Configuring DNS informationPlease note that this step isn't mandatory. If you do not want to change the DNS information, then skip this step. Here we change the IP of DNS server to what we prefer. There are a lot of DNS server IPs, that can be found and used. First open the file "resolv.conf" using the following command:sudo gedit /etc/resolv.confInitially it will look something like this:# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)# DO NOT EDIT THIS FILE BY HAND -- YOUR CHANGES WILL BE OVERWRITTENnameserver 127.0.1.1search HomeNow we can add many nameservers and change the existing one to suit our needs. Make changes and save the file. The following screenshot shows the resolv.conf file changed to have two nameservers:

3 Making the changes permanentOnce the changes have been made to one or both the files (interfaces and resolv.conf), we will have to apply those changes to reflect them. Previously, we could restart the network to make the changes happen, but due to some reason, newer versions of Ubuntu doesn't apply those changes. So, we will have to reboot the whole system. To do so, use the command:sudo rebootAfter the restart, the output of network details should show the changes. Open a terminal and run the command:ifconfigOn examining the output , the eth0 interface should have the new IP, Bcast and mask. In this case, the output might look similar to this:eth0 Link encap:Ethernet HWaddr xx:xx:xx:xx:xx:xx inet addr:192.168.3.215 Bcast:192.168.3.255 Mask:255.255.255.0 .....This confirms that the changes have been applied.4 Configuring other interface like "eth1"There might be other interfaces, like "eth1" that might require configuration. In this case, some changes are required to interface file as shown. The changes here are: adding eth1 in the "auto" line ading the configuration for eth0Make changes as shown in the image below with the required IP, Bcast and mask

So, this way changes can be made to many different interfaces.5 Configuring another IP for same interfaceHere we have set one IP address for "eth0". But, what if we want to set another IP? Here we have set the IP as 192.168.3.215. Now for the same interface if we want to set another IP say 192.168.3.217, then we can do it by changing the "interfaces" file. Here "eth0:1" indicates that we are assigning a second IP for the "eth0" interface.The changes are represented in the image below.

6 Configuring IP address using the Desktop ApplicationMost of the configuration done above can be carried out in the desktop application called "network". To go ahead with that, start by opening the "network" application from the dash as shown in the image below.

Click on "network" to open it. It will look similar to the one below:

In that window, click on the "options" button at the bottom right corner and in the window that opens, click on the "IPv4 settings" tab. The window is shown below

Initially the setting is set to "Automatic(dhcp)", which is dynamic IP. To make it static, select the dropdown menu and click on manual as shown in the image below:

Once manual is selected the text box below it is activated. Click the "Add" button on the right and on the left hand text box, enter the IP, the mask(netmask) and the gateway (Bcast) addresses. Also add the DNS server IP if you wish to change that too. Once done click on save. After this editing, it should look similar to the image below:

Once saved, we will have to restart the system as before in order for the changes to be applied.