linux debian 更改ip,如何在Debian Linux上设置静态IP地址

目的

目标是在Debian Linux服务器上配置静态IP地址。

请注意,对于桌面安装,建议使用GUI工具,例如network-manager。如果您希望通过/etc/network/interfaces桌面上的文件直接配置网络接口,请确保禁用任何其他可能干扰的网络配置守护程序例如,以下命令将禁用。network-manager: # systemctl stop NetworkManager.service # systemctl disable NetworkManager.service

操作系统和软件版本 操作系统:

要求

需要对Debian Linux系统进行特权访问。

约定 #linuxsudo命令

$linux命令作为常规非特权用户执行

启用静态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。/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 static

配置IP地址

在这个阶段,我们有两种选择为如何我们的eth0网络接口配置静态IP地址第一个选项是将IP地址配置直接添加到。/etc/network/interfaces文件中将以下行附加到您现有的行。/etc/network/interfaces: address 10.1.1.125 netmask 255.0.0.0 gateway 10.1.1.1

的生成内容/etc/network/interfaces文件应如下所示根据需要更新您的IP地址,网络掩码和网关: 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 static address 10.1.1.125 netmask 255.0.0.0 gateway 10.1.1.1

PS:这里是另外一种配置,二选一

一种另外选择配置英文的在/etc/network/interfaces.d/目录中单独定义网络接口。

在networking守护程序启动期间,将/etc/network/interfaces.d/搜索目录以查找网络接口配置。任何找到的网络配置都包含在内/etc/network/interfaces。

使用任意文件名创建新的网络配置文件,例如,eth0并包括eth0下面显示的IP地址配置为此,请使用首选的文本编辑器,例如VIM: # 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/resolv.conf文件,并包含您首选的IP地址,nameserver例如: nameserver 8.8.8.8

或者,将以下行添加到/etc/network/interfaces网络配置文件中: dns-nameservers 8.8.8.8 8.8.4.4

应用更改

要应用更改,请重新启动网络守护程序: # service networking restart

PS:如果您使用的是虚拟机VirturalBox,请注意要先将网络配置成桥接网络,原来是NAT模式,改成静态静态还是连接不上,需要把网络改成Bridged Adapter即可,Promiscuous Mode设置为允许全部。

d18925192f7c471b25ef9034d4b42adf.png root@debian-extrem:~# 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 enp0s3 iface enp0s3 inet static address 192.168.1.98 netmask 255.255.255.0 gateway 192.168.1.1 dns-nameservers 8.8.8.8 8.8.4.4

现在能ping通网络: root@debian-extrem:~# ping www.baidu.com PING www.a.shifen.coM (119.75.217.26) 56(84) bytes of data. 64 bytes from 119.75.217.26 (119.75.217.26): icmp_seq=1 ttl=49 time=48.2 ms 64 bytes from 119.75.217.26 (119.75.217.26): icmp_seq=2 ttl=49 time=46.1 ms 64 bytes from 119.75.217.26 (119.75.217.26): icmp_seq=3 ttl=49 time=52.4 ms 64 bytes from 119.75.217.26 (119.75.217.26): icmp_seq=4 ttl=49 time=47.9 ms 64 bytes from 119.75.217.26 (119.75.217.26): icmp_seq=5 ttl=49 time=52.1 ms

转载来源:https://linuxconfig.org/how-to-setup-a-static-ip-address-on-debian-linux

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值