T
T
Taurus2017-03-16 18:52:36
OpenVZ
Taurus, 2017-03-16 18:52:36

How to configure the host so that the IP of the Openvz container is determined correctly?

The system is running Proxmox 3.4
. The container has access to the Internet. You can connect to it at yyy120.
But for outgoing connections from it, the IP is determined by the host, not the container.
How to solve the problem?
I suspect you need to write iptables rules.
Host network settings:

auto vmbr1
iface vmbr1 inet static
        address  y.y.y.119
        netmask  255.255.255.0
        bridge_ports none
        bridge_stp off
        bridge_fd 0

post-up echo 1 > /proc/sys/net/ipv4/ip_forward
post-up iptables -t nat -A POSTROUTING -s 'y.y.y.119/24' -o eth0 -j MASQUERADE

Container:
cat /etc/network/
# Auto gerated lo interface
auto lo
iface lo inet loopback

# Auto generated venet0 interface
auto venet0
iface venet0 inet manual
        up ifconfig venet0 up
        up ifconfig venet0 127.0.0.2
        up route add default dev venet0
        down route del default dev venet0
        down ifconfig venet0 down

iface venet0 inet6 manual
        up route -A inet6 add default dev venet0
        down route -A inet6 del default dev venet0

auto venet0:0
iface venet0:0 inet static
        address y.y.y.120
        netmask 255.255.255.255

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Taurus, 2017-03-19
@Taurus

The complete working config looks like this.

auto eth0
iface eth0 inet static

        address x.x.x.107 
        netmask  255.255.255.0
        network x.x.x.0
        broadcast x.x.x.255
        gateway x.x.x.254

auto vmbr1
iface vmbr1 inet static
        address  y.y.y.119
        netmask  255.255.255.0
        bridge_ports none
        bridge_stp off
        bridge_fd 0

        post-up echo 1 > /proc/sys/net/ipv4/ip_forward
        post-up iptables -t nat -A POSTROUTING -s 'y.y.y.119/24' -o vmbr1 -j SNAT --to x.x.x.107

M
Mystray, 2017-03-16
@Mystray

But for outgoing connections from it, the IP is determined by the host, not the container.

What did you actually want?
MASQUERADE and replaces the source address with the host address in outgoing connections

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question