如何在Linux中创建虚拟以太网设备? [英] How do I create virtual ethernet devices in linux?

查看:451
本文介绍了如何在Linux中创建虚拟以太网设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在测试一种协议的实现,该协议使用以太网(不是IP)在两台计算机之间进行通信.为了实际上不必具有两台物理计算机,我想创建两个虚拟以太网接口.这些只能相互通信,因此一个端点程序将绑定到一个接口,而另一个端点将绑定到另一个接口.

I am testing an implementation of a protocol that talks between two computers using ethernet (not IP). In order to not actually have to have two physical computers, I want to create two virtual ethernet interfaces. These would only be able to talk to each other, so one endpoint program would bind to one interface and the other endpoint would bind to the other.

这可能吗,我该怎么做?

Is this possible and how do I do it?

推荐答案

您可以使用虚拟交换机VDE2.

You can use VDE2, a virtual switch.

例如(您将需要几个术语):

For example (you will need a few terms):

# Install vde2 (assumes Debian/Ubuntu)
sudo aptitude install vde2
# Create the switch and two tap interfaces attached to it
sudo vde_switch -tap tap0 -tap tap1
# Configure the interfaces
sudo ip addr add 10.0.31.10 dev tap0
sudo ip addr add 10.0.31.11 dev tap1
# Start a server
socat - TCP-LISTEN:4234,bind=10.0.31.10
# Alternatively, an echo server:
#socat PIPE TCP-LISTEN:4234,bind=10.0.31.10
# Start a client
socat - TCP:10.0.31.10:4234,bind=10.0.31.11

在一侧键入,它将出现在另一侧.

Type on one side, it will appear on the other.

这篇关于如何在Linux中创建虚拟以太网设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆