简体   繁体   English

如何连接到 linux 中的本地主机

[英]How to connect to a Localhost in linux

I want to do a connection between a computer simulating being a server and another computer being a user, both with Linux.我想在模拟作为服务器的计算机和作为用户的另一台计算机之间建立连接,两者都使用 Linux。

In the first computer I've created a directory called "server" and in that directory I've done the following command:在第一台计算机上,我创建了一个名为“server”的目录,并在该目录中执行了以下命令:

python3 -m http.server 8080

Then I can see that directory going to the localhost.然后我可以看到该目录转到本地主机。 But what I want is to see that localhost from the other computer, I tried with wget, and the gnome system of sharing files but none of them worked, and I'm not seeing any solution online.但我想要的是从另一台计算机上查看 localhost,我尝试使用 wget 和共享文件的 gnome 系统,但它们都不起作用,而且我没有看到任何在线解决方案。

I'm not sure I fully understand your question but if you want to reach your folder from an other computer with your command python3, you can use the option -b followed by an IP address used on your linux.我不确定我是否完全理解您的问题,但如果您想使用命令 python3 从其他计算机访问您的文件夹,您可以使用选项 -b 后跟 linux 上使用的 IP 地址。

All you need to do is get the IP of the server using ifconfig command.您需要做的就是使用ifconfig命令获取服务器的 IP。 ifconfig |如果配置 | grep 192 make sure not to use the broadcast address part. grep 192 确保不要使用广播地址部分。

Now logon to the other machine and hit the command现在登录到另一台机器并点击命令

http://192.168.71.145:8080 http://192.168.71.145:8080

And it should work.它应该工作。 Here I have assumed that your IP is 192.168.71.145 and the port is 8080.这里我假设你的 IP 是 192.168.71.145,端口是 8080。

Just change the IP and port as per your values.只需根据您的值更改 IP 和端口即可。

If I'm understanding your question correctly you want to connect to the server from another machine on the same network.如果我正确理解您的问题,您希望从同一网络上的另一台机器连接到服务器。

If so you can run hostname -I on the server to output to the local IP address of the server, you can then use this on the other machine to connect to it (provided they are on the same network)如果是这样,您可以在服务器上运行hostname -I到 output 到服务器的本地 IP 地址,然后您可以在另一台机器上使用它来连接它(前提是它们在同一网络上)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM