Linux - Network Settings

In this page we will discuss about how to set IP address on your machine.

Methods for assigning IP

We will study several methods to give IP address to my machine. Open file
This file looks like this
Ip address in Linux
IP address setting

This file already has the ip configuration because we already assigned Ip configuration in machine. You can change the IP address. In Centos 5.x and RHEL 5.x you can take advantages of setup command. IP address have been assigned by DHCP server ,will be discuss in later When you assign the ip address to your machine Use command to update your system.
[root@localhost~]# service network restart
[root@localhost ~]# /etc/init.d/network restart The above method is applicable for RHEL and Centos Linux.

For Ubuntu and Debian Linux you can edit the /etc/networking/interfaces file. When your machine has dynamic IP, provided by DHCP server, Then the file looks
IP address in Ubuntu, Debian
IP address in Ubuntu and Debian

For static IP you can edit files like as given below.
auto lo
iface lo inet loopback

# The primary network interface
auto eth0
iface eth0 inet static
address 192.168.0.X
gateway 192.168.0.X
dns-nameservers 192.168.0.X

Important files of Network settings

Here we will discuss about some file related to Networking.


The /etc/hosts file contains the IP address-to-hostname translation table. The /etc/hosts file on each member must contain entries for the following:
  • IP addresses and associated hostnames for all cluster members
  • IP addresses and associated hostnames for the point-to-point Ethernet heartbeat connections (these can be private IP addresses)


You can change your computer name as shown in below figure.
/etc/sysconfig/network hostname

Hostname means your computer name ,this time ""mohitraj" is my computer name, you can edit it.

Important Commands

Here we will study some commands related to networking.


If want to know your network configuration Use command
[root@localhost~]# ifconfig

Redhat 6 sometime does not bringing up Ethernet card. If you face this problem then open the file /etc/sysconfig/network –scripts/ifcfg-eth0 check the options ONBOOT=yes Make sure that it should be "yes", if it is "no" change this to "yes". Reboot the system


To track what ports are open and what services are running on that ports.
For example:
[root@localhost /root]# netstat -natu

-a option is used to display both listening and non listening ports.
-t option is used to display TCP ports.
-u option is used to display UDP ports.
-n option is used, not to resolve hostnames from IP addresses