New on LowEndTalk? Please Register and read our Community Rules.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
All new Registrations are manually reviewed and approved, so a short delay after registration may occur before your account becomes active.
Assigning IPs to OpenVZ

I have a KVM server and want to split it into 3 OpenVZ servers. I have 2 public IPs and want to assign 1 of them to one of the OpenVZ containers, but I couldn't figure out how to assign the public dedicated IP for the container. Please help and don't hate.
Public IP: 23.45.67.81 and 23.45.67.82
23.45.67.81 => 192.168.1.100 container A
23.45.67.81 => 192.168.1.200 container B
23.45.67.82 => 23.45.67.82 container C
[let's not get into the nested VM hate, this is just a personal server and sharing with friends]
Comments
vzctl set $ctid --ipadd $ip --save
In case you want NAT IP's for containers A and B, have a look at this: https://openvz.org/Using_NAT_for_container_with_private_IPs
I figured out A and B, but C has no internet access after I did that, and if I try to SSH in, I would login to the host node instead of the CT. I figured either I did it wrong or I need iptables to allow access.
Is 23.45.67.82 the KVM's public IP?
Not the real one, just used it as an example.
it's like assigning node's main IP to a container, figure it'll work?
Well I tried to directly assign the IP, didn't work. Also I tried to use an internal IP and forward all requests to that IP, well didn't work either. Iptables rules not correct?
iptables -t nat -A PREROUTING -d 23.45.67.82 -j DNAT --to-destination 192.168.2.100
iptables -t nat -A POSTROUTING -s 192.168.2.100 -j SNAT --to-source 23.45.67.82
@lostinwoods maybe this will help http://www.danpros.com/2014/09/setting-up-nat-vps-on-centos-6-using-ip-tables-and-haproxy
Thanks for the help, that link is for 1 IP and sharing with multiple containers (which I have done correctly). But my case I have 2 IPs and want to assign 1 just to one container.
@lostinwoods just a ref.
more importantly, there's a brief on sharing IP for node/container. can it work now?
Check if the 2nd IP shows in ifconfig on the host node, it should not.
Didn't work
when I ping it I get destination not resolvable.
It does. I'll try removing it from the host node and see if it works.
I figured it out, it was a careless mistake. Thanks to @PetaByet @century1stop @linuxthefish for the help.