Linux kvm Virtual Machine NAT/BRIDGE configuration, kvmnat

Source: Internet
Author: User
Tags root access

Linux kvm Virtual Machine NAT/BRIDGE configuration, kvmnat

Host Nic Configuration:

When you install KVM in NAT mode, it is configured by default. If not:

Retrieve NAT:
# Virsh net-define/usr/share/libvirt/networks/default. xml // target:/etc/libvirt/storage/default. xml
# Virsh net-autostart defalut // target:/etc/libvirt/storage/autostart/default. xml
# Virsh net-start default
[Root @ ywzx-01 ~] # Virsh net-list
Ç ç§ ° C. ~~~~~~~~~§ Persistent
--------------------------------------------------
Default comment '» comment ¨ yes

[Root @ ywzx-01 ~] #


BRIDGE Mode:

Disable the NetworkManager tool and enable the built-in network service.
Chkconfig NetworkManager off
Chkconfig network on
Service NetworkManager stop

During the test, disable the firewall of the host machine and virtual machine, and configure the firewall after testing.


Host NIC:

[Root @ ywzx-01 ~] # Cat/etc/sysconfig/network-scripts/ifcfg-br0
DEVICE =Br0
TYPE = Bridge
# UUID = 498400a2-bc2d-4680-963d-d0a585cdde5b
ONBOOT = yes
NM_CONTROLLED = yes
BOOTPROTO = static
DEFROUTE = yes
20174_failure_fatal = yes
IPV6INIT = no
# NAME = "System eth4"
# HWADDR = 70: E2: 84: 0F: 08: 18
IPADDR = 192.168.0.239
NETMASK = 255.255.254.0
NETWORK = 192.168.0.0
PREFIX = 23
GATEWAY = 192.168.1.1
DNS1 = 61.139.2.69
LAST_CONNECT = 1438859818
[Root @ ywzx-01 ~] #

[Root @ ywzx-01 ~] # Cat/etc/sysconfig/network-scripts/ifcfg-eth4
DEVICE = eth4
TYPE = Ethernet
# UUID = 498400a2-bc2d-4680-963d-d0a585cdde5b
ONBOOT = yes
# NM_CONTROLLED = yes
# BOOTPROTO = static
# DEFROUTE = yes
# Define 4_failure_fatal = yes
# IPV6INIT = no
# NAME = "System eth4"
HWADDR = 70: E2: 84: 0F: 08: 18
# IPADDR = 192.168.0.239
# NETMASK = 255.255.254.0
# PREFIX = 23
# GATEWAY = 192.168.1.1
# DNS1 = 61.139.2.69
# LAST_CONNECT = 1438859818
BRIDGE ="Br0"
[Root @ ywzx-01 ~] #

After the network service is restarted
Service network restart
The "Master connection not found or invalid" network error occurs.
Disable NetworkManager and restart the network
Service NetworkManager stop
Service network restart

[Root @ ywzx-01 ~] # Brctl show
Bridge name bridge id STP enabled interfaces
Br0 8000.70e2840f0818 no eth4
Vnet0
Virbr0 8000.52540097dc51 yes virbr0-nic

Bridge br0 has been set up, And the vnet0 generated during eth4 and Virtual Machine startup is already in br0

[Root @ ywzx-01 ~] # Route-n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
192.168.122.0 0.0.0.0 255.255.255.0 U 0 0 0 virbr0
192.168.0.0 0.0.0.0 255.255.254.0 U 0 0 0 br0
169.254.0.0 0.0.0.0 255.255.0.0 U 1009 0 0 br0
0.0.0.0 192.168.1.1 0.0.0.0 UG 0 0 0 br0
[Root @ ywzx-01 ~] #


Virtual Machine Nic Configuration:

IPADDR = 192.168.0.237
NETMASK = 255.255.254.0
NETWORK = 192.168.0.0
GATEWAY = 192.168.1.1
DNS1 = 61.139.2.69









Bytes -----------------------------------------------------------------------------------

Other references:

RHEL 6 Virtual Networks and Network Bridges
From: http://www.techotopia.com/index.php/Creating_an_RHEL_6_KVM_Networked_Bridge_Interface

A kvm virtual machine running on RHEL 6 has two options in terms of networking connectivity.

One option is for it to be connected to a virtual network running within the operating system of the host computer. in this configuration any virtual machines on the virtual network can see each other but access to the external network is provided by Network Address Translation (NAT ). when using the virtual network and NAT, each virtual machine is represented on the external network (the network to which the host is connected) using the IP address of the host system. this is the default behavior for KVM virtualization alization and requires no additional configuration, other than selecting the Virtual network option on the Network screen of the virt-manager new virtual machine wizard. typically, a single virtual network is created by default, represented by the name default and the device virbr0.

In order for guests to appear as individual and independent systems on the external network (I. e. with their own IP addresses), they must be configured to share a physical network interface on the host. this is achieved by grouping a network bridge interface on the host system to which the guests can connect. in the remainder of this chapter we will cover the steps necessary to configure an RHEL 6 network bridge for use by KVM based guest operating systems.
Creating an RHEL 6 Network Bridge

The creation of a network bridge involves the use of the bridge-utils package. Begin by checking if this is already installed by executing the following command:

Rpm-q bridge-utils

If the package is not yet installed, install it using yum:

Su-
Yum install bridge-utils

With this package installed it is time to look at the current network configuration. the easiest way to do this is to run the ifconfig command. the following shows output from running ifconfig on a system on which KVM is installed, but on which a network bridge has yet to be configured:

Eth0 Link encap: Ethernet HWaddr 00: 13: 72: 0B: 14: 57
Inet addr: 192.168.2.18 Bcast: 255.255.255.255 Mask: 255.255.255.0
Inet6 addr: fe80: 213: 72ff: fe0b: 1457/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 14715 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 8586 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 100
RX bytes: 19628565 (18.7 MiB) TX bytes: 687049 (670.9 KiB)
Memory: fe3e0000-fe400000

Lo Link encap: Local Loopback
Inet addr: 127.0.0.1 Mask: 255.0.0.0
Inet6 addr: 1/128 Scope: Host
Up loopback running mtu: 16436 Metric: 1
RX packets: 8 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 8 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 480 (480.0 B) TX bytes: 480 (480.0 B)

Virbr0 Link encap: Ethernet HWaddr 62: C1: 46: 30: 92: 37
Inet addr: 192.168.122.1 Bcast: 192.168.122.255 Mask: 255.255.255.0
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 24 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 0 (0.0 B) TX bytes: 4187 (4.0 KiB)

In the above output, the entry for eth0 represents a physical network adaptor on the host computer. this is the connection currently used by this host to access the external network. the virbr0 entry represents the virtual network to which guest operating systems will connect if configured to do so.

In order to provide the option for guest operating systems to share the eth0 connection of the host it is necessary to establish a network bridge between eth0 and the virtual machines.

Begin the bridge creation process by gaining root access and changing directory to the/etc/sysconfig/network-scripts directory:

Su-
Cd/etc/sysconfig/network-scripts

If the interface to be bridged is currently running it shoshould be taken down before proceeding:

Ifdown eth0

The next step is to modify the script file for the physical network device. in this example the device is eth0 so we need to edit the ifcfg-eth0 file to add a BRIDGE = line. for the purposes of this example we will name the interface bridge0:

DEVICE = "eth0"
BOOTPROTO = "dhcp"
HWADDR = "00: 13: 72: 0B: 14: 57"
IPV6INIT = "yes"
IPV6_AUTOCONF = "yes"
NM_CONTROLLED = "yes"
ONBOOT = "yes"
BRIDGE = "bridge0"

The next step is to create a script file for the bridge interface. the name of this file must take the form ifcfg-<bridgename> where <bridgename> matches the name of the bridge defined in the BRIDGE = directive outlined above. given this requirement, we will name the file ifcfg-bridge0. the contents of this file for this example will read as follows:

DEVICE = "bridge0"
TYPE = "Bridge"
BOOTPROTO = "dhcp"
ONBOOT = "yes"
DELAY = 0

Note that the DEVICE = line must refer to the bridge name previusly specified (I. e. bridge0 in this instance). Save the file and then start up both interfaces:

Ifup eth1
Ifup bridge0

Using the ifconfig command, the new bridge interface shoshould now be visible:

Bridge0 Link encap: Ethernet HWaddr 00: 13: 72: 0B: 14: 57
Inet addr: 192.168.2.18 Bcast: 255.255.255.255 Mask: 255.255.255.0
Inet6 addr: fe80: 213: 72ff: fe0b: 1457/64 Scope: Link
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 951 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 970 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 760584 (742.7 KiB) TX bytes: 139643 (136.3 KiB)

Eth0 Link encap: Ethernet HWaddr 00: 13: 72: 0B: 14: 57
Inet6 addr: fe80: 213: 72ff: fe0b: 1457/64 Scope: Link
Up broadcast running promisc multicast mtu: 1500 Metric: 1
RX packets: 15831 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 9750 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 FIG: 100
RX bytes: 20420107 (19.4 MiB) TX bytes: 858409 (838.2 KiB)
Memory: fe3e0000-fe400000

Lo Link encap: Local Loopback
Inet addr: 127.0.0.1 Mask: 255.0.0.0
Inet6 addr: 1/128 Scope: Host
Up loopback running mtu: 16436 Metric: 1
RX packets: 11 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 11 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 816 (816.0 B) TX bytes: 816 (816.0 B)

Virbr0 Link encap: Ethernet HWaddr 62: C1: 46: 30: 92: 37
Inet addr: 192.168.122.1 Bcast: 192.168.122.255 Mask: 255.255.255.0
Up broadcast running multicast mtu: 1500 Metric: 1
RX packets: 0 errors: 0 dropped: 0 overruns: 0 frame: 0
TX packets: 24 errors: 0 dropped: 0 overruns: 0 carrier: 0
Collisions: 0 txqueuelen: 0
RX bytes: 0 (0.0 B) TX bytes: 4187 (4.0 KiB)

Refreshing ing an RHEL 6 Firewall for a Network Bridge

If a firewall is enabled on the RHEL 6 host, it may be necessary to add an iptables rule to allow network traffic via the bridge interface. this is achieved by adding a rule similar to the following to the/etc/sysconfig/iptables configuration file:

-An RH-Firewall-1-INPUT-I bridge0-j ACCEPT

The change to the firewall will not take effect until the service is restarted, so complete the configuration by running the following command at the prompt in a terminal window:

/Sbin/service iptables restart

Using ing a Virtual Machine to use the Network Bridge


During the virtual machine creation process using the virt-manager tool, the network configuration screen will list now Host device eth0 (Bridge 'bridge0 ') under the Advanced options section of the final page of the new virtual machine creation wizard:




Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

Related Article

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.