UbuntuNetworking: Difference between revisions

From KVM
m (Bsd moved page AnthonyLiguori/Networking to UbuntuNetworking without leaving a redirect: Moved to more relevant heading)
 
(6 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= Setting up NAT with KVM in Ubuntu =                                                                  
= Setting up NAT with KVM in Ubuntu =


Normally, the best way to do guest networking is by setting up a bridge.  However, if you use a wireless card, are frequently switching network interfaces or using VPN, or for other reason want to do NAT, then this outlines the easiest way to set it up with Ubuntu.  The setup here is very similar to what [http://www.libvirt.org libvirt] uses for QEMU networking.                                                         
Normally, the best way to do guest networking is by setting up a bridge.  However, if you use a wireless card, are frequently switching network interfaces or using VPN, or for other reason want to do NAT, then this outlines the easiest way to set it up with Ubuntu.  The setup here is very similar to what [http://www.libvirt.org libvirt] uses for QEMU networking.                                                         
Line 5: Line 5:
== Install Dependencies ==
== Install Dependencies ==


  sudo apt-get install bridge-utils dnsmasq
  sudo apt-get install bridge-utils dnsmasq
                                         


== Check Kernel Modules ==
== Check Kernel Modules ==


Make sure that all of the following modules are around: either built in to the kernel or loadable.  If you are running a plain distribution kernel, you should have all of these around without doing anything extra.                                                                                                    
Make sure that all of the following modules are around: either built in to the kernel or loadable.  If you are running a plain distribution kernel, you should have all of these around without doing anything extra.


  # lsmod
  # lsmod
Line 24: Line 22:
  nf_conntrack_ipv4      21776  3 iptable_nat               
  nf_conntrack_ipv4      21776  3 iptable_nat               
  nf_conntrack          76688  5 xt_state,ipt_MASQUERADE,iptable_nat,nf_nat,nf_conntrack_ipv4
  nf_conntrack          76688  5 xt_state,ipt_MASQUERADE,iptable_nat,nf_nat,nf_conntrack_ipv4
                                                                                           


== Enabling ip forwarding ==
== Enabling ip forwarding ==


Add the following line to the bottom of <code>/etc/sysctl.conf
Add the following line to the bottom of <code>/etc/sysctl.conf
  net.ipv4.ip_forward=1
  net.ipv4.ip_forward=1


== Configuring a bridge ==
== Configuring a bridge ==


Add the following to the bottom of <code>/etc/network/interfaces
Add the following to the bottom of <code>/etc/network/interfaces</code>
 


  auto br0
  auto br0
Line 48: Line 41:
  bridge_ports none
  bridge_ports none
  pre-up iptables-restore < /etc/iptables.up.rules
  pre-up iptables-restore < /etc/iptables.up.rules


== Installing config files ==
== Installing config files ==


# Copy [[Media:dnsmasq.conf|dnsmasq.conf]] to <code>/ec/dnsmasq.conf</code>
# Copy [[Media:dnsmasq.conf|dnsmasq.conf]] to <code>/etc/dnsmasq.conf</code>
# Copy [[Media:iptables.up.rules|iptables.up.rules]] to <code>/etc/iptables.up.rules</code>
# Copy [[Media:iptables.up.rules|iptables.up.rules]] to <code>/etc/iptables.up.rules</code>
# Copy [[Media:qemu-ifup|qemu-ifup]] to <code>/etc/qemu-ifup</code> and change permissions to <code>755</code>
# Copy [[Media:qemu-ifup|qemu-ifup]] to <code>/etc/qemu-ifup</code> and change permissions to <code>755</code>

Latest revision as of 15:34, 16 May 2015

Setting up NAT with KVM in Ubuntu

Normally, the best way to do guest networking is by setting up a bridge. However, if you use a wireless card, are frequently switching network interfaces or using VPN, or for other reason want to do NAT, then this outlines the easiest way to set it up with Ubuntu. The setup here is very similar to what libvirt uses for QEMU networking.

Install Dependencies

sudo apt-get install bridge-utils dnsmasq

Check Kernel Modules

Make sure that all of the following modules are around: either built in to the kernel or loadable. If you are running a plain distribution kernel, you should have all of these around without doing anything extra.

# lsmod
Module                  Size  Used by
tun                    15616  0      
bridge                 64104  0      
llc                    11504  1 bridge
xt_state                5248  1       
ipt_MASQUERADE          6720  1       
iptable_nat            10512  1       
nf_nat                 24344  2 ipt_MASQUERADE,iptable_nat
nf_conntrack_ipv4      21776  3 iptable_nat               
nf_conntrack           76688  5 xt_state,ipt_MASQUERADE,iptable_nat,nf_nat,nf_conntrack_ipv4

Enabling ip forwarding

Add the following line to the bottom of /etc/sysctl.conf

net.ipv4.ip_forward=1

Configuring a bridge

Add the following to the bottom of /etc/network/interfaces

auto br0
iface br0 inet static
address 10.0.1.1
netmask 255.255.255.0
network 10.0.1.0
bridge_stp off
bridge_maxwait 5
bridge_ports none
pre-up iptables-restore < /etc/iptables.up.rules

Installing config files

  1. Copy dnsmasq.conf to /etc/dnsmasq.conf
  2. Copy iptables.up.rules to /etc/iptables.up.rules
  3. Copy qemu-ifup to /etc/qemu-ifup and change permissions to 755