IP address command to show global and local IPs

Commands to show the global Internet IP address and the local IPv4 or IPv6 addresses in the CLI and in the terminal

IP address command to show global and local IPs on LinuxDisplay the global IP with which I surf in the Internet, this does simply in the command line for Windows, Linux and macOS

Show my IP address with which I surf in the internet. Run the following command in the Linux terminal to output the public IP address.

$ curl echo.ipline.ch

To show the local private IP address with the following command:

$ /sbin/ifconfig ens192 | grep 'inet' | cut -d: -f2 | awk '{print $2}'

Note. output from Debian 11 in System Locale LANG=en_US.UTF-8.

For Linux operating systems installed in German:

$ /sbin/ifconfig ens192 | grep 'inet Adresse' | cut -d: -f2 | awk '{print $1}'

Note: ipconfig is deprecated, for current distributions, such as Debian, Ubuntu or Rocky and Fedora, the ip command is used.

This command show IPv4 addresses using -4:

$ ip -4 addr

The clear and concise output as follows:

$ ip -4 addr | grep -oP '(?<=inet\s)\d+(\.\d+){3}'

Only IPv6 addresses should be output:

$ ip -6 addr | grep -oP '(?<=inet6\s)[\da-f:]+'

The “hostname” command will also show the IP address:

$ hostname -i

Show IP addresses on macOS

IP address command to show global and local IPs on macOS


macOS returns the IP address from the terminal with the following command

$ /sbin/ifconfig en0 | awk '/inet /{print $2}'

The hostname command is also available on macOS.

$ hostname -I

Show IP addresses on Windows

IP address command to show global and local IPs on Windows

Windows use ipconfig to show IP address

Show the local network configuration in Windows command prompt.

C:\> ipconfig /all

If only the IPv4 addresses should be output.

C:\> ipconfig | findstr /i "ipv4"

Individual values can be queried using Windows management interface commands.

C:\> wmic NICCONFIG GET IPAddress

This query e.g. show the IP address of each interface.

C:\> netsh interface ipv4 show address

Get IP addresses in the PowerShell with Get-NetIPAddress

PS C:\> Get-NetIPAddress | ft

With the AddressFamily option, only IPV4 addresses will be displayed.

PS C:\> Get-NetIPAddress -AddressFamily IPv4 | ft

By typing Get-NetIPAddress -? all parameters to the cmdlet are output.

Example: show IP address in the PowerShell

Show public IP address and local private IP address in the PowerShell.

$GlobalIP = Invoke-RestMethod -Uri http://echo.ipline.ch
$PrivatIP = $(Get-NetIPAddress -InterfaceIndex 11 -AddressFamily IPv4).IPAddress
Write-Host "My public IPv4 address is:" $GlobalIP
Write-Host "My privat IPv4 address is:" $PrivatIP

Wake On Lan (WOL)

Wake on LAN (WOL) using on Linux, Windows, and Synology

Wake On Lan

To start remote devices – Wake on LAN (WOL) is a standard released by AMD in collaboration with HPE in 1995 to boot off computers from the NIC that support these ACPI. A general requirement for WOL is that the network card continues to be powered by the power supply’s standby power, even when the computer is turned off.

The network card is waiting for a magic packet to be received. The data packet is either addressed directly to the network card or is sent as broadcast. It contains the hexadecimal value FF six times in a row; Immediately afterwards, the continuous repetition of the MAC address of the network card of the respective target system appears 16 times.

WOL on Linux

Under GNU/Linux there is the package etherwake with the “wakeonlan” tool, which is provided as follows if it is not already installed.

$ sudo apt install etherwake

The Linux command to start a computer with WOL is wakeonlan.

$ wakeonlan -i 10.10.10.1 00:11:22:33:44:55
Sending magic packet to 10.10.10.1 with 00:11:22:33:44:55

Ubuntu and Debian awaken computers with wakeonlan.

$ wakeonlan 00:00:33:44:55:66
Sending magic packet to 255.255.255.255:9 with 00:22:33:44:55:66

quote For help with options, use the command: etherwake -u

Fedora and RHEL on the other hand awakens with ether-wake.

$ sudo ether-wake -i eno1 00:11:22:33:44:55

quote it -i eno1 means the Ethernet interface here.

The MAC address can be obtained using the arp command as follows.

$ ping -c 4 10.10.10.1 && arp -n

WOL on Synology

Synology has its own tool with synonet in the Busybox Shell.

$ synonet --wake xx:xx:xx:xx:xx:xx ethX

where -i eno1 means the Ethernet interface.

WOL for Windows

Microsoft Windows does not have a Wake on LAN onboard, a reliable WOL offers WakeMeOnLan from Nirsoft here.

Microsoft Windows does not have a WOL onboard, a reliable WOL offers WakeMeOnLan from Nirsoft here.
Wakemeonlan

WOL on macOS

Since macOS also comes with Python by default, you can get a script, the following lines allow a Wake On LAN on the Mac.

#!/usr/bin/env python

import socket
import sys

if len(sys.argv) < 3:
    print "Usage: wake.py <IP> <MAC>   (example: 192.168.1.255 00:11:22:33:44:55)"
    sys.exit(1)

mac = sys.argv[2]
data = ''.join(['FF' * 6, mac.replace(':', '') * 16])
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
sock.sendto(data.decode("hex"), (sys.argv[1], 9))

Save the script and run it from the OSX terminal.

python wake.py 192.168.1.255 00:11:22:33:44:55

How it works!

The magic packet is sent on the data link layer (layer 2 in the OSI model). When sent, is broadcast to all attached devices on a given network, using the network broadcast address. The IP address (which relates to the internet layer) is not used. Because Wake-on-LAN is built upon broadcast messaging, it can generally only be used within a subnet. Wake-on-LAN can, however, operate across any network in practice, given appropriate configuration and hardware, including remote wake-up across the Internet.

In order for Wake-on-LAN to work, parts of the network interface need to stay on. This consumes a small amount of standby power. To further reduce power consumption, the link speed is usually reduced to the lowest possible speed (e.g. a Gigabit Ethernet NIC maintains only a 10 Mbit/s link). Disabling Wake-on-LAN, when not needed, can slightly reduce power consumption on computers that are switched off but still plugged into a power socket. The power drain becomes a consideration on battery-powered devices such as laptops as this can deplete the battery even when the device is completely shut down.