在 Linux 中找到你的路由器的 IP 地址（默认网关）
网关
![](/data/attachment/album/202207/06/155222cgjpa9ppa19zr2g1.jpg)


你可能已经知道如何在 Linux 中获得你的系统的 IP 地址。


但是你怎么知道你的路由器的 IP 地址呢？


我说的不是你可以通过连接到 “[Show My IP](https://www.showmyip.com/)” 这样的网站或简单地在 [DuckDuckGo](https://itsfoss.com/duckduckgo-easter-eggs/) 中 [搜索“what is my ip”](https://duckduckgo.com/?q=what+is+my+ip&t=h_&ia=answer) 获得的公网 IP。


我说的是默认网关 IP，你的 Linux 桌面所连接的地址。


你为什么需要它？嗯，如果你需要改变你的 Wi-Fi/网络的 SSID、密码或其他配置，你必须连接到它。简单的方法是在网页浏览器中输入路由器的 IP 地址，然后使用路由器的用户名和密码。


虽然我不能帮助你获得路由器的用户名和密码，但我肯定可以告诉你如何获得它的 IP。


一如既往，我将展示 GUI 和命令行两种方法。


### 方法 1：在 Linux 中使用 GUI 获取路由器的 IP 地址


这其实很简单。我在这里使用的是 Ubuntu 的 GNOME 桌面。如果你使用一些 [其他桌面环境](https://itsfoss.com/best-linux-desktop-environments/)，截图可能会有所不同。


打开“<ruby> 系统设置 <rt>  System Settings </rt></ruby>”：


![go to settings](/data/attachment/album/202207/06/155257xxyx9bb9ag11cch3.jpg)


现在进入 Wi-Fi 或“<ruby> 网络 <rt>  Network </rt></ruby>”（如果你使用的是有线的以太网连接）。在这里，点击你当前使用的网络旁边的小设置符号。


![access network settings ubuntu](/data/attachment/album/202207/06/155258zst8a6ntaarwr6w6.png)


它将打开一个新窗口，里面有关于你的连接的一些细节，如 IP 地址、DNS 和 [Mac 地址](https://itsfoss.com/change-mac-address-linux/)。你还可以在“<ruby> 安全 <rt>  security </rt></ruby>”标签下看到 [保存的 Wi-Fi 密码](https://itsfoss.com/how-to-find-saved-wireless-wifi-passwords-ubuntu/)。


你还会看到一个名为“<ruby> 默认路由 <rt>  Default Route </rt></ruby>”的条目。这就是你要找的东西。你的路由器的 IP 地址。


![default gateway ip ubuntu](/data/attachment/album/202207/06/155258r1jfs6zxf38wnpap.png)


你的系统和网络上的所有其他设备都使用这个 IP 地址连接到路由器。这就是大多数家庭的设置。


现在我已经展示了 GUI 的方法，让我们去看看终端的路线。


### 方法 2：在 Linux 命令行中获取路由器的 IP 地址


打开一个终端，使用以下命令：



```
ip route

```

它将显示几个条目。



```
~$ ip route
default via 192.168.1.1 dev wlp0s20f3 proto dhcp metric 600 
169.254.0.0/16 dev wlp0s20f3 scope link metric 1000 
192.168.1.0/24 dev wlp0s20f3 proto kernel scope link src 192.168.1.34 metric 600

```

第一行，以 `default via` 开头，给出了你网关的 IP。这是你的路由器的 IP 地址。


![default route linux terminal](/data/attachment/album/202207/06/155258vj6m2q2q6j2jq545.png)


你可以看到，`192.168.1.1` 是我的路由器的 IP 地址。通常情况下，路由器的 IP 地址是子网的第一个数字。然而，这并不是一个硬性规定。我也见过有 `x.y.z.30` 地址的路由器。


### 额外技巧


正如 Samir 在评论中所分享的，你也可以（在 Debian 上）使用 `ping` 命令来获得网关 IP：



```
ping _gateway

```

![ping gateway](/data/attachment/album/202207/06/155258uyuuu4yczqpycyzu.png)


以防你不知道，你必须 [在 Linux 中使用 Ctrl+C 来停止一个正在运行的命令](https://itsfoss.com/stop-program-linux-terminal/)。


我希望你在需要的时候能发现这个技巧是有用的。




---


via: <https://itsfoss.com/router-ip-address-linux/>


作者：[Abhishek Prakash](https://itsfoss.com/author/abhishek/) 选题：[lkxed](https://github.com/lkxed) 译者：[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)

You probably already know how to [get your system’s IP address in Linux](https://itsfoss.com/check-ip-address-ubuntu/).

But how do you know the IP address of your router?

I am not talking about the public-facing IP which you can get by connecting to websites like [Show My IP](https://www.showmyip.com/?ref=its-foss) or simply [searching for ‘what is my ip’](https://duckduckgo.com/?q=what+is+my+ip&t=h_&ia=answer&ref=its-foss) in [DuckDuckGo](https://itsfoss.com/duckduckgo-easter-eggs/).

I am talking about the default gateway IP which your Linux desktop uses to connect to it.

Why do you need it? Well, if you need to change the SSID, password, or other configuration of your wi-fi/network, you have to connect to it. And the simplest way is to type the router's IP address in a web browser and then use the router’s username and password.

While I cannot help you with the username and password of your router, I can surely tell you how to get its IP.

As always, I’ll show both GUI and command-line methods.

## Method 1: Get the router’s IP address in Linux using GUI

It’s quite simple actually. I am using GNOME desktop with Ubuntu here. If you use some [other desktop environments](https://itsfoss.com/best-linux-desktop-environments/), screenshots may look different.

Open System Settings:

![go to settings](https://itsfoss.com/content/images/wordpress/2022/02/go_to_settings.jpg)

Now go to Wi-Fi or Network (if you are using a wired, Ethernet connection). Here, click on the little settings symbol beside your currently used network.

![access network settings ubuntu](https://itsfoss.com/content/images/wordpress/2022/06/access-network-settings-ubuntu-800x448.png)

It will open a new window with several details about your connection such as the IP address, DNS, and [Mac address](https://itsfoss.com/change-mac-address-linux/). You can also see the [saved wifi password](https://itsfoss.com/how-to-find-saved-wireless-wifi-passwords-ubuntu/) under the security tab.

You’ll also see an entry named ‘Default Route’. This is what you are looking for. The IP address of your router.

![defaul gateway ip ubuntu](https://itsfoss.com/content/images/wordpress/2022/06/defaul-gateway-ip-ubuntu.png)

Your system and all other devices on your network connect to the router using this IP address. This is the setup most households have.

Now that I have shown the GUI method, let’s go to the terminal route.

## Method 2: Get the router’s IP address in Linux command line

Open a terminal and use the following command:

`ip route`


It will show you a few entries.

```
abhishek@itsfoss:~$ ip route
default via 192.168.1.1 dev wlp0s20f3 proto dhcp metric 600
169.254.0.0/16 dev wlp0s20f3 scope link metric 1000
192.168.1.0/24 dev wlp0s20f3 proto kernel scope link src 192.168.1.34 metric 600
```


The first line, which starts with ‘default via’, gives you the gateway IP. This is your router’s IP address.

![defaul route linux terminal](https://itsfoss.com/content/images/wordpress/2022/06/defaul-route-linux-terminal.png)

As you can see, 192.168.1.1 is the IP address of my router. Usually, the router’s IP address is the first number of the subnet. However, this is not a hard and fast rule. I have seen routers with x.y.z.30 addresses as well.

## Bonus tip

As shared by Samir in the comments, you can also [use the ping command](https://itsfoss.com/ping-command/) to get the gateway IP:

`ping _gateway`


![ping gateway](https://itsfoss.com/content/images/wordpress/2022/06/ping-gateway.png)

In case you didn’t know, you have to [use the Ctrl+C to stop a running command in Linux](https://itsfoss.com/stop-program-linux-terminal/).

I hope you find this tip useful when you need it.