1. ifconfig

ifconfig 是用于配置和显示网络接口状态的命令。在较新的Linux系统中,推荐使用 ip 命令替代。

  • 基本用法
    
    ifconfig [interface] [up/down]
    
  • 示例
    
    ifconfig eth0 up
    ifconfig eth0 192.168.1.100 netmask 255.255.255.0
    

2. ip

ip 命令提供了更为强大的网络配置功能,包括地址、路由、隧道、邻居和协议等。

  • 基本用法
    
    ip addr show [interface]
    ip route show
    ip link set [interface] up/down
    
  • 示例
    
    ip addr add 192.168.1.100/24 dev eth0
    ip route add default via 192.168.1.1
    

3. ping

ping 用于测试网络连接,通过发送ICMP回显请求并接收响应来检查网络连通性。

  • 基本用法
    
    ping [hostname or IP address]
    
  • 示例
    
    ping google.com
    

4. netstat

netstat 显示网络连接、路由表、接口统计信息、伪装连接和监听端口。

  • 基本用法
    
    netstat -tulnp
    
  • 示例
    
    netstat -tulnp | grep 80
    

5. ss

ssnetstat 的替代品,提供了更详细的网络连接信息。

  • 基本用法
    
    ss -tulnp
    
  • 示例
    
    ss -tulnp | grep 80
    

6. curl

curl 用于传输文件和获取信息,支持多种协议。

  • 基本用法
    
    curl [url]
    
  • 示例
    
    curl http://www.google.com
    

7. wget

wget 用于从网络上下载文件,支持断点续传。

  • 基本用法
    
    wget [url]
    
  • 示例
    
    wget http://www.google.com
    

8. route

route 用于显示和修改本地路由表。

  • 基本用法
    
    route add [destination] via [gateway]
    
  • 示例
    
    route add default gw 192.168.1.1
    

9. traceroute

traceroute 用于追踪数据包到达目标主机的路径,显示经过的每个路由器的IP地址。

  • 基本用法
    
    traceroute [hostname or IP address]
    
  • 示例
    
    traceroute google.com
    

10. nslookup

nslookup 用于查询域名对应的IP地址或查询IP地址对应的域名。

  • 基本用法
    
    nslookup [domain or IP address]
    
  • 示例
    
    nslookup google.com
    

11. host

host 类似于 nslookup,用于查询域名对应的IP地址。

  • 基本用法
    
    host [domain or IP address]
    
  • 示例
    
    host google.com
    

12. dig

dig 是一个功能强大的域名信息查询工具,可以查询DNS记录。

  • 基本用法
    
    dig [domain] [record type]
    
  • 示例
    
    dig google.com A
    

13. mtr

mtr 结合了 pingtraceroutenslookup 的功能,可以实时显示网络连接状态。

  • 基本用法
    
    mtr [hostname or IP address]
    
  • 示例
    
    mtr google.com
    

14. tcpdump

tcpdump 用于捕获网络数据包,分析网络流量。

  • 基本用法
    
    tcpdump -i [interface] [expression]
    
  • 示例
    
    tcpdump -i eth0 tcp port 80
    

15. nmap

nmap 用于扫描网络上的开放端口,检测目标主机的安全漏洞。

  • 基本用法
    
    nmap [hostname or IP address]
    
  • 示例
    
    nmap google.com
    

16. netstat -anp

netstat -anp 显示所有网络连接和监听端口,包括进程信息。

  • 基本用法
    
    netstat -anp
    
  • 示例
    
    netstat -anp | grep 80
    

17. systemctl status

systemctl status 查看系统服务状态,包括网络服务。

  • 基本用法
    
    systemctl status [service name]
    
  • 示例
    
    systemctl status network-manager
    

18. systemctl restart

systemctl restart 重启系统服务。

  • 基本用法
    
    systemctl restart [service name]
    
  • 示例
    
    systemctl restart network-manager
    

19. systemctl enable

systemctl enable 设置系统服务开机自启。

  • 基本用法
    
    systemctl enable [service name]
    
  • 示例
    
    systemctl enable network-manager
    

20. systemctl disable

systemctl disable 禁用系统服务开机自启。

  • 基本用法
    
    systemctl disable [service name]
    
  • 示例
    
    systemctl disable network-manager
    

通过掌握以上20个实用命令,您将能够更好地管理和配置CentOS网络。