Learn how to get your public IP address in Ubuntu Terminal with our easy-to-follow guide. With images to help you every step of the way, you'll be able to find your public IP address in minutes.
There are a few different ways to get your public IP address in the Linux Ubuntu terminal.
Method 1: Using the curl
command
The curl
command is a versatile tool that can be used to transfer data over the network. To get your public IP address using the curl
command, run the following command in a terminal window:
curl ifconfig.me
This will print your public IP address to the console.
Method 2: Using the dig
command
The dig
command is a DNS lookup tool. To get your public IP address using the dig
command, run the following command in a terminal window:
dig +short myip.opendns.com @resolver1.opendns.com
This will also print your public IP address to the console.
Method 3: Using the ip
command
The ip
command is a network interface configuration tool. To get your public IP address using the ip
command, run the following command in a terminal window:
ip addr show | grep -oP '(?<=inet )\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}'
This will print all of the IP addresses assigned to your network interfaces. Your public IP address will be the one that is not assigned to a loopback interface (127.0.0.1) or a local network interface (192.168.0.0/24 or 10.0.0.0/8).
Conclusion
Which method you choose to use to get your public IP address in the Linux Ubuntu terminal is up to you. All three methods are simple and effective.