域名和端口号

域名和IP地址

由一串用点分隔的名字组成,www.abc.com
是IP 地址的别名,方便记忆。

端口号

通过IP 地址可以找到网络上的计算机。
通过端口号,则可以找到计算机上运行的程序。image.png

访问域名

我们可以使用ping 命令来尝试访问网址:

  1. $ ping www.baidu.com
  2. PING www.a.shifen.com (36.152.44.95): 56 data bytes
  3. 64 bytes from 36.152.44.95: icmp_seq=0 ttl=56 time=11.452 ms
  4. 64 bytes from 36.152.44.95: icmp_seq=1 ttl=56 time=16.187 ms
  5. 64 bytes from 36.152.44.95: icmp_seq=2 ttl=56 time=12.856 ms
  6. ^C
  7. --- www.a.shifen.com ping statistics ---
  8. 3 packets transmitted, 3 packets received, 0.0% packet loss
  9. round-trip min/avg/max/stddev = 11.452/13.498/16.187/1.986 ms

我们可以尝试使用这个IP 在浏览器中访问一下试试:
image.png

因此我们通常使用域名来访问网址,也就是IP 地址的别名,否则太难记忆啦。

我们可以拆解一下访问域名/网站的过程:
1)本地电脑,将访问指令传送给远程电脑;
2)远程电脑上装有WEB 服务器,当我们将地址输入后,还需要设置一个端口,也就是上面提到的端口号,告诉远程电脑,我们需要访问装有WEB 服务器的软件,由该软件为访问者提供需要访问的内容;
3)本地电脑获得远程电脑数据,加载想要访问的网页。

通常我们不指定端口,则会使用默认的端口。比如使用ssh,默认为22,访问web 服务器,默认为80。

如果我们给了一个错误的端口,则无法正常访问需要的服务了:
image.png

SSH

ssh,全称secure shell (SSH),是一种使用协议连接到远程计算机的软件程序。

SSH 目前较为可靠,专为远程登陆会话和其他网络服务提供安全性协议。

在mac os, ubuntu, linux 中,我们都是可以通过终端直接使用的:
image.png

通过网络,将客户端的指定,传输给服务器;服务器执行了指令后,通过网络,再将结果返回给客户端。
实现远程的使用。

image.png

我们可以尝试一下ssh 远程访问自己的服务器,或者也可以创建一个虚拟机,用本地电脑访问虚拟机,关于授权信息,选择yes:

$ ssh mugpeng@192.168.130.128 -p 22
The authenticity of host '192.168.130.128 (192.168.130.128)' can't be established.
ECDSA key fingerprint is SHA256:uQKHuYrukuWxYAmR7owG6f+Xz7q2KD6a+lgxXbfLy6c.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.130.128' (ECDSA) to the list of known hosts.
mugpeng@192.168.130.128's password: 
Welcome to Ubuntu 20.04.1 LTS (GNU/Linux 5.8.0-41-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage


243 updates can be installed immediately.
24 of these updates are security updates.
To see these additional updates run: apt list --upgradable

Your Hardware Enablement Stack (HWE) is supported until April 2025.
*** 需要重启系统 ***

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

# 成功进去啦
mugpeng@mugpeng-virtual-machine:~$ ls
Desktop  Documents  Downloads  Music  Pictures  Public  snap  Templates  Videos
mugpeng@mugpeng-virtual-machine:~$

SCP

image.png

端口也可以写成-oPort=

服务器使用scp下载和上传

• 下载
scp -oPort=6652 user@120.77.173.108:/path/filename /home/folder 
• 上传
scp -oPort=6652 /home/filename user@120.77.173.108:/path/folder

还可以指定-r 参数,对文件夹下载或上传(遍历文件)。

就是撸代码有点儿麻烦:

$ scp -r ~/Desktop appe@192.168.1.6:~/Desktop
Password:
test1.txt                                     100%    0     0.0KB/s   00:00

ps:这里强烈建议使用奶牛快传实现文件传输:https://www.yuque.com/mugpeng/pc_skills/kqduxr