Ifconfig – Linux


ifconfig– to display interface status in Linux

  • Without any arguments it displays all active interfaces.
  • With “–a” it shows both active and inactive interfaces
  • With specific arguments like eth1, it gives only eth1 interface status.
  • Options:
    • To change MTU: “ifconfig eth0 mtu 2000”
    • To shut an interface: “ifconfig eth0 down” or “ifdown eth0”
    • To no-shut an interface: “ifconfig eth0 up” or “ifup eth0”
    • To add/change the IPv4 address “ifconfig eth0 20.20.20.2 netmask 255.255.255.0”. Will no-shut the interface automatically.
    • To start/restart/stop/check-status on network service:
# service network ?
Usage: /etc/init.d/network {start|stop|restart|reload|status}
[root@server2 ~]# service network status
Configured devices:
lo eth0 eth1 eth2 eth3 eth4 eth5 eth6 eth7 eth8 eth9
Currently active devices:
eth1 eth5
[root@server2 ~]#
  • To reset interface counters:

Just restart the network services using “service network restart” command (OR)

  • Bring down the interface:
[root@server2 ~]# ifdown eth4
[root@server2 ~]# ifconfig eth4
eth4      Link encap:Ethernet  HWaddr 00:18:FE:2E:36:6B
          BROADCAST MULTICAST  MTU:1500  Metric:1
          RX packets:128992991 errors:0 dropped:0 overruns:0 frame:0
          TX packets:75 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:3890882324 (3.6 GiB)  TX bytes:5958 (5.8 KiB)
[root@server2 ~]#
  • Check the module for the ethernet. Module should be either in “etc/modules.conf” or “/etc/modprobe.conf”.
[root@server2 ~]# cat /etc/modprobe.conf | grep eth4
alias eth4 e1000e
[root@server2 ~]#
  • Remove the module and [re]load the module again. The interface status should be reset and interface can be brought up:
[root@server2 ~]# rmmod e1000e
[root@server2 ~]# modprobe e1000e
[root@server2 ~]# ifup eth4
[root@server2 ~]# ifconfig eth4
eth4      Link encap:Ethernet  HWaddr 00:18:FE:2E:36:6B
          inet addr:20.20.20.2  Bcast:20.20.20.255  Mask:255.255.255.0
          inet6 addr: 2001:4860:800c:301:218:feff:fe2e:366b/64 Scope:Global
          inet6 addr: fe80::218:feff:fe2e:366b/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:4 errors:0 dropped:0 overruns:0 frame:0
          TX packets:14 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:472 (472.0 b)  TX bytes:784 (784.0 b)
  • “UP” implies the interface is admin UP and “RUNNING” implies the interface line protocol is UP and functioning.
  • To change HW mac-address on an interface: use “ifconfig eth0 hw ether  <hw address>“.    Doing “service network restart[reload]” will through the error

“Device eth0 has different MAC address than expected, ignoring.”

  • Whenever we do “service network restart”/reloads, the configuration from “/etc/sysconfig/network-scripts/ifcfg-eth0” will be applied to eth0 interface. So, make sure the file has correct desired configuration to be applied after reload.
  • To summarize, the configurations on below files should be same;
    • “ifconfig eth0”   <<< Current active configuration
    • “cat /etc/sysconfig/network-scripts/ifcfg-eth0”  <<< configuration will apply after reload
    • “cat /etc/sysconfig/networking/devices/ifcfg-eth0”
    • “cat /etc/sysconfig/networking/profiles/default/ifcfg-eth0”

To disable IPv6 networking module to load modify below files;

1. /etc/modprobe.conf –  Kernel driver configuration file.

2. /etc/sysconfig/network – RHEL / CentOS networking configuration file.

Sample ifcfg-eth0 file:

[root@-linux-1 ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth0
# Broadcom Corporation NetXtreme II BCM5708 Gigabit Ethernet
DEVICE=eth0
BOOTPROTO=none
BROADCAST=10.16.151.255
HWADDR=00:19:BB:2E:B7:1A
IPADDR=10.16.151.206
IPV6INIT=yes
IPV6_AUTOCONF=yes
NETMASK=255.255.255.0
NETWORK=10.16.151.0
ONBOOT=yes
TYPE=Ethernet
PEERDNS=yes
USERCTL=no
GATEWAY=10.16.151.254
[root@-linux-1 ~]#
  • “system-config-network-cmd” displays the systems’ network configuration.

					
Advertisements
This entry was posted in Linux and tagged . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s