I deployed a .NET Windows Service on Azure Virtual Machine running Windows Server with an opened port that allow me to connect to it, this service is like a server using socket. The problem is that when I try to connect from my PC to that hosted server it doesn't work and I get this exception: System.Net.Sockets.SocketException: 'No such host is known'. The port is opened and visible from my PC. Can someone tell me why I get that exception? If I run locally all works ok.
The Exception seems to be a DNS issue. I am not familiar with C#, from networking, you could check the followings on your side:
Windows service is running and the port is listening on the Azure VM.
The port is allowed for outbound traffic from your PC and Inbound traffic on your Azure VM. Check the VM firewall settings on both sides between your PC and Azure VM. Also, you could check the NSG settings follow this. You could use telnet vmpublicIP port on your PC CMD to verify network connectivity.
Verify your PC can resolve the address of hosted server if you connect it via its DNS name. You could use the NSlookup or DIG to verify this. If it's DNS issue, you also could add a line in hosts file (located in %WINDIR%\system32\drivers\etc on windows) mapping the hosted server's IP to a name.
Hope this helps.
Related
I am developing bot solution, in which I am making REST call to get some details from other server.
In local host my code is working fine, but after publishing the code in Azure I am getting the below error:
System.Net.WebException: No such host is known No such host is known —> System.Net.Http.HttpRequestException: No such host is known —> System.Net.Sockets.SocketException: No such host is known
I am using HttpWebRequest option.
May I know what could be the reason?
I'm not sure the solution below will work for you but it looks like the solution is worth to be checked out. Here is an answer that may have useful information. Take a look at this answer and check your solution accordingly:
The problem description:
I deployed a .NET Windows Service on Azure Virtual Machine running
Windows Server with an opened port that allow me to connect to it,
this service is like a server using socket. The problem is that when I
try to connect from my PC to that hosted server it doesn't work and I
get this exception: System.Net.Sockets.SocketException: 'No such host
is known'. The port is opened and visible from my PC. Can someone tell
me why I get that exception? If I run locally all works ok.
The answer:
The Exception seems to be a DNS issue. I am not familiar with C#, from
networking, you could check the followings on your side:
Windows service is running and the port is listening on the Azure VM.
The port is allowed for outbound traffic from your PC and Inbound
traffic on your Azure VM. Check the VM firewall settings on both sides
between your PC and Azure VM. Also, you could check the NSG settings
follow this. You could use telnet vmpublicIP port on your PC CMD to
verify network connectivity.
Verify your PC can resolve the address of the hosted server if you connect
it via its DNS name. You could use the NSlookup or DIG to verify this.
If it's DNS issue, you also could add a line in hosts file (located in
%WINDIR%\system32\drivers\etc on windows) mapping the hosted server's
IP to a name. Hope this helps.
.NET Service System.Net.Sockets.SocketException: 'No such host is known'
I am trying to figure out how to setup a development environment for developing multiple apis locally.
My development environment is as follows:
Host Machine: 10.10.4.19
SQL Server 2016 Express Installed on the host listening at 10.10.4.19,1433 which I can connect to locally from the host and from other PCs on the network.
Docker for windows stable version, installed and developing netcore webapis which get containerized and run locally which I want to connect to the SQL Server Instance on the host.
Ideally each container would have a static IP in some NAT network, however I have been unable to get static IPs working for the default NAT network setup with docker for windows.
I have tried setting up a transparent network, however this probably won't work as I don't really want these on network. I would like them only to be accessible by the host, or through some port mapping by the host IP through the docker run -p command.
I have the containers running and working (except for static ip addresses) however I cannot access the host. I can ping (what I am assuming is) the host at the gateway IP address found in the container, but I can't seem to access any services running on the host.
From within the container I can ping other PCs in the network (IE 10.10.4.22) and have internet access, but for some reason I cannot ping the host at 10.10.4.19. I get the Request timed out.
So the question I am asking is, how can i setup a NAT network with internet access where containers can talk to the host and other containers and the host can talk to all containers too. And ideally I could setup static IPs for each service where I could setup nginx or some other reverse proxy on the host to help proxy requests to each container.
I have tried creating a separate NAT using docker network create -d NAT mynat but it tells me the object already exists.
I have tried accessing the host's SQL instance by the 10.10.4.19 ip address and the 172.20.xxx.1 address defined on the virtual NIC however none of them will connect to the SQL instance or any website/api I have running on the host. The containers however can access other PC's websites/apis on the network. Just not the host.
So I guess I am asking if it is even possible to access the host's services from inside a container too?
A lot of the documentation I have found is based on linux and I'm not sure if it can be used the same or not
Any direction anyone can give will be greatly appreciated.
EDIT:
After playing all night with the docker networks, I was able to replace the default docker NAT network with my own so I could specify static IP address.
What I did for that was add "bridge: "none" to the daemon.json file located at C:\ProgramData\Docker\config. Which made it so the default NAT network isn't created by default
Then I ran the following commands in an admin powershell to create my own NAT network
PS C:\WINDOWS\system32> stop-service com.docker.service
PS C:\WINDOWS\system32> stop-service hns
PS C:\WINDOWS\system32> del 'C:\ProgramData\Microsoft\Windows\HNS\HNS.data'
PS C:\WINDOWS\system32> Get-ContainerNetwork | Remove-ContainerNetwork
PS C:\WINDOWS\system32> Get-NetNat | Remove-NetNat
PS C:\WINDOWS\system32> start-service hns
PS C:\WINDOWS\system32> start-service com.docker.service
PS C:\WINDOWS\system32> docker network create -d nat --subnet=192.168.1.0/24 --gateway=192.168.1.1 mynat
d0d31ecf39ec6cada948c3158b176e9a67d7e0ba6458208d9c91b240587c0763
I am then able to start my containers with the following command
docker run -itd --net=mynat --ip=192.168.1.25 --rm <containername>
However: I am still unable to access the SQL Server Express instance on the host machine. I thought I would be able to access it at 192.168.1.1,1433\SQL2016 or 10.10.4.19\SQL2016 however I get the error: provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified for both.
Pinging 192.168.1.1 does return results, however pinging 10.10.4.19 returns Request timed out.
I have set a static IP of 192.168.1.1 on the virtual NIC adapter and that didn't seem to help anything. Hopefully someone knows how to access the host from within a container. Thanks!
EDIT2:
I am able to hit an api running on the host now. To be honest I am not sure what changed. But i can now hit a service at http://192.168.1.1/api running on the host from the within the container.
NOTE: That the port binding doesn't seem to work though going to the static IP setup on the container. You can only hit the service on the EXPOSE port in the dockerfile and running the docker command with -p 5600:9606 doesn't expose on 5600 it is still exposed only on 9606. calling 192.168.1.25:9606 works but localhost:5600 does not
However I am still unable to connect to the SQL Server Express instance on the 192.168.1.1 IP. I have tried adding the 192.168.1.1 ip to the SQL Server bindings but that doesn't seem to work.
I can connect from the host at 10.10.4.19,1433\SQL2016 but cannot connect at 192.168.1.1,1433\SQL2016 so I am assuming that is the issue at hand here. Windows Firewall is disabled.
I have set the virtual NAT NIC to use the static ip 192.168.1.1 also but still cannot connect to the SQL Server instance at 192.168.1.1,1433\SQL2016
The last thing i had to do was enable both ipv4 and ipv6 (as ipv6 was used for some of the authentication checks I guess) on the host server for sql server express 2016. And added firewall rules.
Hopefully this will help someone else get setup for local development and single server docker deployments.
The one thing I still cannot do is the host:container port mapping
I'm using VS Express 2012, setting up a simple server and client on a Windows Server 2008R2 machine with all of the latest updates installed. When I have the client try to connect to the running server using "localhost" as the host to connect to, everything works fine. When I have the client try to connect to the running server using the IP address or the actual host name, I see the "No connection could be made because the target machine actively refused it 192.168.5.159:13000 ..." error message. netstat shows my server is listening on the same port as reported in the error message (13000). I've modified the Windows Firewall setting to allow my client and server to communicate through the Windows Firewall. I've added an entry to my Hosts file associating my host name with the IP address. Any suggestions as to what else I can try? All of this is being done on a private (work) network.
Usually when you set up a server, you need to specify the hostname or IP the server listens on. When you initialize a server to use localhost, you can only use localhost to connect to it.
If you want a server to accept requests from every source you need to see if you can use a wildcard to accept all connections. For example 0.0.0.0 is used a lot.
I'm a little confused when it comes to socket servers in terms of deploying it online.
Running locally is fine as most tutorials get you to make a server application and a client application which I can execute. Done all that for awhile now and I'm happy with it but now I want to try it using a web host.
How would I deploy the socket server to my web host and then run the server? do I just upload the program to the server and run www.mywebpage.com/mysocketserver (assuming the program is called mysocketserver.exe)
may sound like a stupid question but I'm having one of those brain dead moments.
[Edit]
Great answers guys thank you. Shame I can only mark one as the answer.
Most hosting services are website related: you upload your website to their server and the host takes care of provisioning the application.
However you haven't written a website that is served by a web server, but a socket server, which is more akin to the web server itself that runs a website.
As a result you will need a host that will allow you to install and run applications, such as a Virtual Private Server service, rent a physical server or use a cloud service such as Amazon EC2.
You usually Remote Desktop or SSH into the server you are renting (or own) to upload and start the application either as a normal application, a Service or a Daemon.
Once you have installed your socket server on the host server and started the application running you should be able to contact your service using the IP address for your server and the port that you are running your socket server on.
For example, if your ip address is 10.0.0.1 and you've written your socket server to listen on port 1234, you should be able to contact your service at address 10.0.0.1:1234.
Take into account firewalls allowing access to that port.
You will also then be able to use a DNS service such as DynDns to assign a domain name to that ip address.
You can't do that unless your socket server is using HTTP as a protocol.
You are using a port for your server, right? The ports are used to identify which application to talk with.
When you browse the web using "http://something" you really say let me get the stuff which can be found on the IP 1.2.3.4 (DNS lookup) using port 80 (which is registered for HTTP). You don't have to specify the port in the browser since all browsers know that HTTP uses port 80.
So what you are really should do is to put the socket server on your host and tell your customers/users that they can connect to your socket server at port XXX on host "www.mywebpage.com".
If you've built a client you'll just hard code the port in it or specify the default port automatically.
The problem in the Internet is the routing/name translation, so that mywebpage gets translated into the correct IP address.
Either your webserver needs a fixed public IP address or you need to use a service like dynds which will dynamically map your changing IP address to the static name.
I am writing silverlight 3 application which is working on network.
It works like client-server application. There is WinForm application for server and silverlight application for client.
I use TcpListener on server and connect from client to it with Socket.
In local network it works fine, but when I try to use it from internet it don't connect to server.
I use IP address on local network and real IP with port number for internet version.
I get error 10013 AccessDenied.
Port number is correct and access policy exist.
Firewall is turned of.
Where is the problem?
Thanks.
Have you tried to check the general availability of the connection from your machine to the Internet server with telnet ?
The problem was that computer, where hosted website hasn't real IP address, and I couldn't connect to it from internet. I added Real IP address and everything works fine now.