pyratelog

personal blog
git clone git://git.pyratebeard.net/pyratelog.git
Log | Files | Refs | README

20220118-default_interface.md (1658B)


      1 #### TL;DR
      2 Alias to only show the default interface details
      3 ```
      4 alias iip="ip a s $(ip r | grep default | grep -oP '(?<=dev )[^ ]*')"
      5 ```
      6 
      7 ---
      8 
      9 I work on a lot of systems these days that run tools like docker or kubernetes, and with them a lot of virtual interfaces exist.  The number of interfaces can be as 10, it can be 200.  Whatever the number, when you want to quickly check the IP address of the system the output of `ip a` can be too much.
     10 
     11 If you know the default device name you can incant
     12 ```
     13 ip a show <device>
     14 ip a s eth0
     15 ```
     16 
     17 It use to be that the first ethernet interface was `eth0`, but this isn't always the case these days.  As a Linux sysadmin I mostly deal with Red Hat Enterprise Linux (RHEL) or CentOS systems.  The network interface naming convention was changed in RHEL 7 to use "[consistent network device naming](https://access.redhat.com/documentation/en-us/red_hat_enterprise_linux/7/html/networking_guide/ch-consistent_network_device_naming)".  The system now uses the bus-ID to create _predictable device names_.  The default device name now changes across systems.  Or maybe you don't want to scroll back through the output of 200 interfaces to find your IP.  Or maybe you use bonds on some systems but not others.
     18 
     19 Whatever the reason, it is too much effort.  We're sysadmins, our time is precious remember, and that is why I set this alias on my systems
     20 ```
     21 alias iip="ip a s $(ip r | grep default | grep -oP '(?<=dev )[^ ]*')
     22 ```
     23 
     24 Now when I want the default interface details I can run `iip` and be spared all the gumph.
     25 
     26 If you know of a sleeker way of doing this, or want to recommend any other good aliases let me know.