Connect to the server/VM using Remote Desktop Connection and open up SQL Server Management Sutdio on remote server, then connect to the SQL Server instance.
Now right click on the server and go to Properties.
On the Connections page under Remote server connections, make sure that the Allow remote connections to this server is checked.
Now open SQL Server Configuration Manager.
Visit Protocols for <instance name>, in my case Protocols for MSSQLSERVER under SQL Server Network Configuration node, go to TCP/IP and make sure the ‘Status’ is set to Enabled. If not, right click and select Enable.
After that, again right click and select Properties of TCP/IP protocol.
Goto IP Addresses tab and go down until you see IPALL section. Make sure the TCP Port is set to 1433. If not set it to 1433.
Restart the SQL server for the changes to take effect.
Configuring the Firewall:
Open up Windows Firewall. Go to Inbound Rules and select New Rule.
Add the following rule. Follow images if unclear.
Rule Type: Port
Protocol and Ports: TCP, 1433
Action: Allow the connection
Profile: Domain, Private, Public
Name: SQLTCP1433
Click finish. We need to add another rule for UDP connections as well.
Rule Type: Port
Protocol and Ports: UDP, 1434
Action: Allow the connection
Profile: Domain, Private, Public
Name: SQLUDP1434
Now make SQL Server and SQL Server Browser accessible through firewall.
Rule Type: Program
Program: C:\Program Files\Microsoft SQL Server\<Server version>.<Instance name>\MSSQL\Binn\sqlservr.exe
e.g. C:\Program Files\Microsoft SQL Server\MSSQL14.MSSQLSERVER\MSSQL\Binn
Action: Allow the connection
Profile: Domain, Private, Public
Name: SQLSERVER