Whether you need to connect to your Linux machine via SSH, set up a web server, or configure a local firewall, the very first piece of information you need is the server’s IP address. If you are running Ubuntu Server without a graphical user interface, you cannot simply click on a Wi-Fi or Ethernet icon to find this information.
In this guide, we will show you the fastest and most reliable terminal commands to find both your local (internal) IP address and your public (external) IP address on Ubuntu.
Understanding Local vs. Public IP Addresses
Before you run any commands, it is crucial to understand which IP address you actually need:
- Local IP Address (Internal): This is the address assigned to your Ubuntu machine by your home or office router (e.g.,
192.168.1.50). You use this address to connect to the server from another computer on the same network. - Public IP Address (External): This is the address assigned to your modem by your Internet Service Provider. You use this address if you are trying to connect to your Ubuntu server from outside your home (e.g., while sitting in a coffee shop).
Method 1: Find Your Local IP Address (The Modern Command)
Historically, Linux users relied on the ifconfig command. However, this command is now deprecated and is no longer installed by default on modern versions of Ubuntu. The correct, modern replacement is the ip command.
- Open your terminal or log into your server console.
- Type the following command and press Enter:
ip a - The terminal will print a block of text detailing all your network interfaces. Look for the block labeled eth0 (if you are on a wired Ethernet connection) or wlan0 (if you are on Wi-Fi). Note that on modern systems, these interfaces might be named enp3s0 or wlp2s0.
- Look for the line that begins with the word
inet. The numbers immediately following it (before the slash) represent your local IP address. For example:
inet 192.168.1.15/24 - In this example, your local IP address is 192.168.1.15.
Method 2: Find Your Local IP Address (The Cleanest Output)
If the ip a command produces too much technical jargon and you simply want the IP address printed on the screen with no extra text, you can use the hostname command.
- In your terminal, type:
hostname -I - Press Enter. The terminal will output a single line containing only your local IP addresses, separated by spaces. If your server is connected to both Ethernet and Wi-Fi, it will print both addresses.
Method 3: Find Your Public IP Address
Your Ubuntu server does not actually know its own public IP address. To find it, the server must reach out to an external website on the internet and ask, “What IP address do you see me connecting from?”
You can do this effortlessly using the curl command, which downloads data from a URL directly in the terminal.
- In your terminal, type the following command to query a free IP identification service:
curl ifconfig.me - Press Enter. The terminal will print your public IP address (e.g.,
203.0.113.45). - Alternatively, if
ifconfig.meis offline, you can use a secondary service by typing:
curl icanhazip.com
By keeping these simple commands in your administrative toolkit, you can instantly identify your Ubuntu server’s network location, regardless of whether you are configuring a local database or opening a port to the outside world.