{
  "schemaVersion": "0.11.0",
  "canonical": "https://www.pystone.net/notes/centos7-network-configuration/",
  "atlas": "https://www.pystone.net/?node=centos7-network-configuration#knowledge-atlas",
  "markdown": "https://www.pystone.net/notes/centos7-network-configuration.md",
  "context": "https://www.pystone.net/notes/centos7-network-configuration.context.json",
  "knowledgeVersion": "224c990773de.5fa8af6e39fa",
  "build": {
    "siteCommit": "224c990773de166d23a886306577dd90379529ce",
    "notesCommit": "5fa8af6e39fa3891d1b9b4832bfa6c4e0ecaaf0a",
    "builtAt": "1970-01-01T00:00:00.000Z",
    "version": "224c990773de.5fa8af6e39fa"
  },
  "id": "note:centos7-network-configuration",
  "slug": "centos7-network-configuration",
  "title": "【OS Unix-like】CentOS 7 网络配置",
  "type": "note",
  "visibility": "public",
  "idStability": "rename-stable",
  "author": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "publisher": {
    "name": "Perrin Yong",
    "profile": "https://www.pystone.net/profile/"
  },
  "aliases": [],
  "summary": "【OS Unix like】CentOS 7 网络配置",
  "contentRole": "unspecified",
  "isMoc": false,
  "mocRecognition": "none",
  "generated": false,
  "attribution": "unspecified",
  "domain": "10-计算机、信息技术与工程",
  "tags": [],
  "mocs": [],
  "contentHash": "c7174f2791728a94e6fec85d6f619f1eadf5c9f7218c2cceb1e8fcb30cd441c6",
  "assets": [
    {
      "reference": "assets/2159939-cf8af88089423af6.PNG",
      "url": "/media/a8707a521ff1f713ef7c.png",
      "mediaType": "image/png",
      "contentHash": "a8707a521ff1f713ef7c2173dd575d74ef69cdfdc414f3aa3d2830c8ac62074c",
      "byteLength": 2342,
      "width": 934,
      "height": 85
    },
    {
      "reference": "assets/2159939-8a428f4a4d776f2a.PNG",
      "url": "/media/f4de82fd99e8182b7b32.png",
      "mediaType": "image/png",
      "contentHash": "f4de82fd99e8182b7b32c1079ce6543e26be69c944bac954cd3bf8933cb2640c",
      "byteLength": 3374,
      "width": 860,
      "height": 76
    },
    {
      "reference": "assets/2159939-91b15a2941d6f7f7.PNG",
      "url": "/media/3b5b546aaa5354803a88.png",
      "mediaType": "image/png",
      "contentHash": "3b5b546aaa5354803a881e5bbeb45c5bef12ec6a60d7f4cfcc1b133eafdec7f5",
      "byteLength": 19034,
      "width": 907,
      "height": 629
    },
    {
      "reference": "assets/2159939-040ebf4f38c5a032.PNG",
      "url": "/media/e42f19bbac5899dea09b.png",
      "mediaType": "image/png",
      "contentHash": "e42f19bbac5899dea09be849728e1b6e3c8e4a855d8774db8e6e446119628ca1",
      "byteLength": 6825,
      "width": 779,
      "height": 136
    }
  ],
  "headings": [
    {
      "depth": 1,
      "text": "【OS Unix-like】CentOS 7 网络配置",
      "anchor": "os-unix-likecentos-7-网络配置",
      "citation": "https://www.pystone.net/notes/centos7-network-configuration/#os-unix-likecentos-7-%E7%BD%91%E7%BB%9C%E9%85%8D%E7%BD%AE"
    },
    {
      "depth": 2,
      "text": "yum install net-tools",
      "anchor": "yum-install-net-tools",
      "citation": "https://www.pystone.net/notes/centos7-network-configuration/#yum-install-net-tools"
    },
    {
      "depth": 2,
      "text": "vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 # 不同的网卡名臣可能不同",
      "anchor": "vi-etcsysconfignetwork-scriptsifcfg-enp0s3-不同的网卡名臣可能不同",
      "citation": "https://www.pystone.net/notes/centos7-network-configuration/#vi-etcsysconfignetwork-scriptsifcfg-enp0s3-%E4%B8%8D%E5%90%8C%E7%9A%84%E7%BD%91%E5%8D%A1%E5%90%8D%E8%87%A3%E5%8F%AF%E8%83%BD%E4%B8%8D%E5%90%8C"
    },
    {
      "depth": 2,
      "text": "ip addr show",
      "anchor": "ip-addr-show",
      "citation": "https://www.pystone.net/notes/centos7-network-configuration/#ip-addr-show"
    }
  ],
  "claims": [],
  "outgoing": [
    {
      "id": "note:linux-distro-migration-checklist",
      "title": "受支持 Linux 发行版的部署迁移检查清单",
      "url": "https://www.pystone.net/notes/linux-distro-migration-checklist/",
      "atlas": "https://www.pystone.net/?node=linux-distro-migration-checklist#knowledge-atlas",
      "label": "受支持Linux发行版的部署迁移检查清单",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "CentOS Linux 7 已于 2024-06-30 停止维护，不再获得常规安全更新。本文仅用于维护遗留环境；新部署应使用仍在支持期内的发行版，并以其当前网络管理文档为准。迁移步骤见 受支持Linux发行版的部署迁移检查清单。",
      "citation": "https://www.pystone.net/notes/centos7-network-configuration/#os-unix-likecentos-7-%E7%BD%91%E7%BB%9C%E9%85%8D%E7%BD%AE"
    }
  ],
  "incoming": [
    {
      "id": "note:software-engineering-and-quality",
      "title": "软件工程与质量保障",
      "url": "https://www.pystone.net/notes/software-engineering-and-quality/",
      "atlas": "https://www.pystone.net/?node=software-engineering-and-quality#knowledge-atlas",
      "label": "软件工程与质量保障",
      "origin": "explicit",
      "humanReviewed": true,
      "context": "CI-CD与质量保障/CI-CD工具链中的“【OS Unix-like】CentOS 7 网络配置”导航项",
      "citation": "https://www.pystone.net/notes/software-engineering-and-quality/#ci-cd%E4%B8%8E%E8%B4%A8%E9%87%8F%E4%BF%9D%E9%9A%9Cci-cd%E5%B7%A5%E5%85%B7%E9%93%BE"
    }
  ],
  "contentMarkdown": "# 【OS Unix-like】CentOS 7 网络配置\n\n> [!danger] 已停止维护的历史配置\n> CentOS Linux 7 已于 2024-06-30 停止维护，不再获得常规安全更新。本文仅用于维护遗留环境；新部署应使用仍在支持期内的发行版，并以其当前网络管理文档为准。迁移步骤见 [[受支持Linux发行版的部署迁移检查清单]]。\n\n> 创建时间：2022/1/4 19:41\n\n[l蓝色梦幻](https://www.jianshu.com/u/abd3db9d23a6)\n\n2018.10.22 13:46:12字数 528阅读 5,504\n\nMinimal 版本的 CentOS 7 安装完成后, 如果没有在安装过程中配置网络,那么安装成功后的系统是没有网络访问的.这是因为默认情况下,没有配置对应的 IP 以及 DNS 等导致的问题.此外,大部分 CentOS 是作为服务器存在的.为了方便使用,建议为 CentOS 配置静态 IP。\n\n  1. 配置 CentOS 7 访问到网络.\n\nCentOS 安装成功后,进行一下 ping 的操作,验证网络是否联通.\n\n& ping 10.1.1.1\n\n![](assets/2159939-cf8af88089423af6.PNG)\n\n001.PNG\n\n当出现网络未联通的情况,我们使用 nmcli 命令查看一下网络设置:\n\nnmcli connection show\n\n![](assets/2159939-8a428f4a4d776f2a.PNG)\n\n002.PNG\n\n该命令会返回 4 列数据. 分别是 NAME(联网代号), UUID(识别码), TYPE网卡类型, DEVICE(网卡名称).\n\n查看指定网卡的信息:\n\n`nmcli connection show 联网代号`\n\n![](assets/2159939-91b15a2941d6f7f7.PNG)\n\n003.PNG\n\n这时候我们找到原因了. IP 和 DNS 配置都不正确.\n\n设置网络获取方式为自动获取 IP. 一般至此, 硬件连接成功的话都会连接到互联网上.\n\nnmcli connection modify 联网代号 connection.autoconnect yes ipv4.method auto\n\n![](assets/2159939-040ebf4f38c5a032.PNG)\n\n004.PNG\n\n  1. 安装 ifconfig 工具\n\nCentOS 7 中使用 ip 命令代替了 ifconfig 命令, 如果你不习惯 ip 命令，可以将其安装回来.\n\n## yum install net-tools\n\n  2. 设置为固定 ip.\n\n修改网卡配置文件：\n\n## vi /etc/sysconfig/network-scripts/ifcfg-enp0s3 # 不同的网卡名臣可能不同\n\n已经配置为动态获取 ip 的配置:\n\n006.PNG\n\n修改以下两个地方。注意：ip dns 等信息请于 ISP 处获取。\n\n    * IPADDR = \"[在这里输入你的静态 IP]\"\n\n    * GATEWAY = \"[输入你的默认网关]\"\n\n    * NETMASK = \"[输入你的网关]\"\n\n    * DNS1 = \"[你的 DNS]\"\n\n    * DNS2 = \"[你的 DNS]\"\n\n  3. 007.PNG\n\n使网卡配置生效\n\n  4. nmcli connection up ens33\n\n重启网络服务。后查看 ip 是否与分配的相同。\n\n  5. # service network restart\n\n## ip addr show\n\n  6. 008.PNG\n\nping 以下网络，检查网络连接状态。\n\n  7. # ping -c4 www.baidu.com\n\nMeasure\n\nMeasure\n"
}
