Skip to content

Networking 基础

理解 IP 地址, ports, DNS, and HTTP — 基本的 network communication.

你将学到

  • IP 地址, ports, and TCP/IP model
  • 如何 DNS resolves 领域 names 到 IP 地址
  • HTTP 请求, 响应, and 状态 codes
  • 常见 networking commands: ping, curl, netstat

概念讲解

IP 地址和端口

Every device on a network has an IP address — a unique identifier that lets other devices find it. IPv4 addresses look like 192.168.1.1; IPv6 addresses are longer, like 2001:db8::1. Ports are numbered channels on an IP address (0–65535). A web server typically listens on port 80 (HTTP) or 443 (HTTPS). The combination of IP and port — 192.168.1.1:3000 — identifies a specific service on a specific machine.

DNS

The Domain Name System (DNS) translates human-readable domain names like 示例.com into IP addresses that computers use to connect. When you type a URL, your computer queries a DNS resolver, which returns the IP address. DNS also stores other records: MX records for email, CNAME records for aliases, and TXT records for verification. The dig and nslookup commands let you query DNS records directly.

HTTP

HTTP is the protocol that web browsers and servers use to communicate. A client sends a request with a method (GET, POST, PUT, DELETE) and a URL. The server returns a response with a status code and a body. Status codes in the 200s mean success, 300s mean redirection, 400s mean client errors, and 500s mean server errors. HTTPS adds TLS encryption on top of HTTP to protect data in transit.

Diagnostic Commands

DevOps engineers use several commands to diagnose network issues. ping checks if a host is reachable. curl makes HTTP requests from the terminal. netstat and ss show which ports are in use. traceroute shows the path packets take to a destination. These tools are indispensable for debugging connectivity issues and verifying that services are accessible.

Security Considerations

Network security is a core DevOps responsibility. Use firewalls to restrict which ports are accessible. Use TLS to encrypt traffic in transit. Use VPN or SSH tunnels to access internal services securely. Understand the difference between public and private IP ranges — 10.x.x.x, 172.16.x.x, and 192.168.x.x are private and not routable on the internet. Misunderstanding network boundaries is a common cause of security incidents, so always verify which interfaces and ports your services are exposed on.

示例代码

              # Check connectivity
ping -c 4 google.com              # send 4 ping packets
curl -I https://example.com       # fetch HTTP headers only

# DNS lookups
dig example.com                   # query A record
dig MX example.com                # query mail records
nslookup api.example.com

# Inspect open ports and connections
ss -tlnp                           # list listening TCP ports
netstat -tlnp                     # older alternative

# Make an API request
curl -X POST https://api.example.com/users \
  -H "Content-Type: application/json" \
  -d '{"name":"Alice"}'
            

ping 检查 reachability, dig 查询 DNS, ss/netstat show 打开 ports, and curl 制作 HTTP 请求. 这些是 核心 network diagnostic tools.

动手试一试

常见错误

错误写法

Confusing TCP and UDP

正确做法

TCP 是连接-oriented and reliable (web, email). UDP 是 connectionless and 快但 可能 drop packets (DNS, video streaming). 选择 based on whether 你需要 guaranteed delivery.

错误写法

Forgetting 到检查 DNS propagation 之后更改

正确做法

DNS 更改能 take minutes 到 hours 到 propagate. Use dig 针对不同 resolvers (dig @8.8.8.8 示例.com) 到检查 propagation 状态.

练习 Networking 基础

1 个练习

练习 Networking 基础

查阅不认识的术语

新手友好的术语表用大白话解释编程术语——变量、函数、DOM、Promise 等等。

查看术语表

动手做项目

通过引导式项目应用所学,含起始代码与解决方案。

查看项目

解读错误信息

用大白话解释常见错误——什么意思、为什么发生、如何修复。

查看错误