我测试,使用以太网(未IP)两台计算机之间的谈判协议的实现。为了实际上并不需要有两个物理计算机,我要创建两个虚拟以太网接口。这些将仅能够彼此交谈,所以一个端点方案将结合一个接口和所述另一个端点将结合到其他

这是可能的,我该怎么办呢?

有帮助吗?

解决方案

可以使用VDE2,虚拟交换机。

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

# 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

在一侧类型,它会出现在其他

其他提示

可以使用“抽头”虚拟以太网驱动程序,它可以让用户空间程序假装是以太网接口。这是一段时间了标准的内核功能现在(它可能不是在你的内核中启用虽然)。

您可以使用NS3模拟两个分流设备之间的复杂的网络,如果你需要它: HTTP:// WWW。 nsnam.org/

我已经它模仿两个开关,一个无线客户端,和AP,2个的virtualbox实例之间。

人接口 人的ifconfig

只是在添加新的节的/ etc /网络/接口

我的示例配置:

iface eth0 inet static
   address 192.168.2.150
   netmask 255.255.255.0
   network 192.168.2.0
   broadcast 192.168.2.255
   gateway 192.168.2.253
   # dns-* options are implemented by the resolvconf package, if installed
   dns-nameservers 8.8.4.4


iface eth0:1 inet static
    address 192.168.2.2
    netmask 255.255.255.0
    network 192.168.2.0
    broadcast 192.168.2.255
    gateway 192.168.2.253
    # dns-* options are implemented by the resolvconf package, if installed
    dns-nameservers 8.8.4.4

-

eth0的具有IP 192.168.2.150而为eth0:1具有192.168.2.2

如果您想让自己的子网,也不想刻意去使用VDE。

。简而言之:

# tunctl -t eth0
Set 'eth0' persistent and owned by uid 0
# ifconfig eth0
eth0      Link encap:Ethernet  HWaddr a6:9b:fe:d8:d9:5e  
      BROADCAST MULTICAST  MTU:1500  Metric:1
      RX packets:0 errors:0 dropped:0 overruns:0 frame:0
      TX packets:0 errors:0 dropped:0 overruns:0 carrier:0
      collisions:0 txqueuelen:500 
      RX bytes:0 (0.0 B)  TX bytes:0 (0.0 B)

或者与IP:

# ip tuntap add dev eth0 mode tap
# ip link ls dev eth0
  7: eth0: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT qlen 500
  link/ether 0e:55:9b:6f:57:6c brd ff:ff:ff:ff:ff:ff

可以使用vconfig的命令 例如:

vconfig add eth0 10 #virtual interface eth0.10 will be created

也许我失去了一些重要的东西..但不是这正是环路(LO)接口是什么?

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top