How to set a Static IP in Ubuntu?
Setting a static IP in Ubuntu is useful for a lot of things. You may want to forward ports from your router to serve web pages, use SSH from outside your local network or set up some sort of media server. To prevent conflict with static IP addressing, change the clone`s static IP before the clone connects to the network.
Disabling visual (nm-tool) network management.
Using Ubuntu’s graphical interface to set a static IP.
To regain control of our network interfaces we first have to disable nm-tools’ management of them.
Disable dnsmasq by commenting out the line with a # (hash) at the beginning of the line.
Set managed (under the ifupdown section) to true.
I find the terminology for ‘managed’ a little confusing here because I have to set this to true to get Network Manager to recognise that I am actually managing this connection manually.
So our NetworkManager.conf now looks like this…
Which connection do I use for my static IP?
So, let’s have a look at our current network information, open a terminal and type/copy the following command
You will now be presented with all the available network connections (whether connected or not). Your output should look something like this
What are the ifconfig connections?
lo – this is a loopback connection, a virtual connection used to connect to the machine (itself) only.
eth0 – an ethernet interface (wired port).
You may well have more eth interfaces, especially in servers where the machine may need to be connected to the network and other machines.
What static IP should I use?
There are some IP ranges reserved for private use.
These are:
10.0.0.0 – 10.255.255.255
172.16.0.0 – 172.31.255.255
192.168.0.0 – 192.168.255.255
The remaining IP ranges are public. So we can use any IP range.
What is my Network Gateway?
Your Network Gateway is the gateway between your network and the Internet, the connection between 2 networks – your network and the worlds.
In most residential broadband set-ups, this will be the router provided by your Internet supplier. In commercial scenario’s, this could be a firewall or other routing device.
To find your current gateway type/copy this command
The output will show a line containing the word ‘default’, the IP on this line will be the IP of your network Gateway… sometimes used interchangeably with Default Gateway.
What is my Netmask / Subnet?
A subnet is used to divide a network into logical groups – sub networks. A Netmask specifies the boundaries of a sub network.
To find your subnet, use ifconfig again.
Your subnet is the value after Mask, in 99% of residential router’s this value will be 255.255.255.0.
What about DNS?
DNS (Domain Name Servers) are like indexes which resolve the domain name to an IP. I primarily use Google’s Public DNS but you may choose to use your gateway IP to let your router deal with DNS.
The name servers I will be using are 8.8.8.8 and 8.8.4.4.
the gateway entry in network configuration i.e., /etc/network/interfaces
iface inet eth0 static
address 192.168.0.13
network 255.255.255.0
gateway 192.168.0.1
get the gateway address from windows using command prompt
go to commnad prompt and type cmd enter
c:>ipconfig
here we have complete network information from which we need to see wired or wireless connection, in that we have gateway address information.
In Ubuntu, open the network configuration file with vi as
by default network configuration in latest versions of linux flavours are dhcp i.e.,
iface inet eth0 dhcp
auto eth0
change dhcp as static by assigning ipaddress, netmask, network, gateway.
root@webusr:~$ vi /etc/network/interfaces
iface inet eth0 static
address 192.168.0.14
network 255.255.255.0
gateway 192.168.0.1
Restart your networking services
Finally, restart your networking services to put your new settings into effect.
This should restart your network interfaces and services.
Use ifconfig to confirm your new static IP
Hostname Configuration
You might run into a situation that requires you to change your computer name, either because you need it to meet a naming scheme.
Open the terminal and give file name as /etc/hostname
Give new hostname and save and quit the file.
Always newly assigned hostname through /etc/hostname will effect when system restarts or session logout.
To check hostname of the system command is hostname
Now we can communicate from Windows to Linux.
After configuring hostname and IP-address in linux machine, we need to give both the entries i.e., hostname and IP-address in /etc/hosts file.
Because always communication between two linux machines will happen by listening /etc/hosts file entries.
The communication will happen through IP-address, But when you want to communicate with hostname you need to give hostname and IP-address entries in /etc/hosts file.
websr@ubuntu:~$ vi /etc/hosts
192.168.0.14 ubuntu1
Save file and exit.
Very Nice Explanation. Please post another topic too.. its very helpful for beginners..
ReplyDeleteThanks
-Sunil