How to create a virtual network for an application - networking

I'm creating a simple p2p application. To test this I'd like to be able to simulate a simple network of about 2-3 computers, such that each instance of the application thinks its on a different computer and talking with others over the network. I considered qemu, but haven't managed to get networking working using VDE or TUN/TAP. is their any other solution?

You might have better luck using VMs running on something like Virtual PC (Sun's Virtual Box is another good alternative).

Here are example using vde and qemu. Not require to configure firewall/routing. Much more simple to setup. Do not need root privilege to run qemu. Easy to use. Tested and working.
# brctl addbr br0
# brctl addif br0 eth0
# dhclient br0
# vde_tunctl -u testuser -t tap0
# ifconfig tap0 up
# brctl addif br0 tap0
# brctl setfd br0 0
$ vde_switch -d -s /tmp/vde0 -M /tmp/vde0mgmt
$ vde_plug2tap -d -s /tmp/vde0 tap0
$ vdeqemu -hda testdisk1.qcow2 ... -net nic,macaddr=... -net vde,sock=/tmp/vde0
$ vdeqemu -hda testdisk2.qcow2 ... -net nic,macaddr=... -net vde,sock=/tmp/vde0
You might refer to simple diagram at
http://selamatpagicikgu.wordpress.com/2011/06/08/quickhowto-qemu-networking-using-vde-tuntap-and-bridge/

I recently set up a small network using VirtualBox and VDE on my laptop that cannot reach the internet. VirtualBox 4.0.6 natively integrates with VDE. Setting up VDE should be as simple as starting your switch:
vde_switch -s /tmp/switch1
Then, selecting "VDE Adapter" as your network adapter for each of your VMs and specifying the name of your adapter as the following will connect all of your VMs to the same switch so they can communicate:
/tmp/switch1
Alternatively (and more simply), you could just choose "Internal Network" as your network adapter and specify the same name for the network in each of your VMs to connect them all together in VBox.

Related

Configure LXC to use wireless hosted network

I found most of the configuration is for giving static or private network. But I want it to act as a different machine so it will get a separate IP address from the DHCP and I want to do it through nmcli.
Thanks in advance.
If you are using docker as tagged, rather than LXC, use pipework to map the wlan interface from the host to the container
pipework eth2 $CONTAINERID 10.10.9.9/24
or alternatively let the container do the dhcp negotiation for you
pipework eth1 $CONTAINERID dhclient
This setup is based on a macvlan interface so the same concept should work with LXC you just won't get the easy front end.
I'm confused if this is a docker question or an LXC question.
EDIT: as per the comments, wlan interface support in a bridge depends on the wlan vendor. It may work, or it may not work at all.
In any case, you should be able to create a bridge, add your wlan0 interface to the bridge, and then have your LXC container connect to this bridge directly. Then, when you run your DHCP client in the container, it will grab it from the wlan0 interface.
Configure bridge (manually for now)
# ifconfig wlan0 up
# brctl addbr br0
# brctl addif br0 wlan0
# ifconfig br0 up
# dhclient br0
Configure LXC configuration
If using traditional priviliged LXC, edit the container's config file at /var/lib/lxc/$NAME/config,
and update this value to point to your new bridge.
lxc.network.link = br0
Run DHCP in container
# lxc-attach -n $NAME
# dhclient eth0
# ip a
If the output to ip a shows the desired IP, you're all set!
If you want to make the configuration persistent, you'll have to add the bridge to your /etc/network/interfaces file.
IEEE 802.11 doesn’t like multiple MAC addresses on a single client, so bridge and macvlans are not the right solution here.
Use ipvlan in L2 mode.

How to set a specific fixed IP address when I create a docker machine or container?

When I create my container, I want to set a specific container's IP address in the same LAN.
Is that possible? If not, after the creation can I edit the DHCP IP address?
Considering the conclusion of the (now old October 2013) article "How to configure Docker to start containers on a specific IP address range", this doesn't seem to be possible (or at least "done automatically for you by Docker") yet.
Update Nov 2015: a similar problem is discussed in docker/machine issue 1709, which include the recent workaround (Nov 2015)proposed by Tobias Munk (schmunk42) for docker machine
(for container see the next section):
A workaround for some use-cases could be to create machines like so:
192.168.98.100
docker-machine create -d virtualbox --virtualbox-hostonly-cidr "192.168.98.1/24" m98
192.168.97.100
docker-machine create -d virtualbox --virtualbox-hostonly-cidr "192.168.97.1/24" m97
192.168.96.100
docker-machine create -d virtualbox --virtualbox-hostonly-cidr "192.168.96.1/24" m96
If there's no other machine with the same cidr (Classless Inter-Domain Routing), the machine should always get the .100 IP upon start.
Another workaround:
(see my script in "How do I create a docker machine with a specific URL using docker-machine and VirtualBox?")
My virtualbox has dhcp range 192.168.99.100 - 255 and I want to set an IP before 100.
I've found a simple trick to set a static IP: after create a machine I run this command and restart the machine:
echo "ifconfig eth1 192.168.99.50 netmask 255.255.255.0 broadcast 192.168.99.255 up" \
| docker-machine ssh prova-discovery sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null
This command create a file bootsync.sh that is searched by boot2docker startup scripts and executed.
Now during machine boot the command is executed and set static IP.
docker-machine ls
NAME ACTIVE DRIVER STATE URL SWARM
test-1 - virtualbox Running tcp://192.168.99.50:2376 test-1 (mast
Michele Tedeschi (micheletedeschi) adds
I've updated the commands with:
echo "kill `more /var/run/udhcpc.eth1.pid`\nifconfig eth1 192.168.99.50 netmask 255.255.255.0 broadcast 192.168.99.255 up" | docker-machine ssh prova-discovery sudo tee /var/lib/boot2docker/bootsync.sh > /dev/null
then run command (only the first time)
docker-machine regenerate-certs prova-discovery
now the IP will not be changed by the DHCP
(replace prova-discovery by the name of your docker-machine)
April 2015:
The article mentions the possibility to create your own bridge (but that doesn't assign one of those IP addresses to a container though):
create your own bridge, configure it with a fixed address, tell Docker to use it. Done.
If you do it manually, it will look like this (on Ubuntu):
stop docker
ip link add br0 type bridge
ip addr add 172.30.1.1/20 dev br0
ip link set br0 up
docker -d -b br0
To assign a static IP within the range of an existing bridge IP range, you can try "How can I set a static IP address in a Docker container?", using a static script which creates the bridge and a pair of peer interfaces.
Update July 2015:
The idea mention above is also detailed in "How can I set a static IP address in a Docker container?" using:
Building your own bridge
The result should be that the Docker server starts successfully and is now prepared to bind containers to the new bridge.
After pausing to verify the bridge’s configuration, try creating a container — you will see that its IP address is in your new IP address range, which Docker will have auto-detected.
you can use the brctl show command to see Docker add and remove interfaces from the bridge as you start and stop containers, and can run ip addr and ip route inside a container to see that it has been given an address in the bridge’s IP address range and has been told to use the Docker host’s IP address on the bridge as its default gateway to the rest of the Internet.
Start docker with: -b=br0 (that is also what the echo 'DOCKER_OPTS="-b=bridge0"' >> /etc/default/docker can set for you by default)
Use pipework (192.168.1.1 below being the default gateway ip address):
pipework br0 container-name 192.168.1.10/24#192.168.1.1

KVM Virtualization 10gbe virtual ethernet

I am planning on using KVM in order to virtualize some GNU/Linux and Windows machines at home.
My physical network is 1gbe using Link Aggregation at some stages. In the worst case, it's still 1gbe though.
I am wondering if it is possible to "emulate" 10gbe ethernet (or anything faster than 1gbe) between two virtual machines on the same host (or one VM and the host itself) by avoiding the physical network altogether. I think for this to work they'll need to be in the same network, connected to the same virtual switch and VLAN.
Yes.
Create a bridge using brctl tool on the host:
brctl addbr vm-bridge
ifconfig vm-bridge up
For each VM specify virtio-net NIC and add them to the bridge.
Create qemu-ifup script:
#!/bin/sh
switch=vm-bridge
/sbin/ifconfig $1 promisc 0.0.0.0
/usr/sbin/brctl addif ${switch} $1
Specify this script in "-netdev" parameter of QEMU:
-netdev tap,id=net1,vhost=on,script=/home/user/qemu-ifup,ifname=vm_net1

How-to setup a traffic control server

I am trying to set up a traffic control server between the network and the firewall-router.
The server has two network devices:
Firewall <--> Server <---> NETWORK
It is running CentOS 6.4 x64 and I would like to use Etherape.
My idea is to have eth0 connected directly to our router and eth1 to our network.
eth1 would have two virtual interfaces, one with an IP to ssh the server and the other just forwarding with IPTables to eth0 with no IP. Of course, eth0 would not have any IP (we don't want to change the Gateway).
Any suggestion or better way to do this?
Thank you very much!!
Ok, finally it was quite easy. Install brctl and etherape, then:
brctl addbr br0
brctl stp br0 off
brctl addif br0 eth0
brctl addif br0 eth1
echo 1 > /proc/sys/net/ipv4/ip_forward
ifconfig eth0 up
ifconfig eth1 up
ifconfig br0 up
service network restart
ifconfig br0 XX.YY.ZZ.AA
That is a temporal configuration. If you reboot you have to re-do it. Here is a way to make it persistent:
http://www.tldp.org/HOWTO/Ethernet-Bridge-netfilter-HOWTO.html#toc3.3
Finally, (installing if you are in a Windows Box, Xming and Putty and) connecting as root to XX.YY.ZZ.AA with X11 redirection, execute etherape and you will have you remote traffic control.
To make it easier, I will recommend to add the filter:
ip and not ((src net XX.YY.ZZ.AA) or dst net XX.YY.ZZ.AA)
To avoid the X11 traffic between the server and your box.

Using TunTap with linux kernel 2.6

The TunTap documentation on the vtun site points out that the driver is only supported till Linux kernel 2.4. Is there any way to get it to run on 2.6 and 3.2 versions of Linux?
A cat on the device shows:
# cat /dev/net/tun
cat: File descriptor in bad state
I tried installing directly from the rpm file to see how far I could go and got:
# rpm -i tun-1.1-6.rh71.i386.rpm
error: Failed dependencies:
/bin/sh is needed by tun-1.1-6.i386
Is there any way I can get this to work on linux 2.6+ or are there any good alternatives to tuntap that you are aware of?
The tuntap documentation is outdated. Also, in newer versions of linux, you might need to use
tunctl
instead of
ip tuntap add
To install tunctl on debian Squeeze, install the package 'uml-utilities' which provides the tunctl command. You can add a new tunnel using
tunctl -t tun1
Use the below script to create it automatically, just copy the contents in to a file.sh, change the "ETHOIPADDR" to your ip address, similarly also the change the gateway and broadcast address and run the script with sudo permission.
#!/bin/sh
#
# script to bring up the tun device in QEMU in bridged mode
# first parameter is name of tap device (e.g. tap0)
#
# some constants specific to the local host - change to suit your host
#
ETH0IPADDR=192.168.0.3
GATEWAY=192.168.0.1
BROADCAST=192.168.0.255
#
# First take eth0 down, then bring it up with IP address 0.0.0.0
#
/sbin/ifdown eth0
/sbin/ifconfig eth0 0.0.0.0 promisc up
#
# Bring up the tap device (name specified as first argument, by QEMU)
#
/usr/sbin/openvpn --mktun --dev $1 --user `id -un`
/sbin/ifconfig $1 0.0.0.0 promisc up
#
# create the bridge between eth0 and the tap device
#
/usr/sbin/brctl addbr br0
/usr/sbin/brctl addif br0 eth0
/usr/sbin/brctl addif br0 $1
#
# only a single bridge so loops are not possible, turn off spanning tree protocol
#
/usr/sbin/brctl stp br0 off
#
# Bring up the bridge with ETH0IPADDR and add the default route
#
/sbin/ifconfig br0 $ETH0IPADDR netmask 255.255.255.0 broadcast $BROADCAST
/sbin/route add default gw $GATEWAY
#
# stop firewall - comment this out if you don't use Firestarter
#
/sbin/service firestarter stop

Resources