IP configuration in linux

How to configure IP address in Linux

The IP address configuration in Linux flavors like (centos , redhat & Fedora) are similar.
IP address require to communicate with other node in network. communication is nothing but data transfer between nodes.

 

IP version:
IPv4(4octets , each octet equal to 8bits) total 8*4= 32bit (present).
Ex: 0.0.0.0 0.0.0.0 0.0.0.0 0.0.0.0 = 8bits + 8bits + 8bits + 8bits = 32

IPv6 (8octets, each octet equal to 16bits) 16*8 = 128bit (future)

TCP/IP: transmission control protocol / internet protocol
TCP :- Transmission control protocol.

  • connection oriented
  • Reliable
  • slower than UDP
  • http,https , smtp,pop3 & ftp

UDP :- User datagram protocol.

  • connection less
  • unreliable
  • faster than TCP.
  • DNS , tftp

ICMP :- Internet Control Message Protocol

  • Ping and Pong

The IP address configuration in Linux

This video is about IP address configuration on Linux, you can use several methods to assign IP address as described below.

1. IP address configuration using command line
2. IP address configuration using configuration file
3. IP address configuration using GUI tool within CLI terminal console(system-config-network-tui)
4. Adding Route (static / default)

1. IP address configuration using command line
IP configuration in linux over command line, the below steps will guide through.
IP Address can be assigned to an interface using command line utility “ifconfig” , following actions can be performed

1.1 Assign an IP address

We assume that you have a network card installed in machine with Centos operating system.

Syntax :
ifconfig interface IPaddress netmask:subnet g status
Ex: ifconfig eth0 192.168.100.1 netmask 255.255.255.0 gw 192.168.100.1 up

Run below command to verify, how many NIC’s installed in.
make sure, you logged as root.
#ifconfig -a

OR

#ifconfig -a |more

In our guide we are going to use eth0 as network interface name to assign 192.168.100.1

#ifconfig eth0 192.168.100.1 netmask 255.255.255.0 gw 192.168.100.1
If you want to set it on boot startup configuration file /etc/rc.d/rc.local.
Add following entry:

#vi /etc/rc.d/rc.local

ifconfig eth0 192.168.100.1 netmask 255.255.255.0 gw 192.168.100.1

Save & Exit!

1.2 Change interface status (UP / Down)

Change the interface status (UP / Down)

#ifconfig eth0 down

#ifconfig eth0 up

1.3 Create virtual interface & Assign Virtual IP

Create a virtual interface and assign an IPaddress within the network or other network. A virtual interface can have IP adddress of different network than physical interface.
You can create any number of virtual interface and each one can have IP of same network / other network.

#ifconfig eth0:1 192.168.200.1 netmask 255.255.255.0 up


Note : eth0:1 (eth0 is physical , :1 is virtual interface identifier number)
Example :
eth0:1
eth0:2
eth0:3 ….

 

2.Configure IP address using configuration file

The IP configuration settings can be made through a configuration file associated to an interface . each of interface will have it’s configuration file.
The default configuration file resides in /etc/sysconfig/network-scripts

#cd /etc/sysconfig/network-scripts

#ls
output:
ifcfg-eth0 ifdown-isdn ifup-aliases ifup-plusb init.ipv6-global
ifcfg-lo ifdown-post ifup-bnep ifup-post net.hotplug
ifdown ifdown-ppp ifup-eth ifup-ppp network-functions
ifdown-bnep ifdown-routes ifup-ippp ifup-routes network-functions-ipv6
ifdown-eth ifdown-sit ifup-ipv6 ifup-sit
ifdown-ippp ifdown-tunnel ifup-isdn ifup-tunnel
ifdown-ipv6 ifup ifup-plip ifup-wireless
Note :ifcfg-eth0 is a configuration file for interface eth0. it may exist if not you can create it manually.

#vi /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
TYPE=Ethernet
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=none
HWADDR=00:11:43:DE:EE:D0
IPADDR=192.168.100.1
NETMASK=255.255.255.0
PREFIX=24
GATEWAY=192.168.100.100
DEFROUTE=yes
NAME=”eth0″
Save & exit!

Create an interface configuration file virtual interface name eth0:1 , in similar way you can create any number virtual interface like (eth0:2 , eth0:3 , eth0:4….)
Note: Virtual interface doesn’t require mac address.

#vi /etc/sysconfig/network-scripts/ifcfg-eth0:1

DEVICE=eth0 #interface name
TYPE=Ethernet #interface type
ONBOOT=yes # set the status ON at boot
USERCTL=no # user control, changing status up/down access to user
NM_CONTROLLED=yes #network Manager enabled/disable
BOOTPROTO=none #IP – Static / Dynamci
IPADDR=192.168.100.2
NETMASK=255.255.255.0
PREFIX=24
NAME=”eth0″

Save & Exit

Restart network services by using service network restart ,

#service network restart

view configuration settings applied after the network services restart performed.

#ifconfig -a |more
or
#ifconfig eth0
#ifconfig eth0:1

Verify network cable connectivity by issuing below command

#mii-tool eth0 / ethtool eth0

3. IP address configure using GUI tool within CLI terminal console(terminal user interface).
(system-config-network-tui)

system-config-network-tui tool, enables you to configure ip address using terminal user interface mode.

#yum install system-config-network-tui

run setup command from shell to launch tui . within this you can chose networking configuration settings.

#setup

4.Adding Route (static / default)

Routing is nothing but sending packets to next hop. There are three type of routing as described below.

4.1 Default routing
4.2 Static routing
4.3 Dynamic routing

4.1 Default routing :

Any request originates from LAN to a unknown destination will be sent to default route(another gateway device/router). The best example is internet.
Routing is nothing but sending packets to next hop.
find some useful commands used to add and delete default route in Linux

list the routing table.

#netstat -rn

delete default route

#route -del default.

add default route

#route -add default gw gatewayip

for complete help about route command use below manuals

#man route

4.2 Static routing

forwarding source packets to a know destination via a devices acting as gateway / router.
#route add 192.168.0.0 netmask 255.255.255 gw 192.168.0.2

4.3 Dynamic routing

OSPF or BGP over RIP
above dynamic routing protocols are designed to send source packets to a destination address using best path among different paths available to chose from.

The IP address configuration in Linux

We covered all steps about IP address configuration in Linux 

Watch , How to configure IP Address in Centos / Redhat or Fedora.

Both comments and pings are currently closed.

Comments are closed.

Copyright ©Solutions@Experts.com
Copyright © NewWpThemes Techmark Solutions - www.techmarksolutions.co.uk