You can get the advice from IT HELP DESK

SYSTEM[LINUX] Network interface management by ifconfig command

Robert
18 Jan 2019
<head>Disk Management, Server Monitoring, System management, server monitoring, server management, system management, system monitoring, </head>

[LINUX] Network interface management by ifconfig command

Hello ~!

1. Network interface management commands

A typical command for checking and managing network interfaces on a Linux system is ifconfig.

ifconfig command is used to check the IP information, broadcast IP information, and the amount of packet transmission/reception through the corresponding interface set in the network interface.


Below are 10 ways you can use ifconfig.


  1) Output All Network Setting

  • You can check the information of all network interfaces currently in use through ifconfig command.
  • IP information registered in the network interface can also be checked.
[root@localhost ~]# ifconfig

eth2    Link encap:Ethernet  HWaddr B4:96:91:2D:8C:98
          inet addr:192.168.1.18  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::b696:91ff:fe2d:8c98/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28476368 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12131920 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7236493742 (6.7 GiB)  TX bytes:2834554406 (2.6 GiB)
          Memory:b8500000-b85fffff

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:42241455 errors:0 dropped:0 overruns:0 frame:0
          TX packets:42241455 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:43600303846 (40.6 GiB)  TX bytes:43600303846 (40.6 GiB)


  2) Output all Network Interface.

  • When the -a option is used, a list of all interfaces including the list of disabled network interfaces is output.
[root@localhost ~]# ifconfig -a

eth0    Link encap:Ethernet  HWaddr 6C:92:BF:8D:A6:EE
          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)

eth1    Link encap:Ethernet  HWaddr 6C:92:BF:8D:A6:EF
          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)

eth2    Link encap:Ethernet  HWaddr B4:96:91:2D:8C:98
          inet addr:192.168.1.18  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::b696:91ff:fe2d:8c98/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28595524 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12143774 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7265030799 (6.7 GiB)  TX bytes:2837608812 (2.6 GiB)
          Memory:b8500000-b85fffff

eth3    Link encap:Ethernet  HWaddr B4:96:91:2D:8C:99
          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)
          Memory:b8400000-b84fffff

lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:65536  Metric:1
          RX packets:42335313 errors:0 dropped:0 overruns:0 frame:0
          TX packets:42335313 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:43701458077 (40.7 GiB)  TX bytes:43701458077 (40.7 GiB)


  3) Output only specific Network Interface information 

  • If you use both ifconfig command and network interface name (eg eth0), only information about the interface is output. 
  • Use when you want to see only the necessary network interface information. 
[root@localhost ~]# ifconfig eth2

eth2    Link encap:Ethernet  HWaddr B4:96:91:2D:8C:98
          inet addr:192.168.1.18  Bcast:192.168.1.255  Mask:255.255.255.0
          inet6 addr: fe80::b696:91ff:fe2d:8c98/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:28476368 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12131920 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:7236493742 (6.7 GiB)  TX bytes:2834554406 (2.6 GiB)
          Memory:b8500000-b85fffff


  4) Enable a Network Interface 

  • The currently disabled network interface can be activated via ifconfig command.
  • Activate the network interface by combining the ifconfig with the network interface name and up.

             ※  Note!   If you enable the network interface but the IP is not assigned to the interface, communication is impossible!

  • Replaceable with ifup command.
[root@localhost ~]# ifconfig eth0 up

OR

[root@localhost ~]# ifup eth0


  5) Disable a Network Interface 

  • The currently active network interface can be disabled via ifconfig command.
  • Activate the network interface by combining ifconfig with network interface name and down.
  • Replaceable with ifdown command.
[root@localhost ~]# ifconfig eth0 down

OR

[root@localhost ~]# ifdown eth0



  6) Assign an IP Address to Network Interface

  • You can also assign or change an IP to a specific interface through ifconfig command.
  • Enter ifconfig command with the network interface name and the IP address to be entered.
[root@localhost ~]# ifconfig eth0 192.168.10.199


  7) Assign a Netmask to Network Interface

  • When IP is registered with ifconfig command, subnet mask is automatically assigned to network interface according to IP type.
  • If you need to use a specific subnet mask, you need to change the subnet mask with the command below.
[root@localhost ~]# ifconfig eth0 netmask 255.255.255.224


  8) Assign a Broadcast to Network Interface

  • Broadcast IPs are automatically registered as well as subnet masks, but changes need to be made to use a specific broadcast IP.
  • Change to the IP you want to change via ifconfig command and the value of the broadcast argument.
[root@localhost ~]# ifconfig eth0 broadcast 192.168.10.255


  9) Assign an IP, Netmask, and Broadcast IP

  • You can combine all of the parameters described above to do all the work at once.
  • It can be enabled/disabled at the same time as setting value is applied through up/down factor value.
## eth0 Network interface configuration
 [root @ localhost ~] # ifconfig eth0 192.168.10.199 netmask 255.255.255.224 broadcast 192.168.10.255

# eth1 Enabled simultaneously with network interface configuration
 [root @ localhost ~] # ifconfig eth1 192.168.10.200 netmask 255.255.255.224 broadcast 192.168.10.255 up


  10) Change the MAC address of Network Interface

  • If the actual MAC address of the Ethernet card is different from the MAC address registered in the network interface, normal network communication is impossible.
  • In this case, you need to change it to match the actual MAC address, but you can also change it by using ifconfig command.
[root@localhost ~]# ifconfig eth0 hw ether XX:XX:XX:XX:XX:XX



ifconfig command is one of the most frequently used and important commands for using Linux.

Most Linux administrators modify the GUI or the /etc/sysconfig/network-scripts/ifcfg file when configuring the network.

If you can not change the configuration via the above method, you can use ifconfig command!


Leave your comment on the question.