---
title: "Discussion on \"使用tun虚拟网络接口建立IP隧道的实例\" | Hashnode"
description: "Discussion on \"使用tun虚拟网络接口建立IP隧道的实例\". 通常的socket编程，面对的都是物理网卡，Linux下其实很容易创建虚拟网卡；本文简单介绍一下Linux虚拟网卡的概念，并以tun设备为例在客户端和服务器端分别建立一个实际的虚拟网卡，最终实现一个从客户端到服务器的简单的IP隧道，希望本文能对理解虚拟网卡和IP隧道有所帮助，本文将提供完整的源程序；阅读本文需要具备在Linux下使用C语言进行IPv4下socket编程的基本能力，本文对网络编程的初学者难度较大。\n\n1. Linux下的虚拟网卡TUN/TAP\n\nTUN和TAP是Linuxn内核的虚..."
url: "https://hashnode.com/posts/180018-tun-example-for-setting-up-ip-tunnel/6408944de9219e900cb586e0"
---

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

Discussion

# [使用tun虚拟网络接口建立IP隧道的实例](https://whowin.cn/180018-tun-example-for-setting-up-ip-tunnel?utm_source=hashnode&utm_medium=feed)

通常的socket编程，面对的都是物理网卡，Linux下其实很容易创建虚拟网卡；本文简单介绍一下Linux虚拟网卡的概念，并以tun设备为例在客户端和服务器端分别建立一个实际的虚拟网卡，最终实现一个从客户端到服务器的简单的IP隧道，希望本文能对理解虚拟网卡和IP隧道有所帮助，本文将提供完整的源程序；阅读本文需要具备在Linux下使用C语言进行IPv4下socket编程的基本能力，本文对网络编程的初学者难度较大。 1. Linux下的虚拟网卡TUN/TAP TUN和TAP是Linuxn内核的虚...

Mar 7, 2023 · 4 min read · whowin.cn  
Updated Oct 18, 2024  
Read the article

-   [#networking](https://hashnode.com/tag/networking)
-   [#tunnel](https://hashnode.com/tag/tunnel)
-   [#tun](https://hashnode.com/tag/tun)
-   [#ip-tunnel](https://hashnode.com/tag/ip-tunnel)

## 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.
