在本教程中,将介绍如何在 ubuntu 16 LTS 上设置静态 IP 地址,我们需要进行一些更改的文件是 /etc/network/interfaces。
在本教程中,测试服务器将进行下面设置:
– IP 地址:192.168.1.10
– 网络掩码 255.255.255.0
– 网关 192.168.1.1
– 域名服务器:192.168.1.2 192.168.1.3
首先让我们打开文件:
[jack@onitroad ~]# vim /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 auto enp0s3 iface enp0s3 inet dhcp
这里我们需要删除或者注释 iface enp0s3 inet dhcp 或者将其更改为静态,然后添加静态 IP 地址、网络掩码、网关和 dns 服务器,如下所示:
# The primary network interface auto enp0s3 #iface enp0s3 inet dhcp iface enp0s3 inet static address 192.168.1.10 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 192.168.1.2 192.168.1.3
接下来,保存文件并重新启动网络服务。
[jack@onitroad ~]# systemctl restart networking
或者这个命令
[jack@onitroad ~]#/etc/init.d/networking restart
日期:2020-06-02 22:18:22 来源:oir作者:oir