diff --git a/conf/gns3_server.conf b/conf/gns3_server.conf index 5971376c..5e36fb31 100644 --- a/conf/gns3_server.conf +++ b/conf/gns3_server.conf @@ -40,7 +40,12 @@ user = gns3 password = gns3 ; Only allow these interfaces to be used by GNS3, for the Cloud node for example (Linux/OSX only) -allowed_interfaces = eth0,eth1 +; Do not forget to allow virbr0 in order for the NAT node to work +allowed_interfaces = eth0,eth1,virbr0 + +; Specify the NAT interface to be used by the NAT node +; Default is virbr0 on Linux (requires libvirt) and vmnet8 for other platforms (requires VMware) +nat_interface = vmnet10 [VPCS] ; VPCS executable location, default: search in PATH diff --git a/gns3server/compute/builtin/nodes/nat.py b/gns3server/compute/builtin/nodes/nat.py index b8782ed2..2e745177 100644 --- a/gns3server/compute/builtin/nodes/nat.py +++ b/gns3server/compute/builtin/nodes/nat.py @@ -22,6 +22,9 @@ from ...error import NodeError import gns3server.utils.interfaces +import logging +log = logging.getLogger(__name__) + class Nat(Cloud): """ @@ -29,19 +32,22 @@ class Nat(Cloud): NAT access. """ - def __init__(self, *args, **kwargs): + def __init__(self, name, node_id, project, manager, ports=None): if sys.platform.startswith("linux"): - if "virbr0" not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]: - raise NodeError("virbr0 is missing, please install libvirt") - interface = "virbr0" + nat_interface = manager.config.get_section_config("Server").get("nat_interface", "virbr0") + if nat_interface not in [interface["name"] for interface in gns3server.utils.interfaces.interfaces()]: + raise NodeError("NAT interface {} is missing, please install libvirt".format(nat_interface)) + interface = nat_interface else: - interfaces = list(filter(lambda x: 'vmnet8' in x.lower(), + nat_interface = manager.config.get_section_config("Server").get("nat_interface", "vmnet8") + interfaces = list(filter(lambda x: nat_interface in x.lower(), [interface["name"] for interface in gns3server.utils.interfaces.interfaces()])) if not len(interfaces): - raise NodeError("vmnet8 is missing. You need to install VMware or use the NAT node on GNS3 VM") + raise NodeError("NAT interface {} is missing. You need to install VMware or use the NAT node on GNS3 VM".format(nat_interface)) interface = interfaces[0] # take the first available interface containing the vmnet8 name + log.info("NAT node '{}' configured to use NAT interface '{}'".format(name, interface)) ports = [ { "name": "nat0", @@ -50,7 +56,7 @@ class Nat(Cloud): "port_number": 0 } ] - super().__init__(*args, ports=ports) + super().__init__(name, node_id, project, manager, ports=ports) @property def ports_mapping(self):