ifconfig
是一个用于配置和显示 Linux 内核中网络接口的命令行实用程序。通过 ifconfig
,你可以查看网络接口的状态、配置 IP 地址、子网掩码、广播地址等信息。以下是如何使用 ifconfig
进行网络调试的一些建议:
ifconfig
eth0
的接口):ifconfig eth0
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
sudo ifconfig eth0 up
sudo ifconfig eth0 down
sudo ifconfig eth0 broadcast 192.168.1.255
sudo ifconfig eth0 mtu 1400
诊断网络连接问题:
ping
命令检查与另一台设备的连通性:ping 8.8.8.8
traceroute
命令查看数据包在网络中的传输路径:traceroute 8.8.8.8
netstat
命令查看网络连接、路由表和网络接口统计信息:netstat -tuln
保存网络接口配置:
在某些 Linux 发行版中,你可以使用 ifconfig
命令将网络接口配置保存到 /etc/network/interfaces
(Debian/Ubuntu)或 /etc/sysconfig/network-scripts/ifcfg-eth0
(RHEL/CentOS)文件中。
请注意,ifconfig
命令在某些 Linux 发行版中可能已被弃用,取而代之的是 ip
命令。在这种情况下,你可以使用 ip
命令执行类似的操作。