如何在 Ubuntu 中检查你的 IP 地址
IP
不知道你的 IP 地址是什么？以下是在 Ubuntu 和其他 Linux 发行版中检查 IP 地址的几种方法。


![](/data/attachment/album/201909/05/061519lz58opfcjp4pj0c1.png)


### 什么是 IP 地址？


**互联网协议地址**（通常称为 **IP 地址**）是分配给连接到计算机网络的每个设备（使用互联网协议）的数字标签。IP 地址用于识别和定位机器。


**IP 地址**在网络中是*唯一的*，使得所有连接设备能够通信。


你还应该知道有两种**类型的 IP 地址**：**公有**和**私有**。**公有 IP 地址**是用于互联网通信的地址，这与你用于邮件的物理地址相同。但是，在本地网络（例如使用路由器的家庭）的环境中，会为每个设备分配在该子网内唯一的**私有 IP 地址**。这在本地网络中使用，而不直接暴露公有 IP（路由器用它与互联网通信）。


另外还有区分 **IPv4** 和 **IPv6** 协议。**IPv4** 是经典的 IP 格式，它由基本的 4 部分结构组成，四个字节用点分隔（例如 127.0.0.1）。但是，随着设备数量的增加，IPv4 很快就无法提供足够的地址。这就是 **IPv6** 被发明的原因，它使用 **128 位地址**的格式（与 **IPv4** 使用的 **32 位地址**相比）。


### 在 Ubuntu 中检查你的 IP 地址（终端方式）


检查 IP 地址的最快和最简单的方法是使用 `ip` 命令。你可以按以下方式使用此命令：



```
ip addr show
```

它将同时显示 IPv4 和 IPv6 地址：


![Display IP Address in Ubuntu Linux](/data/attachment/album/201909/05/061520f07p0z95qz4rxpi5.png)


实际上，你可以进一步缩短这个命令 `ip a`。它会给你完全相同的结果。



```
ip a
```

如果你希望获得最少的细节，也可以使用 `hostname`：



```
hostname -I
```

还有一些[在 Linux 中检查 IP 地址的方法](https://linuxhandbook.com/find-ip-address/)，但是这两个命令足以满足这个目的。


`ifconfig` 如何？


老用户可能会想要使用 `ifconfig`（net-tools 软件包的一部分），但该程序已被弃用。一些较新的 Linux 发行版不再包含此软件包，如果你尝试运行它，你将看到 ifconfig 命令未找到的错误。


### 在 Ubuntu 中检查你的 IP 地址（GUI 方式）


如果你对命令行不熟悉，你还可以使用图形方式检查 IP 地址。


打开 Ubuntu 应用菜单（在屏幕左下角**显示应用**）并搜索**Settings**，然后单击图标：


![Applications Menu Settings](/data/attachment/album/201909/05/061521sx6mepmlolrm66px.jpg)


这应该会打开**设置菜单**。进入**网络**：


![Network Settings Ubuntu](/data/attachment/album/201909/05/061522artoiggzfrbr2oyi.jpg)


按下连接旁边的**齿轮图标**会打开一个窗口，其中包含更多设置和有关你网络链接的信息，其中包括你的 IP 地址：


![IP Address GUI Ubuntu](/data/attachment/album/201909/05/061523cb0wm44bmop313we.png)


### 额外提示：检查你的公共 IP 地址（适用于台式计算机）


首先，要检查你的**公有 IP 地址**（用于与服务器通信），你可以[使用 curl 命令](https://linuxhandbook.com/curl-command-examples/)。打开终端并输入以下命令：



```
curl ifconfig.me
```

这应该只会返回你的 IP 地址而没有其他多余信息。我建议在分享这个地址时要小心，因为这相当于公布你的个人地址。


**注意：** 如果 `curl` 没有安装，只需使用 `sudo apt install curl -y` 来解决问题，然后再试一次。


另一种可以查看公共 IP 地址的简单方法是在 Google 中搜索 “ip address”。


### 总结


在本文中，我介绍了在 Uuntu Linux 中找到 IP 地址的不同方法，并向你概述了 IP 地址的用途以及它们对我们如此重要的原因。


我希望你喜欢这篇文章。如果你觉得文章有用，请在评论栏告诉我们！




---


via: <https://itsfoss.com/check-ip-address-ubuntu/>


作者：[Sergiu](https://itsfoss.com/author/sergiu/) 选题：[lujun9972](https://github.com/lujun9972) 译者：[geekpi](https://github.com/geekpi) 校对：[wxy](https://github.com/wxy)


本文由 [LCTT](https://github.com/LCTT/TranslateProject) 原创编译，[Linux中国](https://linux.cn/) 荣誉推出


OK
![Warp Terminal](/assets/images/warp-terminal.webp)


![Warp Terminal](/assets/images/warp-terminal.webp)

Wonder what’s your IP address? Here are several ways to check IP addresses in Ubuntu and other Linux distributions.

Want to know your Linux system's IP address? You can use the ip command with the option `a`

like this:

`ip a`


The output is extensive and it shows all the internet interfaces available, including loopback. Identifying the IP address could seem challenging if you are new to it.

```
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN group default qlen 1000
link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
inet 127.0.0.1/8 scope host lo
valid_lft forever preferred_lft forever
inet6 ::1/128 scope host
valid_lft forever preferred_lft forever
2: enx747827c86d70: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN group default qlen 1000
link/ether 74:78:27:c8:6d:70 brd ff:ff:ff:ff:ff:ff
3: wlp0s20f3: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc noqueue state UP group default qlen 1000
link/ether dc:41:a9:fb:7a:c0 brd ff:ff:ff:ff:ff:ff
inet 192.168.1.53/24 brd 192.168.1.255 scope global dynamic noprefixroute wlp0s20f3
valid_lft 82827sec preferred_lft 82827sec
inet6 fe80::e1d:d71b:c507:5cc8/64 scope link noprefixroute
valid_lft forever preferred_lft forever
```


It really is not, actually.

And there are other ways to find the IP address. I'll discuss all this in detail. But first, let's brush up the basics.

## What is an IP Address?

An **Internet Protocol address** (commonly referred to as the **IP address**) is a numerical label assigned to each device connected to a computer network (using the Internet Protocol). An IP address serves both the purpose of identification and localisation of a machine.

The **IP address** is * unique* within the network, allowing communication between all connected devices.

You should also know that there are two

**types of IP addresses**:

**public**and

**private**. The

**public IP address**is used to communicate over the Internet, the same way your physical address is used for postal mail. However, in the context of a local network (such as a home where a router is used), each device is assigned a unique private IP address within this sub-network. This is used inside this local network without directly exposing the public IP (which the router uses to communicate with the Internet).

Another distinction can be made between

**IPv4**and

**IPv6**protocols.

**IPv4**is the classic IP format, consisting of a basic 4-part structure, with four bytes separated by dots (e.g., 127.0.0.1). However, with the growing number of devices, IPv4 will soon be unable to offer enough addresses. This is why

**IPv6**was invented, a format that uses 128-bit addresses (compared to the 32-bit

**IPv4**).

## Checking your IP Address in Ubuntu [Terminal Method]

The fastest and simplest way to check your IP address is by using the `ip`

command. You can use this command in the following fashion:

```
ip a
```


Actually, it’s short for this:

```
ip addr show
```


Both commands show the same output. They will show you both IPv4 and IPv6 addresses:

![Display IP Address in Ubuntu Linux](https://itsfoss.com/content/images/2023/03/ip-addr-show.png)

You should identify the correct interface and then look beside inet for IPv4 and inet6 for IPv6.

For example, inet 192.168.1.53/24 means the IPv4 address is 192.168.1.53.

### Just get the IP address

If you prefer to get minimal details, you can also use the **hostname** command:

```
hostname -I
```


It will just give the IP address of the system. Nothing else.

![Hostname only shows IP address](https://itsfoss.com/content/images/2023/03/hostname-command.png)

There are other [ways to check IP addresses in Linux](https://linuxhandbook.com/find-ip-address/?ref=itsfoss.com) but these two commands are more than enough to serve the purpose.

**ifconfig**(part of net-tools), but that

[command is deprecated](https://itsfoss.com/deprecated-linux-commands/). Some newer Linux distributions don’t include this package anymore and if you try running it, you’ll see the ifconfig command not found error.

## Checking IP address in Ubuntu [GUI Method]

If you are not comfortable with the command line, you can also check the IP address graphically.

Open up the Ubuntu Applications Menu (**Show Applications** in the bottom-left corner of the screen) and search for **Settings** and click on the icon:

![Open system settings from Ubuntu Activities Overview](https://itsfoss.com/content/images/2023/03/open-settings-from-activities-overview.png)

This should open up the **Settings Menu**. Go to **Network**:

![Open settings for the currently connected network from the gear icon adjacent to the name of that particular connection](https://itsfoss.com/content/images/2023/03/click-gear-icon-adjacent-to-network-connection.png)

Pressing on the **gear icon** next to your connection should open up a window with more settings and information about your link to the network, including your IP address:

![IP Address details in Ubuntu System Settings](https://itsfoss.com/content/images/2023/03/ipaddress-details-in-ssytem-settings.png)

You can [see the IP address of your router](https://itsfoss.com/router-ip-address-linux/) as well in the above screenshot. It’s displayed with “Default Route”.

## Bonus Tip: Checking your public IP address (for desktop computers)

First of all, to check your **public IP address** (used for communicating with servers etc.) you can [use the curl command](https://linuxhandbook.com/curl-command-examples/?ref=itsfoss.com). Open up a terminal and enter the following command:

```
curl ifconfig.me
```


This should simply return your IP address with no additional bulk information. I would recommend being careful when sharing this address since it is equivalent to giving out your personal address.

**curl**isn’t installed on your system, simply use

`sudo apt install curl -y`

to [install curl on Ubuntu-based Linux distributions](https://itsfoss.com/install-curl-ubuntu/).

Another simple way you can see your public IP address is by searching for the **IP address** on Google.

## Summary

Here's a summary of the commands you learned:

Description | Command |
---|---|

Show both IPv4 and IPv6 addresses with `ip` command |
ip a or ip addr show |

Print only IP address using `hostname` command |
hostname -I |

To check your public IP address (Need `curl` installed) |
curl ifconfig.me |

Display IP Address with Network Manager tool | nmcli -p device show |

Use the ifconfig command to display the IP address (Need `net-tools` installed ) |
ifconfig -a |


Now that you know your system's IP address, how about [getting the gateway IP](https://itsfoss.com/router-ip-address-linux/)?

[Get Router’s IP Address (Default Gateway) in Ubuntu LinuxLooking for a way to connect to your router but don’t know its address? Here’s how to get the IP address of your router in Ubuntu and other Linux systems.](https://itsfoss.com/router-ip-address-linux/)![](https://itsfoss.com/content/images/wordpress/2022/06/how-to-find-router-ip-address.png)


![](https://itsfoss.com/content/images/wordpress/2022/06/how-to-find-router-ip-address.png)

Boost your Linux networking skills with these essential commands!

[21 Basic Linux Networking Commands You Should KnowA list of basic Linux networking commands that will help you troubleshoot network issues, monitor packets, connect devices, and much more.](https://itsfoss.com/basic-linux-networking-commands/)![](https://itsfoss.com/content/images/wordpress/2016/06/essential-linux-networking-commmands.png)


![](https://itsfoss.com/content/images/wordpress/2016/06/essential-linux-networking-commmands.png)

In this article, I went through the different ways you can find your IP address in Ubuntu Linux, as well as gave you a basic overview of what IP addresses are used for and why they are so important to us.

I also discussed IPv4 and IPv6 briefly. By the way, have you ever wondered why there is no IPv5?

[What Happened to IPv5? Why there is IPv4, IPv6 but no IPv5?If you have spent any amount of time in the world of the internet, you should have heard about the IPv4 and IPv6 protocols that our computers use every day. One question that you might be asking is: Why there is no IPv5? Why IPv6 came after IPv4 and not](https://itsfoss.com/what-happened-to-ipv5/)![](https://itsfoss.com/content/images/wordpress/2020/04/what-happened-to-ipv5.png)


![](https://itsfoss.com/content/images/wordpress/2020/04/what-happened-to-ipv5.png)

I hope you enjoyed this quick guide. Let us know if you found this explanation helpful in the comments section!