Skip to content

Commit 2a88f86

Browse files
committed
Fix Static NAT/Port Forwarding when VM NIC is not the default
1 parent 3c1f031 commit 2a88f86

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

systemvm/debian/opt/cloud/bin/configure.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ def forward_vr(self, rule):
14481448
)
14491449
fw4 = "-j SNAT --to-source %s -A POSTROUTING -s %s -d %s/32 -o %s -p %s -m %s --dport %s" % \
14501450
(
1451-
self.getGuestIp(),
1451+
self.getGuestIpByIp(rule['internal_ip']),
14521452
self.getNetworkByIp(rule['internal_ip']),
14531453
rule['internal_ip'],
14541454
internal_fwinterface,
@@ -1567,6 +1567,13 @@ def processStaticNatRule(self, rule):
15671567
self.fw.append(["nat", "front", "-A POSTROUTING -s %s -d %s -j SNAT -o %s --to-source %s" %
15681568
(self.getNetworkByIp(rule['internal_ip']), rule["internal_ip"], self.getDeviceByIp(rule["internal_ip"]), self.getGuestIpByIp(rule["internal_ip"]))])
15691569

1570+
internal_device = self.getDeviceByIp(rule["internal_ip"])
1571+
internal_vr_ip = self.getGuestIpByIp(rule["internal_ip"])
1572+
if internal_device and internal_vr_ip and internal_device != device:
1573+
self.fw.append(["nat", "front",
1574+
"-A POSTROUTING -o %s -d %s/32 -j SNAT --to-source %s" %
1575+
(internal_device, rule["internal_ip"], internal_vr_ip)])
1576+
15701577

15711578
class IpTablesExecutor:
15721579

0 commit comments

Comments
 (0)