0

I have a task to create connections between host A with a few IP addresses, say: 1.2.3.4, 1.2.3.5, 1.2.3.6, 1.2.3.7 host B with 1 IP 2.3.4.5 On host B there two lxd containers lx1, and lx2. The goal is: lx1 must be visible in the net as 1.2.3.4 and lx2 be visible as 1.2.3.5.

So far there is on host A:

ip link set gre1 down
ip tunnel del gre1
ip tunnel add gre1 mode gre remote 2.3.4.5 local 1.2.3.6 ttl 255
ip link set gre1 up
ip addr add 10.10.10.1/24 dev gre1

ip link set gre2 down
ip tunnel del gre2
ip tunnel add gre2 mode gre remote 2.3.4.5 local 1.2.3.7 ttl 255
ip link set gre2 up
ip addr add 10.10.10.3/24 dev gre2

iptables -P PREROUTING ACCEPT
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P POSTROUTING ACCEPT
iptables -A PREROUTING -d 1.2.3.4/32 -j DNAT --to-destination 10.10.10.2
iptables -A PREROUTING -d 1.2.3.5/32 -j DNAT --to-destination 10.10.10.4
iptables -A POSTROUTING -j MASQUERADE

On host B:

ip link set gre1 down
ip tunnel del gre1
ip tunnel add gre1 mode gre remote 1.2.3.6 local 2.3.4.5 ttl 255
ip link set gre1 up
ip addr add 10.10.10.2/24 dev gre1

ip link set gre2 down
ip tunnel del gre2
ip tunnel add gre2 mode gre remote 1.2.3.7 local 2.3.4.5 ttl 255
ip link set gre2 up
ip addr add 10.10.10.4/24 dev gre2

iptables -P PREROUTING ACCEPT
iptables -P INPUT ACCEPT
iptables -P OUTPUT ACCEPT
iptables -P POSTROUTING ACCEPT
iptables -A PREROUTING -d 10.10.10.2/32 -j DNAT --to-destination 1.2.3.4
iptables -A PREROUTING -d 10.10.10.4/32 -j DNAT --to-destination 1.2.3.5
iptables -A POSTROUTING -j MASQUERADE

ifconfig vc1 172.16.0.1 pointopoint 1.2.3.4 netmask 255.255.255.255 up
ifconfig vc1 172.16.0.2 pointopoint 1.2.3.5 netmask 255.255.255.255 up

lx1 and lx2 has p2p network nic type. lx1 /etc/network/interfaces:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 1.2.3.4/32
    pointopoint 172.16.0.1
    gateway 172.16.0.1
    dns-nameserver 8.8.8.8
    dns-nameserver 8.8.4.4

lx2 /etc/network/interfaces:

auto lo
iface lo inet loopback

auto eth0
iface eth0 inet static
    address 1.2.3.5/32
    pointopoint 172.16.0.2
    gateway 172.16.0.2
    dns-nameserver 8.8.8.8
    dns-nameserver 8.8.4.4

Now,I can ping 1.2.3.4 and 1.2.3.5. http servers in containers serves files, and have "good" IPs, but: connections initiated by lx1 or lx2 have "outgoing" IP 2.3.4.5

What to add/change to configuration to met requirements:? Traffic initiated by lx1 (lx2) has outgoing IP 1.2.3.4 (1.2.3.5) and responses also get back to them. For example browser started in container, visiting page https://www.showmyip.gr/ will show 1.2.3.4 (1.2.3.5).

Sorry, for public IPs, but task also concerns public IPs.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.