How to get just the adapter name when querying the adapter with ip a. This is a simple trick, this one-liner is not that elegant, but it does work. This allows me to get just the name of the adapter, and not any other extraneous information.
4.4 Wed Aug 07 jason@Yog-Sothoth 0: $ ip a | awk '/: / { print $2 }' | sed -n 2p | cut -d ":" -f1 enp3s0 |
This example, shows how to get just the IP address of the current machine.
4.4 Wed Aug 07 jason@Yog-Sothoth 0: $ ip a | awk '/inet / { print $2 }' | sed -n 2p | cut -d "/" -f1 192.168.1.5 |
How to return just the MAC address of an adapter in Linux easily.
4.4 Wed Aug 07 jason@Yog-Sothoth 0: $ ip a | awk '/ether / { print $2 }' | sed -n 2p | cut -d "/" -f1 d0:50:99:0d:ab:0f |
Use this command on an Internet connected machine to get the Internet facing IP address of your location.
4.4 Wed Aug 07 jason@Yog-Sothoth 0: $ curl ifconfig.io |
Get comprehensive information about your IP address.
4.4 Wed Aug 07 jason@Yog-Sothoth 0: $ ipcalc `ip a | awk '/inet / { print $2 }' | sed -n 2p` Address: 192.168.1.5 11000000.10101000.00000001. 00000101 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000 Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111 => Network: 192.168.1.0/24 11000000.10101000.00000001. 00000000 HostMin: 192.168.1.1 11000000.10101000.00000001. 00000001 HostMax: 192.168.1.254 11000000.10101000.00000001. 11111110 Broadcast: 192.168.1.255 11000000.10101000.00000001. 11111111 Hosts/Net: 254 Class C, Private Internet |
Split our network into 3 and display all the required information.
4.4 Wed Aug 07 jason@Yog-Sothoth 0: $ ipcalc `ip a | awk '/inet / { print $2 }' | sed -n 2p` --s 16 16 24 Address: 192.168.1.5 11000000.10101000.00000001. 00000101 Netmask: 255.255.255.0 = 24 11111111.11111111.11111111. 00000000 Wildcard: 0.0.0.255 00000000.00000000.00000000. 11111111 => Network: 192.168.1.0/24 11000000.10101000.00000001. 00000000 HostMin: 192.168.1.1 11000000.10101000.00000001. 00000001 HostMax: 192.168.1.254 11000000.10101000.00000001. 11111110 Broadcast: 192.168.1.255 11000000.10101000.00000001. 11111111 Hosts/Net: 254 Class C, Private Internet 1. Requested size: 16 hosts Netmask: 255.255.255.224 = 27 11111111.11111111.11111111.111 00000 Network: 192.168.1.0/27 11000000.10101000.00000001.000 00000 HostMin: 192.168.1.1 11000000.10101000.00000001.000 00001 HostMax: 192.168.1.30 11000000.10101000.00000001.000 11110 Broadcast: 192.168.1.31 11000000.10101000.00000001.000 11111 Hosts/Net: 30 Class C, Private Internet 2. Requested size: 16 hosts Netmask: 255.255.255.224 = 27 11111111.11111111.11111111.111 00000 Network: 192.168.1.32/27 11000000.10101000.00000001.001 00000 HostMin: 192.168.1.33 11000000.10101000.00000001.001 00001 HostMax: 192.168.1.62 11000000.10101000.00000001.001 11110 Broadcast: 192.168.1.63 11000000.10101000.00000001.001 11111 Hosts/Net: 30 Class C, Private Internet 3. Requested size: 24 hosts Netmask: 255.255.255.224 = 27 11111111.11111111.11111111.111 00000 Network: 192.168.1.64/27 11000000.10101000.00000001.010 00000 HostMin: 192.168.1.65 11000000.10101000.00000001.010 00001 HostMax: 192.168.1.94 11000000.10101000.00000001.010 11110 Broadcast: 192.168.1.95 11000000.10101000.00000001.010 11111 Hosts/Net: 30 Class C, Private Internet Needed size: 96 addresses. Used network: 192.168.1.0/25 Unused: 192.168.1.96/27 192.168.1.128/25 |
This is 3 networks, 2 with 16 addresses, and one with 24. This also displays the required amount of addresses for the whole thing, and unused addresses as well.