Search code examples
javaazureazure-web-app-serviceazure-virtual-machinewindows-firewall

Open custom inbound firewall ports e.g. 8077 by any way using java in azure


I am launching one windows instance in Azure(Microsoft) using Java and trying to open few inbound ports like 445, 8077 for my work. I have also tried using Security groups port opening but it is only opening the inbound ports at security group level, not at the system level. Provide me some solution so that I can open either before launch itself or after launch is also fine. I have done the same thing in AWS as asked in below URL:
Open some custom inbound ports e.g. 8077 by using 80 or 3389


Solution

  • If my understanding is right,you use a Windows VM in Azure(Iaas service). It is same with AWS instance, you could use Power Shell to open port 8077 on Windows Firewall.

    netsh advfirewall firewall add rule name="Open Port 8077" dir=in action=allow protocol=TCP localport=8077
    

    On Azure VM, you also need open port on Azure NSG. enter image description here

    Update:

    If you want to use Azure java SDK to do this, you could use this example.

    I modify the example to add Custom Script Extension like below:

            windowsVM.update()
                .defineNewExtension("shuitest")
                .withPublisher("Microsoft.Compute")
                .withType("CustomScriptExtension")
                .withVersion("1.9")
                .withMinorVersionAutoUpgrade()
                .withPublicSetting("commandToExecute", "netsh advfirewall firewall add rule name=\"Open Port 8077\" dir=in action=allow protocol=TCP localport=8077")
                .attach()
            .apply();
    

    You could check my code on Github.