启用静态IP
默认情况下, 我们将在网络配置文件/etc/network/interfaces中找到以下配置:
source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0 iface eth0 inet dhcp
将iface eth0 inet dhcp
改成iface eth0 inet static
配置IP地址
我们有两种方法为eth0配置静态IP地址。
第一种方法是在/etc/network/interfaces
中配置:
address 10.1.1.125 netmask 255.0.0.0 gateway 10.1.1.1
第二种方法是在“/etc/network/interfaces.d /”目录中添加单独定义网络接口。
如下所示:
# cat /etc/network/interfaces.d/eth0 iface eth0 inet static address 10.1.1.125 netmask 255.0.0.0 gateway 10.1.1.1
第二种方法的/etc/network/interfaces
文件
# cat /etc/network/interfaces # This file describes the network interfaces available on your system # and how to activate them. For more information, see interfaces(5). source /etc/network/interfaces.d/* # The loopback network interface auto lo iface lo inet loopback # The primary network interface allow-hotplug eth0
配置静态DNS服务器
要配置静态DNS,编辑/etc/soldv.conf
文件:
nameserver 8.8.8.8
或者,将以下行添加到/etc/network/interfaces
配置文件中:
dns-nameservers 8.8.8.8 8.8.4.4
使更改生效
要使更改生效,重新启动网络守护程序:
# service networking restart
日期:2020-07-07 20:56:36 来源:oir作者:oir