Case scenario
I installed SQL Server 2019 on Windows Server 2022, When I successful installed SQL Server, local connection with sql server management studio all good. Well, when I tried to using sqlcmd to connect the SQL Server on another Linux machine.
I encountered an issue like this:
Sqlcmd: Error: Microsoft ODBC Driver 17 for SQL Server : A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online..
Troubleshooting
Check SQL server connection protocol
we know sqlcmd use TCP/IP communicating with the server , so I checked the the server side connection protocol, make sure TCP/IP protocol enabled. Basically, It has been enabled by default. But we still need to make sure it has been enabled.

Check IPAddress and TCP Port 1433
why we check this?
Because on sql server TCP/IP configuration parameter, there is an optional value called Dynamic TCP Port, we have to disable it and set a static IP and port .
Checked TCP 1433, Well, not listening. Further checking, Dynamic TCP Port value set with 0,that means enabled, we had to leave it blank to disable it. At meanwhile, We have to enable the IP just like below:


After Restarting the SQL server, check again:


Add firewall rules for SQL server(optional)
This step is optional, When you still have connection issues you can try this .



