我该如何设置NAT? [英] how can i set up NAT?

查看:98
本文介绍了我该如何设置NAT?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨每一个

我希望一切顺利

i在我的笔记本电脑和我的笔记本电脑上有一个有效的ip我有一个本地的netrok

我怎么能写一个程序,我可以访问这个程序

这是基于套接字

一切都很好

但是也许我应该使用我的程序使用设置NAT

所以现在我的代码是基础qt和c ++

你知道我能做到吗?

在Windows中

hi every one
i''ll hope everything being ok
i have a valid ip on my laptop and in my laptop i have a local netrok
how can i write a program that i can access to this program
this is base on socket
everything is good
but maybe i should to use of setup NAT with use of my program
so now my code is base qt and c++
do you know can i do it??
in windows

推荐答案

您根本不需要在软件中实现NAPT,因为它应该由防火墙完成(在您的设置中) ,路由器)。



1)了解Windows套接字(winsock),特别注意源和目标地址和端口号的概念。



2)编写一个程序,在2台PC之间实现通信(我假设这是你想要达到的目标)。一个是客户端,另一个是服务器。



3)在客户端和服务器位于同一网络(子网)的设置中测试程序。确保一切正常。



如果您想要允许外部客户端连接到您的服务器,则需要以下步骤。



4)在路由器中设置NAT,或更准确地说,NAPT。您需要将端口号映射到本地网络外部不可见的本地IP地址。例如,您可以配置路由器,以便将所有外部传入连接(例如,端口10100)转发到IP地址,例如192.168.0.5(这是本地网络上服务器的IP地址)。 />


5)如果Internet上的外部客户端使用正确的端口号(如步骤4中所选)和正确的公共IP,则现在应该可以连接到服务器您的路由器的地址。



6)您的客户端 - 服务器程序应该透明地工作,不需要更改软件。
You do NOT need to implement NAPT in your software at all, as it should all be done by the firewall (in your setup, the router).

1) Learn about Windows Sockets (winsock), in particular pay attention to concept of source and destination addresses and port numbers.

2) Write a program which will implement communicatins between 2 PCs (I am assuming this is what you want to achieve at least). One will be the client the other will be the server.

3) Test the program in a setup where both client and server are on the same network (subnet). Make sure everything works correctly.

Below are the steps required if you want to, for example, allow external clients to connect to your server.

4) Set up NAT, or more correctly, NAPT in your router. You will need to map a port number to a local IP address that is not visible from outside your local network. For example, you can configure the router so that all external incoming connections on, for example, port 10100 are forwarded to IP address, for example, 192.168.0.5 (which is the IP address of the server on your local network).

5) The external client on the Internet should now be able to connect to the server if it uses the correct port number (as selected in step 4) and the correct public IP address of your router.

6) Your client-server program should work transparently with no software changes.


这篇关于我该如何设置NAT?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆