Files
Linux/Docs/Centos7配置静态IP.md
offends 74bca24ec4
All checks were successful
continuous-integration/drone Build is passing
新增文档
2025-11-06 20:09:07 +08:00

37 lines
1.6 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

> 本文作者:丁辉
# Centos7配置静态IP
1. 编辑网卡配置文件
```bash
vi /etc/sysconfig/network-scripts/ifcfg-ens33
```
修改并添加如下内容
```bash
BOOTPROTO=static
DNBOOT=yes
IPADDR=192.168.100.100
GATEWAY=192.168.100.1
NETMASK=255.255.255.0
DNS1=8.8.8.8
```
2. 保存并退出重启网卡
```bash
systemctl restart network
```
**参数解释**
| 参数 | 解释 |
| :-----------: | :----------------------------------------------------------: |
| **BOOTPROTO** | 指定如何配置网络接口的IP地址。 **`static`** 表示使用手动设置的静态IP地址。其他常见值有 `dhcp`(自动获取)、`none`(无协议)。 |
| **ONBOOT** | 指定在系统启动时是否激活此网络连接。 **`yes`** 表示系统启动时会自动启用该网络接口。如果为 `no`,则需要手动启动。 |
| **IPADDR** | 指定网络接口的**静态IP地址**。 **`192.168.100.100`** 就是为本机设置的固定IP地址。 |
| **GATEWAY** | 指定网络的**默认网关**地址,这是数据包发送到其他网络的出口。 **`192.168.100.1`** 通常是路由器或网络出口设备的地址。 |
| **NETMASK** | 指定IP地址的**子网掩码**用于划分IP地址中的网络部分和主机部分。 **`255.255.255.0`** 表示该网络最多可以容纳254台主机192.168.100.1 - 192.168.100.254)。 |
| **DNS1** | 指定主**域名系统服务器**的地址,负责将域名(如 `www.google.com`解析为IP地址。 **`8.8.8.8`** 是Google提供的公共DNS服务器。 |