I have created a network namespace in debian 8 and created
vpngw. On this
vpngw, I am running OpenVPN as client and have default
gw in this namespace towards global namespace (out from the namespace) and there I have a modem with public IP address, through which I am routing this to the OpenVPN server on the other end by using masquerading.
iptables -t nat -I POSTROUTING -s 10.51.31.2 -0 sierra -j MASQUERADE
Now the problem is, sometime it works and traffic from 10.51.31.2 (IP of
vpngw) gets NATted and works as expected. The tunnel gets established.
But most of the times it is not hitting the iptables rule and not getting NATted.
Can anyone please help me? What is wrong here?