How to Find Your Public and Private IP Addresses in Debian 12 Bookworm System

In this guide, you’ll learn how to find your public and private IP addresses in Debian 12 Bookworm.

In a networked environment, identifying your system’s IP addresses is crucial for troubleshooting, configuring services, or setting up network security measures. Debian 12 “Bookworm” offers several methods to determine both your public and private IP addresses efficiently.

This guide explores different approaches to finding these addresses using command-line utilities and online services. We will cover:

  • Understanding the difference between public and private IP addresses
  • Finding your private IP address using built-in Debian tools
  • Finding your public IP address using terminal commands
  • Additional considerations for network troubleshooting

Understanding Public and Private IP Addresses

Private IP Address

A private IP address is assigned to a device within a local network (LAN). It allows communication between devices within the same network but is not routable on the internet. These addresses typically fall within the following ranges:

  • 192.168.0.0 – 192.168.255.255 (Common for home and office networks)
  • 10.0.0.0 – 10.255.255.255 (Often used in large organizations)
  • 172.16.0.0 – 172.31.255.255 (Used in various enterprise setups)

Public IP Address

A public IP address is assigned by an Internet Service Provider (ISP) and is used to identify your device on the internet. This address is globally unique and can be seen by external servers.


Finding Your Private IP Address in Debian 12

Debian provides multiple built-in tools to determine your private IP address. Below are some of the most common methods.

Method 1: Using ip Command

The ip command is the preferred way to retrieve network interface details in modern Linux distributions.

ip addr show

Or a more concise command:

ip -4 addr show | grep inet

Example output:

inet 192.168.1.100/24 brd 192.168.1.255 scope global dynamic eth0

Here, 192.168.1.100 is your private IP address.

Method 2: Using hostname Command

The hostname -I command provides all IP addresses assigned to your machine:

hostname -I

Example output:

192.168.1.100

Method 3: Using ifconfig Command (Deprecated)

The ifconfig tool is part of the net-tools package and is deprecated in favor of the ip command. If still installed, you can use:

ifconfig

or

ifconfig | grep inet

Method 4: Using nmcli (NetworkManager Command Line Interface)

If you are using NetworkManager, you can use:

nmcli device show | grep IP4.ADDRESS

Example output:

IP4.ADDRESS[1]: 192.168.1.100/24

Finding Your Public IP Address in Debian 12

Your public IP address is the address assigned to your network by your ISP. To find it, you can use several methods that interact with external services.

Method 1: Using curl with External Web Services

Using curl, you can retrieve your public IP address from various external services.

curl -s ifconfig.me

or

curl -s icanhazip.com

or

curl -s checkip.amazonaws.com

All of these commands return your public IP address directly.

Method 2: Using wget

If curl is unavailable, wget can be used instead:

wget -qO- ifconfig.me

Method 3: Using dig Command (From dnsutils Package)

The dig command queries a DNS resolver to obtain your public IP address.

dig +short myip.opendns.com @resolver1.opendns.com

Example output:

203.0.113.45

Method 4: Using ip Command with STUN Server

STUN (Session Traversal Utilities for NAT) servers help identify your external IP address:

ip -brief route get 1.1.1.1 | awk '{print $7}'

This returns your public IP address by determining how your system reaches an external destination.


Additional Considerations for Network Troubleshooting

Checking Active Network Interfaces

To list active network interfaces, use:

ip link show

or

nmcli device status

Testing Internet Connectivity

To check if your Debian system has internet access, you can ping a well-known server:

ping -c 4 8.8.8.8

Identifying the Gateway IP Address

Your router’s IP address can be determined using:

ip route | grep default

Example output:

default via 192.168.1.1 dev eth0 proto static

Here, 192.168.1.1 is your gateway (router’s IP address).


Conclusion

Finding your private and public IP addresses in Debian 12 “Bookworm” is straightforward using built-in commands and external services. While ip and hostname are efficient for private IP retrieval, curl, dig, and wget provide quick access to your public IP.

Understanding these methods is essential for network troubleshooting, server management, and security configurations. Keeping track of your system’s IP addresses ensures seamless communication within your network and with external servers.