以下是Debian中使用ifconfig配置网络的教程:
查看网络接口
ifconfig -a # 显示所有接口(包括未激活的)
启用/禁用接口
sudo ifconfig eth0 up # 启用eth0接口
sudo ifconfig eth0 down # 禁用eth0接口
(eth0需替换为实际接口名,如ens33、wlan0等)
配置IP地址与子网掩码
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 # 设置IP和子网掩码
sudo ifconfig eth0 up # 激活接口
设置网关
sudo route add default gw 192.168.1.1 # 添加默认网关
配置DNS
sudo nano /etc/resolv.conf # 编辑DNS文件
添加:nameserver 8.8.8.8 # 保存后生效
ifconfig配置在重启后失效,如需永久保存,需编辑配置文件(见下文)。ip命令替代ifconfig(如ip addr add),若ifconfig不可用,可尝试安装net-tools包:sudo apt install net-tools
若需重启后保留设置,建议通过修改配置文件实现:
/etc/network/interfaces文件:sudo nano /etc/network/interfaces
添加静态IP配置(以eth0为例):auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
dns-nameservers 8.8.8.8 8.8.4.4
sudo systemctl restart networking
参考来源: