I recently found it was tricky to have both a STATIC IP as well as internet connectivity inside of KVM provisioned VMs. The ultimate reason was that the "GATEWAY" field was not being set right.
The moral of the story: On KVM boxes, when bridging in a virtual network, the virt managed default bridged IP address needs to be set as the gateway... Thus, when your guests are in a "virtual network" - the "gateway" is the internal IP address provided to them by the hypervisor that represents the "outside" of their internal network.
1) Stop the firewalls in iptables:
iptables -F
2) Edit /etc/sysconfig/network-scripts/ifcfg-eth0 like so (obviously the "IPADDR" can be anything you want as long as its in the right range.
DEVICE="eth0"
HWADDR="52:54:00:94:AF:F4"
BOOTPROTO="static" <--- Change this from "dhcp" to "static"
ONBOOT="yes"
NM_CONTROLLED="yes"
IPADDR=192.168.122.171 <--- this is any old arbitrary IP in-range.
NETMASK=255.255.255.0
GATEWAY=192.168.122.1 <--- this is aliased ipaddress of your host inside of KVM.
USERCTL="no"3) Restart networking so that the IP and GATEWAY can be reset.
service network restart
4) Ping somebody and watch the magic unfold:
ping www.yahoo.com
Yay!
If you get a "Destination Host Unreachable":
Your gateway is wrong. Make sure your gateway is the same as your host vm's ipaddress.
If you get an unknown host:
You may not have an assigned IP (IPADDR wrong or out of range).
A strange note to keep in mind --- somehow, even with a bad gateway (i.e. destination host unreachable), I could still resolve hostnames - not sure why.
Nice and quite informative post. I really look forward to your other posts.
ReplyDeleteLenovo - 15.6" ThinkPad Notebook - 4 GB Memory - 320 GB Hard Drive - Black
Lenovo - 14" ThinkPad Notebook - 4 GB Memory - 320 GB Hard Drive - Black (2349GCU)