Henry
发布于 2024-01-13 / 43 阅读
0
0

Linux 配置静态IP

背景简介

给Linux系统配置静态IP,配置方式为修改配置文件。

环境配置

  1. 系统:Debian 6.1.66-1 (2023-12-09) x86_64 GNU/Linux

详细步骤

查看配置文件目录 /etc/network

root@peag-k8s-master:/etc/network# ls
if-down.d  if-post-down.d  if-pre-up.d	if-up.d  interfaces  interfaces.d

查看默认配置文件

root@peag-k8s-master:/etc/network# cat 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 enp1s0
iface enp1s0 inet dhcp

可以看到除了默认配置文件信息里面的配置外,还引用了 interfaces.d 文件夹下的配置。

注释默认配置文件 /etc/network/interfaces 里面的 iface enp1s0 的配置,在 interfaces.d 目录下新增自定义配置。

root@peag-k8s-master:/etc/network# nano interfaces

root@peag-k8s-master:/etc/network# cat 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 enp1s0
#iface enp1s0 inet dhcp

新增自定义的 enp1s0 配置文件

root@peag-k8s-master:/etc/network# nano interfaces.d/iface-enp1s0
root@peag-k8s-master:/etc/network# cat interfaces.d/iface-enp1s0
auto enp1s0
iface enp1s0 inet static
address 192.168.122.105
gateway 192.168.122.1
netmask 255.255.255.0

重启网络服务

root@peag-k8s-master:/etc/network# systemctl restart networking

Debian 是 networking , 其他版本的 Linux 可能是 network, 请根据自己的系统详情变更。

至此,静态IP的配置就完成啦~


评论