How to set network settings in Linux using command line?

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.

Linux ifconfig Command

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

Getting Network Information using ifconfig Command

Syntax

[root@localhost ~]# ifconfig <options>

Example

[root@localhost ~]# 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.

Setting IP Address in Linux

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

Syntax

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

Example

[root@localhost ~]# ifconfig eth0 192.168.10.20

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

Linux 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

Network Settings Through route Command

Get network settings through route command

[root@localhost ~]# 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!

Load comments ↻





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