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:

[[email protected] ~]# ifconfig <options>

Example:

[[email protected] ~]# ifconfig
eth0  Link encap:Ethernet  HWaddr 78:45:C4:AC:2F:CA  
          inet addr:192.168.10.20  Bcast: 192.168.255.255  Mask:255.255.255.0
          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 : 192.168.10.20
  2. Subnet Mask : 255.255.255.0
  3. Mac Address : 78:45:C4:AC:2F:CA
  4. Broadcast : 192.168.255.255

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.

Syntax:

[[email protected] ~]# ifconfig <network interface> <ip address>

Example:

[[email protected] ~]# ifconfig eth0 192.168.10.20

C) Setting Subnet Mask

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

Syntax:

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

Example:

ifconfig eth0 192.168.10.20 netmask 255.255.255.0

2) route command

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

Syntax:

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

Example:

route add default gw 192.168.10.1 eth0

Get network settings through route command

[[email protected] ~]# route -n
Kernel IP routing table
Destination     Gateway         Genmask         Flags Metric Ref    Use Iface
192.168.10.0    0.0.0.0         255.255.255.0   U     0      0        0 eth0
0.0.0.0         192.168.10.1    0.0.0.0         UG    0      0        0 eth0





Comments and Discussions

Ad: Are you a blogger? Join our Blogging forum.





Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com some rights reserved.