---
title: "Discussion on \"从proc文件系统中获取gateway的IP地址\" | Hashnode"
description: "Discussion on \"从proc文件系统中获取gateway的IP地址\". 在linux的命令行下获取当前网络环境的gateway的IP并不是一件难事，常用的命令有ip route或者route -n，route -n是通过读取proc文件系统下的文件来从内核获取路由表的，但ip route是通过netlink来获取的路由表；本文将讨论如何编写程序从proc文件系统中获取路由表，并从路由表中获取gateway的IP地址，文章最后给出了完整的源程序，本文对初学者基本没有难度。\n\n1. 为什么要获取网关的IP地址\n\n以前写过一些与raw socket有关的文章，在使用raw..."
url: "https://hashnode.com/posts/180008-get-gateway-ip-from-proc-filesys/63e33a70522d637890a8b26e"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [从proc文件系统中获取gateway的IP地址](https://whowin.cn/180008-get-gateway-ip-from-proc-filesys?utm_source=hashnode&utm_medium=feed)

在linux的命令行下获取当前网络环境的gateway的IP并不是一件难事，常用的命令有ip route或者route -n，route -n是通过读取proc文件系统下的文件来从内核获取路由表的，但ip route是通过netlink来获取的路由表；本文将讨论如何编写程序从proc文件系统中获取路由表，并从路由表中获取gateway的IP地址，文章最后给出了完整的源程序，本文对初学者基本没有难度。 1. 为什么要获取网关的IP地址 以前写过一些与raw socket有关的文章，在使用raw...

Feb 5, 2023 · 2 min read · whowin.cn  
Updated Oct 17, 2024  
Read the article

-   [#linux](https://hashnode.com/tag/linux)
-   [#gateway](https://hashnode.com/tag/gateway)
-   [#proc-filesystem](https://hashnode.com/tag/proc-filesystem)

## Written by

[whowin](https://hashnode.com/@whowin)

@whowin · Beijing, China

  
[View profile](https://hashnode.com/@whowin)

一枚有30多年经验的退休程序员，主要从事嵌入式软件开发

## Responses

Markdown supported · ⌘↵ to post

No responses yet.
