目的

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

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

# systemctl stop NetworkManager.service
# systemctl disable NetworkManager.service

操作系统和软件版本

  • 操作系统:  - Debian 9(Stretch)

要求

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

约定

  •  - 要求使用root权限直接以root用户或使用命令执行给定的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 dhcpiface 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 staticaddress 10.1.1.125netmask 255.0.0.0gateway 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 staticaddress 10.1.1.125netmask 255.0.0.0gateway 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设置为允许全部。

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.98netmask 255.255.255.0gateway 192.168.1.1dns-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

如何在Debian Linux上设置静态IP地址相关推荐

  1. 如何在 Debian11系统上设置静态IP地址 ?

    当我们在安装 Debian Linux 时,在安装过程中它试图从调制解调器(或 DHCP 服务器)获得 DHCP ip 地址(如果可用的话).但是在您的系统上总是建议有一个静态 IP 地址.静态 IP ...

  2. 如何在Eero路由器上设置静态IP地址

    Most of the time, having your router assign dynamic IP addresses to your devices is fine. Sometimes, ...

  3. linux 怎么设置静态ip,如何在Linux中设置静态IP地址和配置网络

    如果您是Linux系统管理员,那么当您需要在系统上配置网络时,就会出现时间. 与可以使用动态IP地址的台式机不同,在服务器基础架构上,您需要设置静态IP地址(至少在大多数情况下).IP地址 :192. ...

  4. 路由器桥接静态ip设置_如何在路由器上设置静态IP地址

    路由器桥接静态ip设置 Routers both modern and antiquated allow users to set static IP addresses for devices on ...

  5. 如何在 Debian 11 上设置一个静态 IP 地址

    当你在电脑上安装一个新的操作系统时,DHCP服务器会给你分配一个动态IP地址.然而,在各种情况下,你可能需要在你的机器上设置一个静态IP地址,例如,当你正在托管一个网络服务器,或者任何服务需要一个IP ...

  6. 如何在CentOS 7中配置静态IP地址

    转载来源:https://www.techrepublic.com/article/how-to-configure-a-static-ip-address-in-centos-7/ PS:这个简短的 ...

  7. 服务器升级debian9_如何在Debian 9上设置PageKite前端服务器

    服务器升级debian9 The author selected the Open Internet/Free Speech Fund to receive a donation as part of ...

  8. linux设置静态ip地址_什么是静态IP地址,与动态IP地址比较以及如何为Windows和Linux设置?...

    linux设置静态ip地址 IP addresses are the core mechanism of Computer networks. The IP address is used to sp ...

  9. linux操作系统-设置静态ip

    在使用linux虚拟机的时候因为经常有关机的需求,然后重新开机后可能面临这上一次获取的ip被改变,在这里我分享一下在linux 下设置静态ip的经验 1.查看路由状态 [root@localhost ...

最新文章

  1. MFCard:易用的信用卡支付集成类库
  2. 【Android 逆向】ARM CPU 架构体系 ( ARM 处理器工作模式 | ARM 架构模型 )
  3. 【转】构造函数的执行序列
  4. firework常用快捷键
  5. 国际农化巨头战略转移-丰收节贸易会:未来农化发展之路
  6. bootstrap html5 表单验证,基于Bootstrap+jQuery.validate实现表单验证
  7. 【转】eclipse中egit插件使用
  8. halcon 17 cuda cudnn 深度学习环境搭建
  9. 数据库运作实践三三之歌(秘制口诀)
  10. 对于Linux安装mysql5.7版本出现的问题
  11. Python面试题解析之网络编程与并发
  12. java的decimalFormat_Java中 DecimalFormat 用法详解
  13. elasticsearch与kibana踩过的坑
  14. 本地计算机的硬件基本配置信息,Windows7系统如何查看硬件的基本配置
  15. 计算机网络对生活的影响论文,浅论计算机对我们生活的影响论文
  16. 设为首页 加入收藏 html,js设为首页和加入收藏代码(兼容所有浏览器)
  17. The requested URL returned error: 403
  18. 关于一个App调起另一个App
  19. 十五、分布式相关理论
  20. 2020年9大IT互联网大佬扎心语录

热门文章

  1. 如何优化网页转化率?(中篇)
  2. UITableView 系列一 :基本使用方法 (显示,删除,添加图片,添加样式等) (实例)...
  3. 如何用Pygame写游戏(十四)
  4. 《剑指Offer》 二叉树的深度
  5. 【今日CV 计算机视觉论文速览 第123期】Mon, 3 Jun 2019
  6. Ubuntu 12.06 双显卡切换
  7. OPENWRT的串口初试
  8. 泛型字典 0104 c#
  9. 云题库进入其它章节的办法 0925
  10. python-for循环与while循环