Linux
Linux Network Configuration Command Line

In this blog, we explain you 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:
1 2 3 4 5 6 7 8 |
cat /etc/sysconfig/network-scripts/ifcfg-eth0 DEVICE=eth0 BOOTPROTO=dhcp ONBOOT=yes TYPE=Ethernet USERCTL=yes PEERDNS=yes |
Help-Notes for above configuration:
1 2 3 4 5 6 7 8 |
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
1 |
$ 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 response)
What to do entry in Host file:
1 2 3 |
<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:
1 |
vi /etc/sysconfig/network |
Even after a reboot, this hostname will be permanent as per the entry in network file.
Temporary change the hostname:
1 |
hostname sshinde |