On 12/09/2013 05:14 AM, scar wrote:> hello i have a server colocated in a datacenter with several external IP
> addresses available to use. the physical server is using one of these
> IPs, and i want to assign another, unused IP to the virtual machine. i
> thought i could just do this by editing the container's
> /etc/network/interfaces, setting a static IP address for eth0 much like
> i did for br0 on the host machine.... but doesn't seem to be working.
> ifconfig shows eth0 has the external address but i can't resolve any
> hostnames nor telnet to a direct IP address (no route to host). if i
> change back to dhcp and let eth0 get an internal address, i can at least
> access the internet but cannot access the virtual machine from the
> internet. what is the trick to giving a VM a routable, external IP
> address? thanks
>
I have a machine running libvirt lxc,
on this machine(host), the network configure looks like this
eth0 is the physical nic, virbr0 is the bridge libvirt created, and vnet0
is the veth device created for libvirt lxc container. you can see, the eth0
is a port of virbr0, and the ip is assigned on virbr0.
ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::5054:ff:fe39:626f prefixlen 64 scopeid 0x20<link>
ether 52:54:00:39:62:6f txqueuelen 1000 (Ethernet)
RX packets 1502 bytes 93029 (90.8 KiB)
RX errors 0 dropped 10 overruns 0 frame 0
TX packets 546 bytes 52825 (51.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
virbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.122.178 netmask 255.255.255.0 broadcast 192.168.122.255
ether 52:54:00:39:62:6f txqueuelen 0 (Ethernet)
RX packets 419 bytes 26899 (26.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 328 bytes 42246 (41.2 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
vnet0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet6 fe80::b4a1:32ff:fe56:5706 prefixlen 64 scopeid 0x20<link>
ether b6:a1:32:56:57:06 txqueuelen 1000 (Ethernet)
RX packets 21 bytes 1642 (1.6 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 214 bytes 11884 (11.6 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
brctl show
bridge name bridge id STP enabled interfaces
virbr0 8000.52540039626f yes eth0
vnet0
And in container
I change the ip of eth0 to 192.168.122.33 and add a route rule
ip route add default via 192.168.122.1 dev eth0
then the container can access the outside.
I think it should work even you change the 192.168.x.x to the
global ip.