How do I create virtual ethernet devices in linux?
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 itsudo vde_switch -tap tap0 -tap tap1# Configure the interfacessudo ip addr add 10.0.31.10 dev tap0sudo ip addr add 10.0.31.11 dev tap1# Start a serversocat - TCP-LISTEN:4234,bind=10.0.31.10# Alternatively, an echo server:#socat PIPE TCP-LISTEN:4234,bind=10.0.31.10# Start a clientsocat - TCP:10.0.31.10:4234,bind=10.0.31.11
Type on one side, it will appear on the other.
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).
You can use ns3 to emulate a complicated network between two tap devices if you need it: http://www.nsnam.org/
I've had it emulating two switches, a wireless client, and an AP, between two virtualbox instances.