Xen network Linux

Source: Internet
Author: User

Xen Network

 

* Bridging Network

 

* Routing network

 

* Virtual LAN with Nat

 

Bridging Network

 

Time for Action-using bridged networking

 

1. The default network setting in xen is bridging, which can be further confirmed by viewing xen in the configuration file (/etc/xen/xend-config.sxp, it should have the following two rows without comments.

 

(Network-script network-bridge)

 

(Vif-script VIF-bridge)

 

2. Create a new configuration file for domu. You can use any image or other image you have created in the previous section.Replace the following configurations with your selected image:

 

Kernel = % 26 quot;/boot/vmlinuz-2.6.16.38-xenU % 26 quot;

 

Memory = 32

 

Name = % 26 quot; bridged_domu % 26 quot;

 

Disk = ['Tap: AIO:/root/xen-images/ttylinux_domu.img, hda, W']

 

VIF = ['bridge = xenbr0']

 

Root = % 26 quot;/dev/hda1 Ro % 26 quot;

 

3. Start domu with XM

 

XM create/root/xenimages/ttylinux_domu.cfg-C

 

4. Check to confirm that domu is started and running properly

 

XM list

 

The following is the event queue that occurs when the xen service and xend are started:

 

1. Run the/etc/xen/scripts/network-bridge script.

 

2. This will create a new bridge called xenbr0.

 

3. Copy Mac and IP addresses from the physical network adapter eth0

 

4. Stop the physical Nic eth0

 

5. Create a new pair of Connected Virtual Network Interfaces-veth0 and vif0.0

 

6. Assign the previously copied MAC address and IP address to veth0.

 

7. Rename the physical Nic eth0 to peth0

 

8. Rename veth0 to eth0

 

9. Connect peth0 and vif0.0 to xenbr0

 

10. Start the Net Bridge xenbr0 and the network adapter peth0, eth0, and vif0.0.

 

UseBrctl showCommand to view the network interfaces connected to each Bridge

 

Routing network

 

Time for Action-using routed networking

 

1. Because we need to modify the xend configuration file, we need to stop the xend

 

Service xend stop

 

2. Modify the xen configuration file/etc/xen/xend-config.sxp so that we can use the routing network.Comment out the two lines of the associated bridge network and cancel the two lines of the associated route network.If no route network line is found in the configuration file, add them:

 

(Network-script network-route)

 

(Vif-script VIF-route)

 

3. Restart xend to start with the new configuration.

 

Xend start

 

4. Modify the previously used domu configuration file so that it can use the routing network

 

Kernel = % 26 quot;/boot/vmlinuz-2.6.16.38-xenU % 26 quot;

 

Memory = 32

 

Name = % 26 quot; routed_domu % 26 quot;

 

Disk = ['Tap: AIO:/root/xen-images/ttylinux_domu.img, hda, W']

 

VIF = ['IP = 192.168.1.165 ']

 

Root = % 26 quot;/dev/hda1 Ro % 26 quot;

 

5. Start domu

 

XM create/root/xen-images/ttylinux_domu.cfg-C

 

6. Check that domu is started and running properly.

 

XM list

 

The following lists the event queues started by xend with route network configuration.

 

1. Allow dom0 for IP Forwarding

 

2. When domu is started, xen copies the IP address from eth0 to the virtual network interface vif.0.The Virtual Interface ID is automatically assigned to each customer domain started by xen.
.The assigned ID will never be reused in a single session. Therefore, if you stop and restart a domain, it will be reassigned to a new ID.

 

3. Start the Virtual Interface vif.0.

 

4. Add a static route for the IP address allocated to the Virtual Interface vif.0 in the domu configuration file

 

 

Virtual Local Network with Network Address Translation

 

Time for Action-Using VLAN with Nat

 

We will create a virtual network on 192.168.2.0 and the network will protect a web server and a database. The IP addresses of all virtual machines on this network will be in this range.We will create two virtual machines on this network and access them from a public IP address.The port is forwarded to each virtual machine by dom0.

 

1. The first network interface is used by dom0. We need to create a new network interface for our VLAN.This interface uses dummy network to remove the creation and name it dummy0.Create a file named/etc/sysconfig/network-scripts/ifcfg-dummy0:

 

A device = dummy0

 

Bootproto = none

 

Onboot = Yes

 

Userctl = No

 

Ipv6init = No

 

Peerdns = Yes

 

Type = Ethernet

 

Netmask = 255.255.255.0

 

Ipaddr = x. x

 

ARP = Yes

 

2. assign an IP address to this interface and add it to the network interface file-/etc/Network/interfaces:

 

Auto dummy0

 

Iface dummy0 Inet static

 

Address 192.168.2.1

 

Netmask 255.255.255.0

 

3. Modify the xend configuration (/etc/xen/xend-config.sxp) to add the following line so that we listen for bridging on the new dummy Network Interface dummy0:

 

(Network-script 'network-bridge netdev = dummy0 ')

 

4. Confirm that IP Forwarding is permitted.

 

Echo % 26 quot; 1% 26 quot; % 26gt;/proc/sys/NET/IPv4/ip_forward

 

5. Restart sysctl to get the modification by live kernel.

 

/Sbin/sysctl-P

 

6. Create the first virtual machine on our VLAN.Modify its configuration file to make it look like the following:

 

# Assume this is the webserver VM

 

Kernel = % 26 quot;/boot/vmlinuz-2.6.16.38-xenU % 26 quot;

 

Memory = 32

 

Name = % 26 quot; vlan_domu_1 % 26 quot;

 

Disk = ['Tap: AIO:/root/xen-images/ttylinux_domu.img, hda, W']

 

VIF = ['IP = 192.168.2.2 ']

 

Root = % 26 quot;/dev/hda1 Ro % 26 quot;

 

Gateway = % 26 quot; 192.168.2.1% 26 quot;

 

7. Create a second virtual machine on our VLAN and modify its configuration file to make it look like the following:

 

# Assume this is the MySQL VM

 

Kernel = % 26 quot;/boot/vmlinuz-2.6.16.38-xenU % 26 quot;

 

Memory = 32

 

Name = % 26 quot; vlan_domu_2 % 26 quot;

 

Disk = ['Tap: AIO:/root/xen-images/ttylinux_domu.img, hda, W']

 

VIF = ['IP = 192.168.2.3 ']

 

Root = % 26 quot;/dev/hda1 Ro % 26 quot;

 

Gateway = % 26 quot; 192.168.2.1% 26 quot;

 

8. Notify dom0 that the request must be forwarded to this VLAN for a specific port.To do this, we need to first allow Nat in dom0:

 

Iptables-T Nat-A postrouting-s 192.168.0.0/16-J Masquerade

 

9. Now we can configure the rule forwarding port to the correct Virtual Machine. First we will forward port 80:

 

Iptables-A prerouting-T nat-p tcp-I eth0 -- dport 80-J DNAT -- To 192.168.2.2: 80

 

10. Forward MySQL port 3306:

 

Iptables-A prerouting-T nat-p tcp-I eth0 -- dport 80-J DNAT -- To 192.168.2.3: 3306

 

Restart xend and create a virtual machine. Now we have a simple network configuration that enables dom0 to forward port-based requests to a customer domain in the VLAN.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.