Linux 提供了丰富的网络相关命令,用于配置、诊断和管理网络连接。以下分类整理常用命令及其用途:
ifconfig
(旧版工具)
ifconfig eth0 192.168.1.100 netmask 255.255.255.0
ip
(推荐替代 ifconfig
)
bash
ip addr show # 显示所有接口
ip route add default via 192.168.1.1 # 添加默认网关
nmcli
nmcli connection show
hostnamectl
hostnamectl set-hostname myserver
ping
ping google.com
traceroute
/ tracepath
traceroute example.com
mtr
ping
+ traceroute
的实时诊断工具mtr google.com
nslookup
/ dig
dig example.com MX
ss
(替代 netstat
)
ss -tulnp
(显示所有监听端口)netstat
(旧版,部分系统已弃用)
netstat -antp
curl
curl -O http://example.com/file.zip
wget
wget -c http://example.com/file.zip
(支持断点续传)scp
scp file.txt user@remote:/path/
rsync
rsync -avz /local/dir/ user@remote:/backup/
iptables
/ nftables
iptables -A INPUT -p tcp --dport 22 -j ACCEPT
ufw
(简化防火墙配置)
ufw allow 22/tcp
ssh
ssh user@host -p 2222
tcpdump
tcpdump -i eth0 port 80
nc
(netcat)
nc -zv host 80
(测试端口)telnet
(不加密,慎用)
telnet example.com 80
whois
whois example.com
systemctl
bash
systemctl restart sshd # 重启SSH服务
systemctl status nginx # 查看Nginx状态
sshd
配置
/etc/ssh/sshd_config
iwconfig
(旧版)
iwconfig wlan0 essid "MyWiFi"
iw
(新版)
iw dev wlan0 scan
(扫描WiFi)ifconfig
、ip
配置)。ip
替代 ifconfig
/route
,ss
替代 netstat
。根据需求选择合适的命令,组合使用可高效解决网络问题!