6

ifconfig can be used on linux to check network transferred bytes in each interface like below:

eth0      Link encap:Ethernet  HWaddr 02:42:ac:11:00:05  
          inet addr:172.17.0.5  Bcast:172.17.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:20782 errors:0 dropped:0 overruns:0 frame:0
          TX packets:16290 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0 
          RX bytes:28527924 (28.5 MB)  TX bytes:1386216 (1.3 MB)

the RX bytes and TX bytes shows the current data transferred in the eth0 interface. However, the ifconfig on Mac doesn't show this information for me.

Is there an equivalent command on Mac? I am looking for a native command without installing 3rd party library.

1 Answer 1

6

Absolutely there is.
I was going to suggest the GUI alternative, through the Network Utility's Info Tab or the Option + Click onto the WiFi icon in the menu bar to bring up current statistics. A set of easy to follow steps that are well-documented in this article.

You are however asking for a "native command" and thus interested in the following:

  • Command: netstat -i : contains Incoming and Outgoing Packets (just another name for RX and TX). By default every interface returns its data but you can easily narrow it down using either netstat -i | grep en0.
  • Command: netstat -I en1 (note the capital -I flag) will produce an output for only that specified interface (here, en0). This is a more direct approach that does not require further filtering such as the grep operation above.

Let me know if you have success with any combination of the above, or if there is anything you don't understand/want to refine.


Additional Explanation
In a comment, you mention seeing three lines of output when querying the interface using netstat -I, and ask how to handle that data. They are all the same values because they tie back to the same interface, read one line only (usually the first) and don't add them all together as you suggested.

Why?
In the Terminal output, those 3 lines are referring to the same interface because multiple addresses are associated with it. In plain terms, it is much like having multiple phone numbers forwarding their calls to your cell phone instead of ringing at their physical location.

In my case (on an iMac, querying en1), the first line's Address column shows the MAC address of my (ethernet) network card. Which is typically referred to as the most reliable out of the three entries because it is hardcoded and unique to the network card itself (hence won't change unless the physical unit is replaced).
The second line is (at least in my case) associated with an IPv6, while the third is an IPv4 address. These are susceptible to change depending on your network configuration and location. That's why the first line is usually the most reliable out of all. Think of line 1 as your cell phone to which lines 2 and 3 are forwarding the calls - it is also the only entry with error (Ierrs and Oerrs) logging.

Why are the errors only logged there?
Well, think of it as a direct reference/shortcut, if that's all they are (logical connections), they do not exist physically - the only physical interface is where the MAC address resides and thus the only location for packets to be verified and error reporting to take place.

I really hope that made sense, I know you were just after the procedure at the top, but I thought a bit of an explanation won't hurt. Is that helpful in any way?

10
  • 1
    macOS does not use e,g, eth0 or eth1, it uses e.g. en0 or en1, etc. Feb 5, 2018 at 12:26
  • I see this command outputs Ipkts and Opkts. Do they mean input and output? I couldn't find an explanation from its man. Feb 5, 2018 at 22:40
  • It's Incoming (RX) and Outgoing (TX) Packets.
    – ProGrammer
    Feb 6, 2018 at 0:32
  • I mean the output from the command doesn't have RX or TX. it only has Ipkts and Opkts. Do you mean these two are the ones I need to look at? Feb 7, 2018 at 2:01
  • @ZhaoYi Correct, you need to look at those values. As I mentioned previously, Ipkts is synonymous with 'Incoming Packets' or RX while Opkts is synonymous with 'Outgoing Packets' or TX. Does that answer your question or do you require further clarification?
    – ProGrammer
    Feb 7, 2018 at 2:08

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .