Linux Commands Examples

A great documentation place for Linux commands

ifconfig

configure a network interface


see also : route - netstat - arp - rarp - iptables - ifup

Synopsis

ifconfig [-v] [-a] [-s] [interface]
ifconfig [-v] interface [aftype] options | address ...


add an example, a script, a trick and tips

: email address (won't be displayed)
: name

Step 2

Thanks for this example ! - It will be moderated and published shortly.

Feel free to post other examples
Oops ! There is a tiny cockup. A damn 404 cockup. Please contact the loosy team who maintains and develops this wonderful site by clicking in the mighty feedback button on the side of the page. Say what happened. Thanks!

examples

1
source
            
ifconfig ath0
exit
1
source

How to detect VPN disconnection with vpnc?

Typically the VPN connection should not break so frequently. In your case, you can first try to diagnose the real connectivity issue instead of writing scripts to automatically connect to the vpn when disconnected.

0
source

ip versus ifconfig

Simple answer: On Linux ifconfig is obsolete.

From man ifconfig:

This program is obsolete! For replacement check ip addr and ip link. For statistics use ip -s link.

0
source

Three computers accessing internet but only two network interfaces showing in ´ifconfig´, why?

I am not sure if I understand correctly. But you have 1 Wireless gateway and 3 Devices connected to it?

So doing ifconfig only shows PHYSICAL hardware/connections on the PC that ran the command - not the connections available or other device.

ifconfig stands for interface configuration

  • An interface if a virtual or physical layer on the computer that enables it to communicate with other devices using a standard, for example in your case TCP/IP

  • eth0 could be your Wired Network card running at 10/100/1000

  • eth1 is possibly your wirless interface running at a/b/g/n speeds.
  • lo is a virtual interface and is called a loopback and bind to your computer using home (127.0.0.1) or (localhost) or whatever your computers name is(because it loops back to it self)

To see other computers you need to use something like ARP and to find other computers or devices within your network range.

Also as suggested you can use a wireless tool iwconfig to scan for access points (an access point is not an interface- but the access point it self uses an interface to communicates with other devices found in ARP)

And you only have 1 internet connection, not 3.

In total you should have 5 ARP entries - 2 PC's, 1Notebook, 1Switch and 1 Modem

enter image description here

So as you can see in the illustration, each host has an interface of eth0, the gateway has eth0 and the ISP on the other side has eth0. the more interfaces a device has the higher the number.

0
source

Is `ip` to supersede `ifconfig`

IP is a newer subset of commands that is meant to take the place of ifconfig, some examples:

ip link show    List network interfaces
ip link set dev eth0 name wan   Rename interface eth0 to wan
ip link set dev eth0 up Bring interface eth0 up (or down)
ip addr show    List addresses for interfaces
ip addr add 1.2.3.4/24 brd + dev eth0   Add (or del) ip and mask (255.255.255.0)
ip route show   List routing table
ip route add default via 1.2.3.254  Set default gateway to 1.2.3.254
0
source

How to restore MAC address in Linux?

Maybe try removing then installing the module again?

sudo rmmod <NICmodule>
sudo insmod <NICmodule> 

Or maybe dropping the interface and bringing it back up?

sudo ifdown <interface> && sudo ifup <interface>
0
source

`ifconfig` isn't showing stats for an alx gigabit card

I could not find a way to fix ifconfig, but I used nstat and some clever awk computations in my conky script to achieve the same thing. So, instead of using "${downspeed eth0}/s" to obtain your download speed for eth0, you could use the following one-liner:

${execi 1 /sbin/nstat | grep -i IpExtInOctets | awk '{if($2>1024*1024){mb=$2/1024/1024;printf "%.2F MB", mb} else if($2>1024){kb=$2/1024;printf "%.2F KB", kb} else {printf "%d B", $2}}' }/s

You have to use execi with 1 second intervals. nstat shows the difference in bytes from its previous run. If you want to run it in longer than 1 sec intervals you may want to divide your result in awk to that number of seconds so you have an average.

For upload, use the IpExtOutOctets line from nstat. You can adapt this to your needs. Please remember that it will show all traffic in and out, not just for a specific interface. But I presume you only have one network interface, I have only one on my desktop PC. For multiple interfaces a different solution may be required.

UPDATE: however, be careful, running the command once for incoming then for outgoing immediately after the first one will show you zero for outgoing. Maybe some "sleep" commands here-and-there will fix this.

UPDATE2: here is how I solved the problem of showing both download and upload spedd in two differen commands and still about right. Adaptations to graphs and charts are needed, but for text only you can try this:

${goto 630}${font sansation:size=10,weight:bold}${color5} \
${texeci 2 /sbin/nstat | grep -i IpExtInOctets | awk '{if($2>1024*1024){mb=$2/1024/1024;printf "%.2F MB", mb} else if($2>1024){kb=$2/1024;printf "%.2F KB", kb} else {printf "%d B", $2}}' }/s \
${alignr 1}${color6} \
${texeci 2 sleep 1 && /sbin/nstat | grep -i IpExtOutOctets | awk '{if($2>1024*1024){mb=$2/1024/1024;printf "%.2F MB", mb} else if($2>1024){kb=$2/1024;printf "%.2F KB", kb} else {printf "%d B", $2}}' }/s

UPDATE: Or you could take both values at once and format them with awk for output.

U/D: ${execi 1 /sbin/nstat | grep -A1 -i IpExtInOctets | awk '{if($2>1024*1024){mb=$2/1024/1024;printf "%.2F MB/s ", mb} else if($2>1024){kb=$2/1024;printf "%.2F KB/s ", kb} else {printf "%d  B/s ", $2}}'}
0
source

What is the real capacity of a network device (ethtool - MiB or MB?)

Ethernet speeds are in base 10 units (10000000, 100000000, 100000000, etc) so that correct unit would be based on SI prefixes. For some time the IT industry has been moving to using SI prefixes. The notable (and logical) exception is computer memory / cache which is based in binary.

0
source

ppp0 strange default router address

The destination isn't the default gateway. PPP stands for 'point-to-point protocol' and this is exactly what you're seeing: the near-end point is 10.223.229.136, and the far end is 10.64.64.64.

Check your routing table (route -n): this will display the default gateway.

The 'all 1s' netmask means that there is in effect no subnet associated with the local address. Don't bother with classes of subnet: they haven't had any real-world meaning for many years.

0
source

What does eth0:cp1 refer to in ifconfig on CentOS?

These are subinterfaces and a method of adding additional IP addresses along with their subnets to an interface. The part after the colon is arbitrary.

iptables cannot reference subinterfaces, so any rules required would be based on IP addresses, but bound to the physical interface if required.

0
source

ifupdown: interface does not get properly configured

Check your scripts in dirs:

if-down.d
if-post-down.d
if-pre-up.d
if-up.d
interfaces.d

0
source

Configure IP v6 on Linux machine

You are missing some routing. You must tell the router to route all from fec0::/10 to your given interface.

But be aware that Site Local Addresses are deprecated.

0
source

Network conf - ever time must set ifconfig

(This assumes that you are running Mint, and that Mint didn't change anything from Debian on this matter)

You need an auto line:

auto eth1

Otherwise, the interface will not be handled by the init.d/networking script.

This way, the interface is started when networking is started, reconfigured if networking is reloaded/restarted and stopped when networking is stopped.

Alternatively, for hotplugged devices, you can use :

allow-hotplug eth1

This way, the device will be configured when it is plugged and unconfigured when unplugged. If the device is already plugged at boot, networking will start it, but will not touch it when networking is stopped/restarted/reloaded

Oh, and by the way, ifconfig is deprecated. I hope that your ìfupdown package is recent enough to use ip (from the iproute2 package) instead.

0
source

Linux: Any distro-independent way to change and persist IP settings?

Perhaps the most direct way would be to put your configuration in a bash script, then run the script at login.

How you have the script run will be distro-dependent but the script itself can be used on any Linux distro.

0
source

What does the field `Memory` mean in `ifconfig`?

Yes. The network card's onboard memory buffers are mapped into memory so the CPU can copy data into and out of them as the card sends and receives packets.

description

Ifconfig is used to configure the kernel-resident network interfaces. It is used at boot time to set up interfaces as necessary. After that, it is usually only needed when debugging or when system tuning is needed.

If no arguments are given, ifconfig displays the status of the currently active interfaces. If a single interface argument is given, it displays the status of the given interface only; if a single -a argument is given, it displays the status of all interfaces, even those that are down. Otherwise, it configures an interface.

options

-a

display all interfaces which are currently available, even if down

-s

display a short list (like netstat -i)

-v

be more verbose for some error conditions

interface

The name of the interface. This is usually a driver name followed by a unit number, for example eth0 for the first Ethernet interface. If your kernel supports alias interfaces, you can specify them with eth0:0 for the first alias of eth0. You can use them to assign a second address. To delete an alias interface use ifconfig eth0:0 down. Note: for every scope (i.e. same net with address/netmask combination) all aliases are deleted, if you delete the first (primary).

up

This flag causes the interface to be activated. It is implicitly specified if an address is assigned to the interface.

down

This flag causes the driver for this interface to be shut down.

[-]arp

Enable or disable the use of the ARP protocol on this interface.

[-]promisc

Enable or disable the promiscuous mode of the interface. If selected, all packets on the network will be received by the interface.

[-]allmulti

Enable or disable all-multicast mode. If selected, all multicast packets on the network will be received by the interface.

metric N

This parameter sets the interface metric.

mtu N

This parameter sets the Maximum Transfer Unit (MTU) of an interface.

dstaddr addr

Set the remote IP address for a point-to-point link (such as PPP). This keyword is now obsolete; use the pointopoint keyword instead.

netmask addr

Set the IP network mask for this interface. This value defaults to the usual class A, B or C network mask (as derived from the interface IP address), but it can be set to any value.

add addr/prefixlen

Add an IPv6 address to an interface.

del addr/prefixlen

Remove an IPv6 address from an interface.

tunnel aa.bb.cc.dd

Create a new SIT (IPv6-in-IPv4) device, tunnelling to the given destination.

irq addr

Set the interrupt line used by this device. Not all devices can dynamically change their IRQ setting.

io_addr addr

Set the start address in I/O space for this device.

mem_start addr

Set the start address for shared memory used by this device. Only a few devices need this.

media type

Set the physical port or medium type to be used by the device. Not all devices can change this setting, and those that can vary in what values they support. Typical values for type are 10base2 (thin Ethernet), 10baseT (twisted-pair 10Mbps Ethernet), AUI (external transceiver) and so on. The special medium type of auto can be used to tell the driver to auto-sense the media. Again, not all drivers can do this.

[-]broadcast [addr]

If the address argument is given, set the protocol broadcast address for this interface. Otherwise, set (or clear) the IFF_BROADCAST flag for the interface.

[-]pointopoint [addr]

This keyword enables the point-to-point mode of an interface, meaning that it is a direct link between two machines with nobody else listening on it.
If the address argument is also given, set the protocol address of the other side of the link, just like the obsolete dstaddr keyword does. Otherwise, set or clear the IFF_POINTOPOINT flag for the interface.

hw class address

Set the hardware address of this interface, if the device driver supports this operation. The keyword must be followed by the name of the hardware class and the printable ASCII equivalent of the hardware address. Hardware classes currently supported include ether (Ethernet), ax25 (AMPR AX.25), ARCnet and netrom (AMPR NET/ROM).

multicast

Set the multicast flag on the interface. This should not normally be needed as the drivers set the flag correctly themselves.

address

The IP address to be assigned to this interface.

txqueuelen length

Set the length of the transmit queue of the device. It is useful to set this to small values for slower devices with a high latency (modem links, ISDN) to prevent fast bulk transfers from disturbing interactive traffic like telnet too much.

address families

If the first argument after the interface name is recognized as the name of a supported address family, that address family is used for decoding and displaying all protocol addresses. Currently supported address families include inet (TCP/IP, default), inet6 (IPv6), ax25 (AMPR Packet Radio), ddp (Appletalk Phase 2), ipx (Novell IPX) and netrom (AMPR Packet radio).

files

/proc/net/socket
/proc/net/dev
/proc/net/if_inet6

notes

Since kernel release 2.2 there are no explicit interface statistics for alias interfaces anymore. The statistics printed for the original address are shared with all alias addresses on the same device. If you want per-address statistics you should add explicit accounting rules for the address using the ipchains(8) or iptables(8) command.

Interrupt problems with Ethernet device drivers fail with EAGAIN (SIOCSIIFLAGS: Resource temporarily unavailable) it is most likely a interrupt conflict. See http://www.scyld.com/expert/irq-conflict.html for more information.


bugs

While appletalk DDP and IPX addresses will be displayed they cannot be altered by this command.


see also

route , netstat , arp , rarp , ipchains, iptables , ifup , interfaces.
http://physics.nist.gov/cuu/Units/binary.html - Prefixes for binary multiples


authors

Fred N. van Kempen, <waltje[:at:]uwalt.nl.mugnet[:dot:]org>
Alan Cox, <Alan.Cox[:at:]linux[:dot:]org>
Phil Blundell, <Philip.Blundell[:at:]pobox[:dot:]com>
Andi Kleen
Bernd Eckenfels, <net-tools[:at:]lina.inka[:dot:]de>

How can this site be more helpful to YOU ?


give  feedback