How to Get Public IP from Terminal on Ubuntu 22.04 (2024)

An Internet Protocol commonly referred as IP address is a numerical representation of a device identification number connected with the Internet. It’s a unique ID that separates one device from another connected to the network thus is different for each device. There are usually two types of IP address; private and public. The private IP address is the address that router assigns to each device while public IP address is assigned by Internet Service Provider (ISP).

In this guide, we will check out how to get public IP from a terminal on Ubuntu 22.04.

Get Public IP from Terminal on Ubuntu 22.04

There are lots of ways to get the IP address of a device which is connected to the Internet. Here we are finding the public IP from the terminal on Ubuntu.

So, let’s discuss several ways through which you can get public IP from the terminal on Ubuntu 22.04.

1: Use Dig command to get public IP address

Dig is an excellent utility that allows Linux users to get public IP from a terminal. The Dig along with the OpenDNS will help you in getting your public IP address on the terminal. The below-given command will be used for this purpose:

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

How to Get Public IP from Terminal on Ubuntu 22.04 (1)

2: Use host command to get public IP address

You can also find the IP address using the host command that gives you a public IP address through DNS lookups. Run the following host command to get a public IP address:

How to Get Public IP from Terminal on Ubuntu 22.04 (2)

3: Use wget command to get IP address

You can also get a public IP address using the wget piped with xarg command which is shown below:

$ wget -qO- http://ipecho.net/plain | xargs echo

How to Get Public IP from Terminal on Ubuntu 22.04 (3)

Or use the following command incanzip service to get a public IP address:

$ wget -qO- icanhazip.com

How to Get Public IP from Terminal on Ubuntu 22.04 (4)

There is another service as well that utilizes the wget command to provide you the public IP address:

$ wget -qO- ifconfig.co

How to Get Public IP from Terminal on Ubuntu 22.04 (5)

You can also utilize wget command with ifconfig.me service to get the public IP address:

$ wget -qO- ifconfig.me | xargs echo

How to Get Public IP from Terminal on Ubuntu 22.04 (6)

4: Use curl command to get IP address

Another way to get a public IP address from the terminal on Ubuntu is using the curl command. However, first you will need to install curl using the following command:

$ sudo apt install curl

How to Get Public IP from Terminal on Ubuntu 22.04 (7)

Once curl is installed, you can then use the following command with ifconfig.co to get a public IP address:

$ curl ifconfig.co

How to Get Public IP from Terminal on Ubuntu 22.04 (8)

You can also use the curl command with ifconfig.me and it will give the public IP address on the terminal:

$ curl ifconfig.me && echo

How to Get Public IP from Terminal on Ubuntu 22.04 (9)

Or you can use the following curl command with icanhazip service to get public IP on your Ubuntu 2.04 terminal:

$ curl icanhazip.com && echo

How to Get Public IP from Terminal on Ubuntu 22.04 (10)

Conclusion

The public IP address is an address that you received from the internet service provider. It is always known to the IPS. There are numerous methods to find the public IP address, all are discussed in this guide. Try all those commands as they need a third-party service to provide your public IP address.

How to Get Public IP from Terminal on Ubuntu 22.04 (2024)

FAQs

How to Get Public IP from Terminal on Ubuntu 22.04? ›

For wired connections, enter ipconfig getifaddr en1 into the Terminal and your local IP will appear. To see your public IP address in the Mac Terminal, type curl ifconfig.me and your public IP will display.

How do I find my public IP address in Ubuntu? ›

Find your IP address
  1. Open the Activities overview and start typing Settings.
  2. Click on Settings.
  3. Click on Network in the sidebar to open the panel. If more than one type of wired connected is available, you might see names like PCI Ethernet or USB Ethernet instead of Wired.
  4. Click the.

How do I find my public IP address in terminal? ›

For wired connections, enter ipconfig getifaddr en1 into the Terminal and your local IP will appear. To see your public IP address in the Mac Terminal, type curl ifconfig.me and your public IP will display.

How to set IP address in Ubuntu Server 22.04 command line? ›

Setting a Static IP Address on Ubuntu Server 22.04
  1. eth0: is the name of my network interface - yours may differ.
  2. Under addresses: is the static IP to set, you'll need to use CIDR notation, so /24 is 255.255. ...
  3. DNS servers are configured under nameservers: multiple servers should be command separated.
Jan 26, 2023

How do I access my public IP? ›

Find your IP address
  1. Open a web browser (such as Chrome, Firefox, or any browser of your choice).
  2. Visit one of the following websites: whatsmyip.org. whatismyip.com.
  3. Either of these web pages will detect and display the public IP address of your network.

How to check public IP in Linux by command? ›

The following commands will get you the IP address list to find public IP addresses for your machine:
  1. curl ifconfig.me.
  2. curl -4/-6 icanhazip.com.
  3. curl ipinfo.io/ip.
  4. curl api.ipify.org.
  5. curl checkip.dyndns.org.
  6. dig +short myip.opendns.com @resolver1.opendns.com.
  7. host myip.opendns.com resolver1.opendns.com.
  8. curl ident.me.

How do I find my public and private IP address? ›

To quickly view your public IP address, go to https://www.google.com, type "What's my IP address?" and click the search button. Your public IP address is visible to other people on the internet, while your private IP address is only used on your local network.

What is my public IP in Linux? ›

Use dig command for determining my public IP address Linux:

Type the following dig (domain information groper) command on a Linux, OS X, or Unix-like operating systems to see your own public IP address assigned by the ISP: $ dig +short myip.opendns.com @resolver1.opendns.com.

How do I trace an IP address in terminal? ›

How to Trace Route an IP Address (Windows/Mac/Linux)
  1. Open Command Prompt (Terminal or Mac OS X or Linux users).
  2. Using your server's IP address, enter the following command: tracert 0.0.0.0. For Terminal users, the full command is used: traceroute 0.0.0.0.

How to configure public IP address on Ubuntu server? ›

How to Set a Static IP Using the GUI
  1. Search for settings .
  2. Click on either Network or Wi-Fi tab, depending on the interface you would like to modify.
  3. To open the interface settings, click on the gear icon next to the interface name.
  4. Select “Manual” in the IPV4 tab and enter your static IP address, Netmask and Gateway.
Mar 2, 2023

What is the command for IP address in Ubuntu terminal? ›

Summary
DescriptionCommand
Print only IP address using hostname commandhostname -I
To check your public IP address (Need curl installed)curl ifconfig.me
Display IP Address with Network Manager toolnmcli -p device show
Use the ifconfig command to display the IP address (Need net-tools installed )ifconfig -a
1 more row
Mar 27, 2023

What is the ipconfig command in Ubuntu? ›

ipconfig on Ubuntu

The ifconfig command is equivalent to the ipconfig command. The ifconfig command will display us the basic information of the network of our adapters in Ubuntu. The command is as follows: $ ifconfig.

How to configure IP in Ubuntu 20.04 CLI? ›

  1. For configuring static IP Address in Ubuntu Server you need to make netplan configuration changes in /etc/netplan/ directory: ...
  2. Now go and edit the configuration file there named "00-installer-config.yaml" and add below configuration for static IP address: (Bold are added lines) ...
  3. Apply added configurations:
Mar 30, 2023

What is the public IP address of localhost? ›

Therefore, usually, localhost is a mapping to the address 127.0. 0.1 in IPv4 (or ::1, in IPv6). This is why we type http://localhost in the browser when accessing a website hosted on our local machine.

Which IP address is a public IP address? ›

A public IP address is an IP address that can be accessed directly over the internet and is assigned to your network router by your internet service provider (ISP). Your personal device also has a private IP that remains hidden when you connect to the internet through your router's public IP.

Is 192.168 a public IP? ›

192.168.

Note that only a portion of the “172” and the “192” address ranges are designated for private use. The remaining addresses are considered “public,” and thus are routable on the global Internet.

How do I find my public IP address on my Mac? ›

The simplest method is to use the Network pane of System Settings:
  1. Click on the Apple menu and choose System Settings.
  2. Select Network.
  3. Click on the type of network you're using to connect to the internet. ...
  4. Choose Details next to the network to which you're connected.
  5. In the window that opens, you'll see an IP address.
Dec 13, 2023

What is the IP address for a public address? ›

A public IP address is a unique IP address assigned to your network router by your internet service provider and can be accessed directly over the internet. A private IP address is a unique address that your network router assigns to your device. It is used within a private network to connect securely to other devices.

Top Articles
Latest Posts
Article information

Author: Kieth Sipes

Last Updated:

Views: 5981

Rating: 4.7 / 5 (47 voted)

Reviews: 94% of readers found this page helpful

Author information

Name: Kieth Sipes

Birthday: 2001-04-14

Address: Suite 492 62479 Champlin Loop, South Catrice, MS 57271

Phone: +9663362133320

Job: District Sales Analyst

Hobby: Digital arts, Dance, Ghost hunting, Worldbuilding, Kayaking, Table tennis, 3D printing

Introduction: My name is Kieth Sipes, I am a zany, rich, courageous, powerful, faithful, jolly, excited person who loves writing and wants to share my knowledge and understanding with you.