ifconfig 是一个用于配置和显示网络接口参数的命令行工具。要使用 ifconfig 设置静态 IP 地址,请按照以下步骤操作:
打开终端(在 Linux 和 macOS 上)或命令提示符/PowerShell(在 Windows 上)。
首先,找到要配置的网络接口名称。在 Linux 和 macOS 上,可以使用 ifconfig -a 命令查看所有网络接口。在 Windows 上,可以使用 ipconfig /all 命令查看所有网络接口。
假设要配置的网络接口名称为 eth0(在 Linux 和 macOS 上)或 Ethernet(在 Windows 上),并且希望为其分配静态 IP 地址 192.168.1.100,子网掩码为 255.255.255.0,默认网关为 192.168.1.1。请根据您的实际需求替换这些值。
在 Linux 和 macOS 上,使用以下命令设置静态 IP 地址:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0
在 Windows 上,使用以下命令设置静态 IP 地址:
netsh interface ip set address "Ethernet" static 192.168.1.100 255.255.255.0 192.168.1.1
echo "nameserver 8.8.8.8" | sudo tee -a /etc/resolv.conf
在 Windows 上,使用以下命令:
Set-DnsClientServerAddress -InterfaceAlias "Ethernet" -ServerAddresses ("8.8.8.8", "8.8.4.4")
请注意,这些命令可能需要管理员权限才能成功执行。如果在执行过程中遇到问题,请确保您具有足够的权限,并检查您输入的命令和参数是否正确。