在 Debian 系统中,推荐使用 ip
命令来配置网络接口,因为它是现代 Linux 中的推荐方法。不过,如果你仍然想使用 ifconfig
命令(注意:ifconfig
在某些 Debian 版本中可能已被弃用,建议使用 ip
命令),以下是使用 ifconfig
修改网关的步骤:
打开终端。
查看当前网络接口信息,例如 eth0
:
ifconfig eth0
停止网络接口:
sudo ifconfig eth0 down
使用 ifconfig
命令配置静态 IP 地址和网关:
sudo ifconfig eth0 192.168.1.100 netmask 255.255.255.0 gateway 192.168.1.1
其中,192.168.1.100
是你要设置的 IP 地址,255.255.255.0
是子网掩码,192.168.1.1
是网关地址。
(可选)配置 DNS 服务器:
sudo echo "nameserver 8.8.8.8" >> /etc/resolv.conf
sudo echo "nameserver 8.8.4.4" >> /etc/resolv.conf
启动网络接口:
sudo ifconfig eth0 up
验证网关配置是否生效:
ip route show
或者,你可以通过编辑网络配置文件 /etc/network/interfaces
来实现永久配置。以下是编辑配置文件的步骤:
使用文本编辑器打开配置文件:
sudo nano /etc/network/interfaces
在文件中添加或修改以下内容:
auto eth0
iface eth0 inet static
address 192.168.1.100
netmask 255.255.255.0
gateway 192.168.1.1
保存并退出编辑器。
重启网络服务以应用更改:
sudo systemctl restart networking
验证配置是否生效:
ip route show
。
亿速云「云服务器」,即开即用、新一代英特尔至强铂金CPU、三副本存储NVMe SSD云盘,价格低至29元/月。点击查看>>