Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create virtual ethernet devices in linux?

Tags:

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?

like image 507
Greg Rogers Avatar asked Jan 17 '10 21:01

Greg Rogers


People also ask

How do I create a virtual network interface in Linux?

Create virtual network interfaces on LinuxStart off by enabling the dummy kernel module with the following command. Now that the module has been loaded, we can create a new virtual interface. Feel free to name yours however you want, but we will name ours eth0 in this example.

How do I create a virtual Ethernet cable?

To create a virtual Ethernet adapter on the management partition, complete the following steps: In the Virtual Ethernet Adapters section, click Create Adapter. Enter the Virtual Ethernet ID and click OK to exit the Enter Virtual Ethernet ID window. Click OK to exit the Partition Properties window.

How do I find virtual network interface in Linux?

ifconfig command – It is used to display or configure a network interface. nmcli command – A command to show or configure a network interface on Linux. tcpdump command – Print the list of the network interfaces available on the system.


2 Answers

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.

like image 149
Tobu Avatar answered Sep 21 '22 12:09

Tobu


You can use the "tap" virtual ethernet driver which lets a userspace program pretend to be an ethernet interface. This is a standard kernel feature for some time now (it might not be enabled in your kernel though).

like image 37
MarkR Avatar answered Sep 25 '22 12:09

MarkR