Linux Network Configuration Command Line

In this blog, you’ll come to know Linux Network Configuration Command Line

Steps to Configure Network in Linux:

  • Setup IP Address
  • Setup Gateway
  • Setup NetMask
  • Name Resolution using /etc/hosts
  • Name Resolution using DNS
  • Setup Hostname

Linux Network related commands:

  • ip route
  • ip addr
  • ifconfig
  • hostname
  • ping
  • dig
  • service

Linux Network Related Files:

  • /etc/sysconfig/network-scripts/ifcfg-eth0
  • /etc/sysconfig/network
  • /etc/resolv.conf
  • /etc/hosts

Eg:

cat /etc/sysconfig/network-scripts/ifcfg-eth0

DEVICE=eth0
BOOTPROTO=dhcp
ONBOOT=yes
TYPE=Ethernet
USERCTL=yes
PEERDNS=yes
Help-Notes for above configuration:
ONBOOT=yes                      // when host is booted this configuration will be set

BOOTPROTO=none/DHCP             //DHCP - Automatically IP Address set from the router/network
                                //NONE - If you want to define manual IP address

DNS1=<your router DNS IP>       //Used for Name Resolution (IP-to-Name vice versa)

GATEWAY=<Router Private IP>     //This Define from where network traffic will flow from one N/W to other N/w

After Network Configuration restart the network service

Linux Network Commands
$ service network restart
If you don’t have DNS Server in your Organization:

You can do the entry in /etc/hosts do the entry of your hostname and IP address.

How it works:

When you ping to your own machine with hostname, first it will go to your /etc/hosts file it will search hostname if it found the hostname then the IP Address is found from their and ping command start working(getting a response)

What to do entry in Host file:
<your machine ip> <FQDN> <your hostname>                  //remove “<>” this.

Eg: 172.168.8.12                sshinde@rhel.com         sshinde
How to Set hostname:

To change hostname permanently goto below file:

vi /etc/sysconfig/network

Even after a reboot, this hostname will be permanent as per the entry in the network file.

Temporary change the hostname:
hostname sshinde
After reboot, this hostname will be lost, it will display the hostname which is there in /etc/sysconfig/network file

End of the article, Linux Network Configuration Command Line.


Thanks for reading this article, you’ll also like:

Use of DNS and Common DNS Record Types

Docker Commands Tutorial for Beginners with Example

Steps to Manage logs in Linux using Logrotate

How to Install AWS CLI in LINUX

What is Linux Software yum and rpm