Home » Linux

How to set network settings in Linux using command line?

Learn: How to get and set network settings of Linux system using commands? In this articles I am going to discuss some of the common and important commands that are used to get and define the network settings like Ip Address, subnet mask etc.

This article contains some of the common and important commands of Linux system to get and set the network settings like IP Address, Subnet Mask, and Gateway etc.

1) ifconfig command

This command is used to get and set the IP Address, Subnet Mask and other network related information on Linux System.

A) Getting Network Information using ifconfig command

Command Syntax:

[root@localhost ~]# ifconfig <options>


[root@localhost ~]# ifconfig
eth0  Link encap:Ethernet  HWaddr 78:45:C4:AC:2F:CA  
          inet addr:  Bcast:  Mask:
          UP BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:0 errors:0 dropped:0 overruns:0 frame:0
          TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:0 (0.0 b)  TX bytes:0 (0.0 b)
          Interrupt:34 Base address:0x8000 

In above command eth0 is network interface on which networking settings are applied. There are following network settings applied on network interface eth0.

  1. IP Address :
  2. Subnet Mask :
  3. Mac Address : 78:45:C4:AC:2F:CA
  4. Broadcast :

Note: If we did not set any IP address to our device or computer system then ifconfig command does not show any IP address, Mac address is always assigned by manufacturer of device or computer system.

B) Setting IP Address

This command can also be used to set IP Address of a Linux based Device or Computer System.


[root@localhost ~]# ifconfig <network interface> <ip address>


[root@localhost ~]# ifconfig eth0

C) Setting Subnet Mask

Subnet Mask or Net Mask can also be set through this command, consider the syntax and example.


ifconfig <network interface> <ip address> netmask <netmask address>


ifconfig eth0 netmask

2) route command

route command is used to set network gateway to computer system.


route add default gw <gateway ip> <network interface>


route add default gw eth0

Get network settings through route command

[root@localhost ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface   U     0      0        0 eth0         UG    0      0        0 eth0

Comments and Discussions!

Load comments ↻

Copyright © 2024 www.includehelp.com. All rights reserved.