This useful one-liner will get your IP address from the command line very easily. This uses Google services and works very well.
4.4 Tue Jun 30 jason@Yog-Sothoth 0: $ dig TXT +short o-o.myaddr.l.google.com @ns1.google.com | sed -e 's/^"//' -e 's/"$//' 209.134.104.200 |
To list MAC addresses, use this command. This lists the neighbor table in the kernel. Using iproute2.
4.4 Tue Jun 30 jason@Yog-Sothoth 0: $ ip neigh 192.168.1.1 dev enp0s25 lladdr c8:14:51:5f:a9:47 REACHABLE fdc8:1451:5fa9:4700::1 dev enp0s25 lladdr c8:14:51:5f:a9:47 router STALE fe80::1 dev enp0s25 lladdr c8:14:51:5f:a9:47 router STALE |
To show the routing table, use this simple command.
4.4 Tue Jun 30 jason@Yog-Sothoth 0: $ ip route show default via 192.168.1.1 dev enp0s25 proto dhcp metric 100 169.254.0.0/16 dev enp0s25 scope link metric 1000 192.168.1.0/24 dev enp0s25 proto kernel scope link src 192.168.1.2 metric 100 192.168.122.0/24 dev virbr0 proto kernel scope link src 192.168.122.1 linkdown |
This is how to get just the IP address of the currently active network interface.
4.4 Tue Jun 30 jason@Yog-Sothoth 0: $ ip a | awk '/inet / { print $2 }' | sed -n 2p | cut -d "/" -f1 192.168.1.2 |
That would be a very useful one-liner to use in a script. More information here: https://securitronlinux.com/debian-testing/how-to-get-just-the-ip-address-or-the-interface-name-with-linux/.
And finally, this interesting command will print only the MAC address of the network interface.
4.4 Tue Jun 30 jason@Yog-Sothoth 0: $ ip link | sed -n 4p | awk '{print $2}' d0:50:99:0d:ab:0f |
I tried it on another machine and it works fine.
┌─[jason@darkstar]─[~] └──╼ $ip link | sed -n 4p | awk '{print $2}' 90:fb:a6:83:0d:f6 |
This shows the Ethernet adapter only.
And yet another way to get the currently active network interface.
┌─[✗]─[jason@darkstar]─[~] └──╼ $sudo route | grep '^default' | grep -o '[^ ]*$' [sudo] password for jason: enp2s0 |