P
P
p4s8x2014-03-01 06:30:30
linux
p4s8x, 2014-03-01 06:30:30

Proxmox and container with internal network

What I'm trying to do:
Create a container, with an IP such as 192.168.2.2, so that it has access to the Internet and then forward the port to it from the host machine.
What I did:
Started a container, in it bridge1 c 192.168.2.1
network parameters are as follows:

# Auto generated 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 192.168.2.2
        netmask 255.255.255.255

Host machine network configuration
# network interface settings
auto lo
iface lo inet loopback

iface eth0 inet manual
        broadcast  155.76.167.159
        up route add -net 155.76.167.128 netmask 255.255.255.224 gw 155.76.167.129 eth0
# default route to access subnet

auto vmbr0
iface vmbr0 inet static
        address  155.76.167.155
        netmask  255.255.255.224
        gateway  155.76.167.129
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0

auto vmbr1
iface vmbr1 inet static
        address  192.168.2.1
        netmask  255.255.255.0
        bridge_ports eth0
        bridge_stp off
        bridge_fd 0

There is access from the host to the container via ip 192.168.2.2.
Ping also goes from the container to 192.168.2.1, but there is no Internet in the container.
Tried to add route add default gw 192.168.2.1 , same result.
There is no special understanding in network settings, help is required.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Petrikov, 2014-03-02
@RicoX

Set up NAT on the hypervisor.

C
Constin, 2014-05-30
@Constin

Smoke man iptables
on the hypervisor do the following:
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to external_ip_on_hypervisor
(and where eth0 is the external IP interface on the hypervisor )
this will give us the Internet on all containers
, then we forward ports using the example of port 25
iptables -t nat -A PREROUTING -p tcp -d external_ip --dport 25 -j DNAT --to-destination local_ip_container:25
iptables -A FORWARD -i eth0 -d external_IP -p tcp --dport 25 -j ACCEPT
Then you need to make sure that all these rules do not fly off on reboot

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question