0

I have a network 10.20.1.0/24, configured within a machine, which is to be used by VMs on that machine. The IP on the physical interface of that machine is 172.31.10.94/24. I am forwarding internet traffic from IP attached to a VM 10.20.1.2/24 at 172.31.10.94/24 to a linux server 172.31.10.2/24 via default route. The linux server is being used as a gateway here. There is an iproute for 10.20.1.2/24 on the gateway to forward all traffic destined to 10.20.1.2/24 to 172.31.10.94/24.

ip route on machine hosting the VM:

default via 172.31.10.2 dev enp1s0f0 
10.20.1.3 dev tap22-dr2 scope link 
172.31.10.0/24 dev enp1s0f0  proto kernel  scope link  src 172.31.81.94 
192.168.20.0/24 dev enp3s0f0  proto kernel  scope link  src 192.168.20.2 
192.168.20.102 dev tapd29f98b1-44  scope link 
unreachable 192.168.121.0/24  proto bird

Here is my ip route on gateway machine

default via 172.31.10.1 dev eth1 
10.20.1.3 via 172.31.10.94 dev eth1  proto bird 
172.31.10.0/24 dev eth1  proto kernel  scope link  src 172.31.10.2 
192.168.20.102 via 172.31.10.94 dev eth1  proto bird 
192.168.121.0/24 dev eth0  proto kernel  scope link  src 192.168.121.43

I’m trying to nat all internet traffic coming from 10.20.1.0/24 to 172.31.10.1 so that VMs on the host machine can get external connectivity. Any help is much appreciated? enter image description here

P.S: this was a simple implementation for external connectivity in OpenStack with Project Calico.

0

It was an easy fix, though I'm not sure if it is the best solution.

# iptables -t nat -A POSTROUTING -o eth1 -s 10.20.1.0/24 -j MASQUERADE

Please suggest if there are any better ways.

| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.