Xen configure host-only adapter - linux

Xen hypervisor has 2 modes for network configuration as I've seen in Virtual Manager. 1 NAT 2 Routed. Both ask for IP Subnet. However i want to configure a network where i could assign any IP instead of being assigned by DHCP of Xen.
I've use oracle Virtual Box there is an option to use Host-only adapter. I want to use Xen in that way.
In other words i want to share physical network interface to guest machine(VM)
I'm using Xen Hypervisor 3.x on CentOS 6.2 x86_64
I did the following to solve the issue this worked for me.
Disabling Xen's network scripts
If using Xen it is recommended to disable its network munging by editing /etc/xen/xend-config.sxp and changing the line
(network-script network-bridge)
To be
(network-script /bin/true)
Disabling NetworkManager
As of the time of writing (Fedora 12), NetworkManager still does not support bridging, so it is necessary to use "classic" network initscripts for the bridge, and to explicitly mark them as independent from NetworkManager (the "NM_CONTROLLED=no" lines in the scripts below).
If desired, you can also completely disable the NetworkManager:
# chkconfig NetworkManager off
# chkconfig network on
# service NetworkManager stop
# service network start
Creating network initscripts
In the /etc/sysconfig/network-scripts directory it is neccessary to create 2 config files. The first (ifcfg-eth0) defines your physical network interface, and says that it will be part of a bridge:
# cat > ifcfg-eth0 <<EOF
DEVICE=eth0
HWADDR=00:16:76:D6:C9:45
ONBOOT=yes
BRIDGE=br0
NM_CONTROLLED=no
EOF
Obviously change the HWADDR to match your actual NIC's address. You may also wish to configure the device's MTU here using e.g. MTU=9000.
The second config file (ifcfg-br0) defines the bridge device:
# cat > ifcfg-br0 <<EOF
DEVICE=br0
TYPE=Bridge
BOOTPROTO=dhcp
ONBOOT=yes
DELAY=0
NM_CONTROLLED=no
EOF
WARNING: The line TYPE=Bridge is case-sensitive - it must have uppercase 'B' and lower case 'ridge'
After changing this restart networking (or simply reboot)
# service network restart
Visit for more details

For Xen, this is just a special case of bridged networking.
You create a dummy bridge on your CentOS Dom0, then connect your VM to that bridge.
From the CentOS Documention (http://www.centos.org/docs/5/html/5.2/Virtualization/sect-Virtualization-Virtualized_network_devices-Laptop_network_configuration.html)
create a dummy0 network interface and assign it a static IP address.
In our example I selected 10.1.1.1 to avoid routing problems in our environment. To enable dummy device support add the following lines to /etc/modprobe.conf
alias dummy0 dummy
options dummy numdummies=1
To configure networking for dummy0 edit/create /etc/sysconfig/network-scripts/ifcfg-dummy0:
DEVICE=dummy0
BOOTPROTO=none
ONBOOT=yes
USERCTL=no
IPV6INIT=no
PEERDNS=yes
TYPE=Ethernet
NETMASK=255.255.255.0
IPADDR=10.1.1.1
ARP=yes
You can then just connect your VM to the dummy0 bridge device
Additional Reference
http://wiki.xen.org/wiki/HostConfiguration/Networking

Related

How to setup routing in Linux to create a NVA in Azure

I am trying to deploy a hub & spoke topology on Azure. I have VNet: hub, spoke1 & spoke2, respectively with the 3 following address spaces: 10.0.0.0/16, 10.1.0.0/16 & 10.2.0.0/16. And each have only one subnet on the /24 address space.
I have peered each spoke to the hub and deployed a Linux machine in my hub subnet. Now, I want to use that Linux machine as a router to forward traffic coming from 10.1.0.0/16 and targetting 10.2.0.0/16 to the spoke2 VNet and vice-versa.
I have added a User Defined Route on each spoke to use the Linux router IP address (10.0.0.5) as the Next hop when targetting the other spoke.
I have enable ip_forwarding on my Linux machine: echo 1 > /proc/sys/net/ipv4/ip_forward and added 2 routes ip route add 10.1.0.0/24 via 10.0.0.1 dev eth0 and ip route add 10.2.0.0/24 via 10.0.0.1 dev eth0 since 10.0.0.1 is my gateway on my router and eth0 my NIC.
I have also enabled IP Forwarding on the NIC of my router in Azure.
But... this does not work. Packets are not forwarded to appropriate network and I don't understand why.
If any of you has a hint or even the solution to implement this I would appreciate.
Thanks.
Don't forget about the setup for NIC for specific machine:
BTW: Microsoft has an easy tutorial on this.
You shoud configure the linux machine as a router.
create a linux bridge, and attach the eth0.
set the bridge ip as 10.0.0.1/24, and setup a dhcp server on it.
on each spokes, set 10.0.0.1 as next hop for target network.
On the linux machine, add router entry to 10.1.0.0/24 and 10.2.0.0/24 through 10.0.0.1.
Okay.
I don't know exactly what went wrong during my first tries.
I simply dropped the Resource Group and restarted from scratch with Windows VM, following Microsoft tutorial.
Then, I replaced step by step the Windows VM by Linux VM... and everything is working.
On the NVA, you simply have to:
enable the IP Forwarding on the Network Interface of the VM in Azure,
enable the IP Forwarding in the VM:
sudo sed -i 's/#net.ipv4.ip_forward=/net.ipv4.ip_forward=/' /etc/sysctl.conf
sudo sed -i 's/net.ipv4.ip_forward=0/net.ipv4.ip_forward=1/' /etc/sysctl.conf
sudo sed -i 's/#net.ipv6.conf.all.forwarding=/net.ipv6.conf.all.forwarding=/' /etc/sysctl.conf
sudo sed -i 's/net.ipv6.conf.all.forwarding=0/net.ipv6.conf.all.forwarding=1/' /etc/sysctl.conf
sudo sysctl -p
Then define routes in Azure (Route table + Routes) in each spoke to forward traffic to the NVA IP.
Nothing more. Works out of the box.
I even created my NVA in a Virtual Machine Scale Set behind an Internal Load Balancer with HA-Ports, so my NVA is highly available.

Multiple IP address problem on debian/beagleboneblack

I'm working on a beaglebone black with a debian system and i want change my ip by modifying "/etc/network/interfaces", this is working but when I switch from DHCP method to static method my address, (atribuate by DHCP), is not "killed" so I end up with two IP addresses.
You need to stop and disable the DHCP client daemon.
How exactly this is done depends on which version of Debian you're using.
On older versions, which I suspect you're on, there is a dhcpcd service. Stop it with systemctl stop dhcpcd and disable it with systemctl disable dhcpcd.
Newer versions or alternate configurations with NetworkManager or systemd-networkd will need those services reconfigured.
I found a way, i just use ip addr flush eth0 after modified "/etc/network/interfaces" and before ifdown eth0 ifup eth0.

How to configure internet on CentOS installation on VirtualBox

I am a beginner to linux. I have done the fresh installation of CentOS 7 on my Windows VirtualBox.
Over the tutorials for CentOs 6 they have mentioned to edit /etc/sysconfig/network-scripts/ifcfg-eth0 file for the configurations.
But in my installation there is no such file. I have ifcfg-enp0s3 and ifcfg-lo files available.
From the CentOS tutorial, the eth0 portion of /etc/sysconfig/network-scripts/ifcfg-eth0 refers to the network interface. eth0 is the most common name for a standard ethernet interface in Linux. From your question, your system has two interfaces: enp0s3 and lo. lo is the loopback interface, so ignore that one. That leaves enp0s3.
Go ahead and follow the instructions with /etc/sysconfig/network-scripts/ifcfg-enp0s3. It should work, assuming that interface doesn't have any weird quirks associated with it.
Same here! I installed CentOS 7 in Windows7 Virtulabox, there is no eth0, but enp0s3.
After first reboot, used command ip addr, enp0s3 had no ip address
bundled;
Then I updated /etc/sysconfig/network-scripts/ifcfg-enp0s3, changed ONBOOT=no to ONBOOT=yes, enp0s3 had ip 10.x.x.x, still useless;
Then I updated /etc/sysconfig/network-scripts/ifcfg-enp0s3 according to the accepted answer of centos minimal installation static ip address, it works!
As my IP address of Ethernet adapter VirtualBox Host-Only Network is 192.168.56.1, I set 192.168.56.35 to enp0s3, and my vbox NIC mode is Host-Only.
Type nmtui in the terminal
Go to 'edit connection' and hit enter
Select 'enp0s3' and hit enter
Go down to 'Automatically connect' using down arrow key
Press space bar
Go down and press hit enter on 'Ok'
Go back and quit
It worked for me like this on windows 10 -Change Adapter 1 Name to "Remote NDIS based Internet Sharing Device"

multicast traffic fails with virtualbox host only network

I have an application where it sends some multicast request to the multicast group ,
If I test my Client and Server application on two separate PC which are in same subnet it works fine .
Since I can not run always on two PCs during testing of my application, I thought of using the virtualbox to run the another OS to run my server application .
My Host is ubuntu , I installed the vitrtualbox to run the another guest os linux , and since my traffic only has to be with in the HOST and Guest , I have selected a "host only network type" .
My guest OS get the IP address but when I run my server application, It fails to join to the multicast group says
"No Such Device" .
Can someone help me to set up a network between the Guest and HOST OS ..
My main goal is to send a multicast request and it should reach the guest OS.
In VM:
ls /sys/class/net - get net devices. (lo, eth0, eth1...). You should have one lo and two eth devices.
sudo nano /etc/network/interfaces. At eth0 there is a NAT connection. Lo is a localhost. We should set the Host-Only connection. Add the following:
# The host-only network interface
auto eth1
iface eth1 inet static
address 192.168.56.101
netmask 255.255.255.0
network 192.168.56.0
broadcast 192.168.56.255
(Address is taken from ipconfig/ifconfig output in host system. Instead eth1 you can have another connection name, taken from the step 4.b.i)
For checking the edited file, run:
sudo service network-manager restart
Check if you have all three connections running. Check Host-Only addresses.
ifconfig
Reboot
sudo reboot

How to access Raspberry PI QEMU VM via network

I have successfully setup a Raspberry PI VM on my Mac OS X via QEMU. Now I want to access the filesystem of this VM from my Mac.
When I call ifconfig on my VM I get this.
And here the content of my /etc/network/interfaces file
On my Mac
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=10b<RXCSUM,TXCSUM,VLAN_HWTAGGING,AV>
ether 3c:07:54:65:da:50
inet6 fe80::3e07:54ff:fe65:da50%en0 prefixlen 64 scopeid 0x4
inet6 fdbf:a879:6730::3e07:54ff:fe65:da50 prefixlen 64 autoconf
inet6 fdbf:a879:6730::401e:56f5:f2f9:a236 prefixlen 64 autoconf temporary
inet 192.168.1.119 netmask 0xffffff00 broadcast 192.168.1.255
nd6 options=1<PERFORMNUD>
media: autoselect (1000baseT <full-duplex,flow-control>)
status: active
I think the reason is, that the VM uses some kind of Shared Network. Is there a way that the VM get the IP address from my router?
The easier method - less flexible but you don't need to muck around so much
They way you have configured qemu appears to be the default host NAT network (aka. qemu -net nic -net user configuration)
By default, your host (your Mac in this case) will be found on 10.0.2.2 when accessed from your guest. From inside your guest you can connect to services on your host (your MAC) at 10.0.2.2. But this is using NAT, so you can't go back the other way as easily.
For example, if you decide to you want to connect to the SSH service and a web server running inside your guest, you will need to start qemu with modified options like the following:
qemu -net nic -net user,hostfwd=tcp::2222-:22,hostfwd=tcp::22280-:80
What this will do is route connections from port 22280 on your host (your MAC) to port 80 inside your qemu guest, (same for port 2222 --> port 22 in the guest)
Which means you can browse to http://localhost:22280 on your Mac, to get to the web server in your virtual Raspberry Pi, etc.
FTP and SMB will be more complicated to setup this way because of the different ports used and they way they are used, etc. although if you setup FTP to use PASV mode it wont be too much of a problem.
The more complicated method
This involves doing what you suggested, configuring the virtual machine quest to be able to get an IP address from your router. In this case, you need to make a bridge from your virtual machine onto your hosts network.
This requires a lot more setup than can be quickly explained here, but essentially, you need to assign your NIC to a vlan and add a tap interface, for example:
qemu -net nic,vlan=0 -net tap,ifname=tap0
This however requires more setup on the host (initially, manual, as you figure out your own situation, but then, scriptable) to create a bridge and tap interface - which usually requires root access beyond that needed to simply run qemu. A bit of Googling brings up a variety of methods to do this, because it varies more depending on your setup. (I found an example setup script here: https://gist.github.com/EmbeddedAndroid/6572715 )
Note - network MAC addresses, network card models, etc. and other qemu options omitted for clarity.
The SAMBA method
Note: I have only tried this under Linux
You can enable a samba server inside qemu:
qemu -smb /path/to/files
This creates a SMB share accessible from inside the guest at \10.0.2.4\qemu mapped from /path/to/files on the host.
If you are happy to use SFTP/SCP then IMO the easiest thing to do is to install openssh-server on your Pi guest:
sudo apt-get update && sudo apt-get install openssh-server
When you launch your Pi VM use the -redir switch when your launch your QEMU guest to redirect port 22 (SSH/SFTP/SCP) e.g.
qemu <other-qemu-switches-options-etc> -redir tcp:2222::22
You can then connect to your VM SFTP/SCP (or SSH) via port 2222 on your host machine. So from your host you can use localhost; from other machines on your LAN you can use :2222
[update 2019] As noted by #ChristophBimminger in a comment, in newer versions of QEMU the -redir switch has been deprecated/removed. The way to achieve this same thing is now via the -net or -netdev switches. Please check the man page, e.g. Debian testing (I don't currently have a QEMU running so can't give a definitive example).

Resources